linkedin-relay-mcp 3.6.1 → 3.7.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.
@@ -202,6 +202,7 @@ Writes are **not on the MCP surface**. They exist only as CLI commands:
202
202
  | `lnrelay comment <activity-urn> "<text>"` | comment on a post |
203
203
  | `lnrelay reply <comment-urn> "<text>"` | reply, nested under that comment |
204
204
  | `lnrelay edit <comment-urn \| share-urn \| ugcPost-urn> "<text>"` | change the text of their own comment or post |
205
+ | `lnrelay edit headline\|about ("<text>" \| --file <path>)` | change their profile headline (max 220 characters) or About section |
205
206
  | `lnrelay react <urn> [--type X] [--remove]` | react to a post or comment |
206
207
  | `lnrelay delete <activity-urn \| comment-urn>` | delete their post or comment |
207
208
 
@@ -240,6 +241,10 @@ Things worth telling a user who asks:
240
241
  and not on a post that already carries images, a video, a PDF or a poll). The plan names the card
241
242
  (`card "<title>" (<site>)`), or says LinkedIn has none. If the lookup fails nothing is posted; add
242
243
  `--no-card` to post the link as plain text.
244
+ - A profile edit's preview shows the current headline or About beside the new one. The approval is
245
+ bound to both, so if the profile changed after the preview, re-plan. Every other profile field
246
+ (name, location, current position) is sent back exactly as LinkedIn holds it, and the result is
247
+ read back from the profile. About edits are refused while the About section has top skills set.
243
248
  - Scheduled posts are listed by `scheduled` (MCP and CLI), not by `my-posts`.
244
249
  - Editing a post replaces its whole text and LinkedIn marks it edited; pass the urn `share` printed
245
250
  (or `shareUrn` from `my-posts`), not the activity urn. An @mention in the old text is not kept.
package/dist/cli.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env bun
2
+ // src/cli.ts
3
+ import { readFileSync as readFileSync3 } from "fs";
4
+
2
5
  // src/args.ts
3
6
  function parseArgs(argv) {
4
7
  const [command, ...rest] = argv;
@@ -1998,9 +2001,9 @@ function textStates(payload, text2) {
1998
2001
  }
1999
2002
  return null;
2000
2003
  };
2001
- const plain = keyOf("commentary", "commentFieldBinding");
2004
+ const plain2 = keyOf("commentary", "commentFieldBinding");
2002
2005
  const rich = keyOf("richTextCommentary", "richCommentFieldBinding");
2003
- if (plain === null || rich === null) return [];
2006
+ if (plain2 === null || rich === null) return [];
2004
2007
  const entry2 = (key, value, protoCase) => ({
2005
2008
  key,
2006
2009
  namespace: "MemoryNamespace",
@@ -2009,7 +2012,7 @@ function textStates(payload, text2) {
2009
2012
  protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id: key } }
2010
2013
  });
2011
2014
  return [
2012
- entry2(plain, text2, "stringValue"),
2015
+ entry2(plain2, text2, "stringValue"),
2013
2016
  entry2(rich, { text: text2, attribute: [], $type: "TextModel", source: "local" }, "textModelForWrite")
2014
2017
  ];
2015
2018
  }
@@ -2068,12 +2071,12 @@ function parseCommentUrn(urn) {
2068
2071
  activityId: fsd[3]
2069
2072
  };
2070
2073
  }
2071
- const plain = /^urn:li:comment:\((?:urn:li:)?(activity|ugcPost):(\d+),(\d+)\)$/.exec(urn);
2072
- if (plain !== null) {
2074
+ const plain2 = /^urn:li:comment:\((?:urn:li:)?(activity|ugcPost):(\d+),(\d+)\)$/.exec(urn);
2075
+ if (plain2 !== null) {
2073
2076
  return {
2074
- threadType: plain[1],
2075
- activityId: plain[2],
2076
- commentId: plain[3]
2077
+ threadType: plain2[1],
2078
+ activityId: plain2[2],
2079
+ commentId: plain2[3]
2077
2080
  };
2078
2081
  }
2079
2082
  return null;
@@ -3691,8 +3694,8 @@ var COMMANDS = [
3691
3694
  {
3692
3695
  name: "edit",
3693
3696
  cost: "1 read + 1 write",
3694
- summary: "Change the text of a comment or post you wrote. Its own verb, so a comment urn can never be mistaken for something to comment ON.",
3695
- usage: 'lnrelay edit <comment-urn | share-urn | ugcPost-urn> "<text>"\n A post is edited by the urn it was created as (`share` prints it; `my-posts` lists\n it as shareUrn), not its activity urn. The whole text is replaced.',
3697
+ summary: "Change the text of a comment or post you wrote, or your profile headline or About. Its own verb, so a comment urn can never be mistaken for something to comment ON.",
3698
+ usage: 'lnrelay edit <comment-urn | share-urn | ugcPost-urn> "<text>"\n lnrelay edit headline|about ("<text>" | --file <path>)\n A post is edited by the urn it was created as (`share` prints it; `my-posts` lists\n it as shareUrn), not its activity urn. The whole text is replaced. A profile edit\n shows the current text beside the new one, sends every other profile field back as\n LinkedIn holds it, and reads the profile back to confirm. Headline max 220 characters.',
3696
3699
  audience: ["cli"],
3697
3700
  risk: "write",
3698
3701
  implemented: true
@@ -4063,6 +4066,218 @@ async function comment(confirmed, client) {
4063
4066
  return { ok: true, id: activityId };
4064
4067
  }
4065
4068
 
4069
+ // src/engine/sdui-profile.ts
4070
+ var NAV_URL = "https://www.linkedin.com/flagship-web/rsc-action/actions/navigation";
4071
+ var ACTION_URL = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
4072
+ var PROFILE_FIELDS = {
4073
+ headline: {
4074
+ name: "headline",
4075
+ screen: "com.linkedin.sdui.flagshipnav.profile.ProfileEditIntroForm",
4076
+ save: "com.linkedin.sdui.requests.profile.saveProfileIntroForm",
4077
+ binding: "headline",
4078
+ // The web form refuses more ("Exceeded maximum length of 220 characters").
4079
+ maxLength: 220
4080
+ },
4081
+ about: {
4082
+ name: "about",
4083
+ screen: "com.linkedin.sdui.flagshipnav.profile.ProfileAboutForm",
4084
+ save: "com.linkedin.sdui.requests.profile.saveProfileAboutForm",
4085
+ binding: "about",
4086
+ maxLength: 2600
4087
+ }
4088
+ };
4089
+ function formNavBody(screen, vanityName) {
4090
+ return {
4091
+ clientArguments: {
4092
+ $type: "proto.sdui.actions.requests.RequestedArguments",
4093
+ requestedStateKeys: [],
4094
+ payload: { vanityName, isVanityNameResolved: true },
4095
+ requestMetadata: { $type: "proto.sdui.common.RequestMetadata" },
4096
+ states: [],
4097
+ screenId: screen,
4098
+ knownTemplateIds: []
4099
+ },
4100
+ isModal: true
4101
+ };
4102
+ }
4103
+ var drift2 = (message) => ({
4104
+ ok: false,
4105
+ code: "SCHEMA_DRIFT",
4106
+ message,
4107
+ hint: "Re-capture the profile form with scripts/observe-write.ts (edit one character, then revert)."
4108
+ });
4109
+ function balanced(s, start) {
4110
+ const open = s[start];
4111
+ const close = open === "[" ? "]" : "}";
4112
+ let depth = 0;
4113
+ let inString = false;
4114
+ let escaped = false;
4115
+ for (let i = start; i < s.length; i++) {
4116
+ const ch = s[i];
4117
+ if (escaped) escaped = false;
4118
+ else if (ch === "\\") escaped = true;
4119
+ else if (ch === '"') inString = !inString;
4120
+ else if (!inString && ch === open) depth++;
4121
+ else if (!inString && ch === close) {
4122
+ depth--;
4123
+ if (depth === 0) return s.slice(start, i + 1);
4124
+ }
4125
+ }
4126
+ return null;
4127
+ }
4128
+ function parseAt(s, start) {
4129
+ const text2 = start === -1 ? null : balanced(s, start);
4130
+ if (text2 === null) return null;
4131
+ try {
4132
+ return JSON.parse(text2);
4133
+ } catch {
4134
+ return null;
4135
+ }
4136
+ }
4137
+ function plain(v) {
4138
+ const protoCase = String(v.$case);
4139
+ const raw = v[protoCase];
4140
+ if (protoCase === "stringListValue") {
4141
+ return { protoCase, value: raw?.stringValues ?? [] };
4142
+ }
4143
+ return { protoCase, value: raw };
4144
+ }
4145
+ function readForm(stream, field) {
4146
+ const at = stream.indexOf('"modelStates":[');
4147
+ const model = parseAt(stream, at === -1 ? -1 : stream.indexOf("[", at));
4148
+ if (model === null) return drift2("the profile form carried no initial values");
4149
+ const states2 = /* @__PURE__ */ new Map();
4150
+ for (const entry2 of model) {
4151
+ const id = entry2.key?.key?.value?.id;
4152
+ if (id !== void 0 && entry2.value !== void 0 && !states2.has(id)) {
4153
+ states2.set(id, plain(entry2.value));
4154
+ }
4155
+ }
4156
+ const req = stream.indexOf(`"requestId":"${field.save}","requestedArguments":`);
4157
+ const args = req === -1 ? null : parseAt(
4158
+ stream,
4159
+ stream.indexOf("{", stream.indexOf('"requestedArguments":', req))
4160
+ );
4161
+ if (args === null || !Array.isArray(args.requestedStateKeys) || args.payload === void 0) {
4162
+ return drift2(`the profile form carried no ${field.save.split(".").pop()} action`);
4163
+ }
4164
+ return { ok: true, args, states: states2, screen: field.screen, save: field.save };
4165
+ }
4166
+ function boundKey(form, property) {
4167
+ const ref = form.args.payload[property];
4168
+ return ref?.key;
4169
+ }
4170
+ function currentValue(form, field) {
4171
+ const key = boundKey(form, field.binding);
4172
+ const v = key === void 0 ? void 0 : form.states.get(key)?.value;
4173
+ return typeof v === "string" ? v : void 0;
4174
+ }
4175
+ function computed(form, key) {
4176
+ if (!key.endsWith("ReorderableSkillsFormBindingsskillIdsBinding")) return void 0;
4177
+ const initial = [...form.states.entries()].find(([k]) => k.startsWith("initialSkills"))?.[1];
4178
+ if (initial === void 0) return drift2("the About form carried no initial top skills");
4179
+ if (!Array.isArray(initial.value) || initial.value.length > 0) {
4180
+ return {
4181
+ ok: false,
4182
+ code: "NOT_IMPLEMENTED",
4183
+ message: "your About section has top skills, and saving it with them has not been verified",
4184
+ hint: "Edit About in the browser for now; nothing was changed."
4185
+ };
4186
+ }
4187
+ return { protoCase: "expression", value: [] };
4188
+ }
4189
+ function saveBody(form, field, value) {
4190
+ if (value.length > field.maxLength) {
4191
+ return {
4192
+ ok: false,
4193
+ code: "INVALID_INPUT",
4194
+ message: `the ${field.name} is ${value.length} characters; LinkedIn allows ${field.maxLength}`
4195
+ };
4196
+ }
4197
+ const target = boundKey(form, field.binding);
4198
+ if (target === void 0 || !form.states.has(target)) {
4199
+ return drift2(`the profile form has no ${field.name} field`);
4200
+ }
4201
+ const states2 = [];
4202
+ for (const { key } of form.args.requestedStateKeys) {
4203
+ const id = key.value.id;
4204
+ let state = form.states.get(id);
4205
+ if (state?.protoCase === "expression") state = computed(form, id);
4206
+ if (state === void 0) continue;
4207
+ if ("ok" in state) return state;
4208
+ states2.push({
4209
+ key: id,
4210
+ namespace: "MemoryNamespace",
4211
+ value: id === target ? value : state.value,
4212
+ originalProtoCase: state.protoCase,
4213
+ protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id } }
4214
+ });
4215
+ }
4216
+ const requestedArguments = {
4217
+ $type: "proto.sdui.actions.requests.RequestedArguments",
4218
+ requestedStateKeys: form.args.requestedStateKeys,
4219
+ payload: form.args.payload,
4220
+ requestMetadata: { $type: "proto.sdui.common.RequestMetadata" }
4221
+ };
4222
+ const body = {
4223
+ requestId: form.save,
4224
+ serverRequest: {
4225
+ requestId: form.save,
4226
+ requestedArguments,
4227
+ isApfcEnabled: false,
4228
+ isStreaming: false,
4229
+ rumPageKey: ""
4230
+ },
4231
+ states: states2,
4232
+ requestedArguments: {
4233
+ ...requestedArguments,
4234
+ states: states2,
4235
+ screenId: form.screen,
4236
+ knownTemplateIds: []
4237
+ }
4238
+ };
4239
+ return { ok: true, body };
4240
+ }
4241
+ async function fetchProfileForm(field, vanityName, client) {
4242
+ const result = await client.request({
4243
+ url: `${NAV_URL}?screenId=${field.screen}&sduiid=${field.screen}`,
4244
+ method: "POST",
4245
+ body: formNavBody(field.screen, vanityName),
4246
+ spendClass: "page",
4247
+ operation: `profile-${field.name}-form`
4248
+ });
4249
+ if (!result.ok) {
4250
+ const out = { ok: false, code: result.code, message: result.message };
4251
+ if (result.hint !== void 0) out.hint = result.hint;
4252
+ return out;
4253
+ }
4254
+ return readForm(result.classification.raw ?? "", field);
4255
+ }
4256
+ async function sendProfileSave(form, body, client) {
4257
+ const result = await client.request({
4258
+ url: `${ACTION_URL}?sduiid=${form.save}`,
4259
+ method: "POST",
4260
+ body,
4261
+ spendClass: "write",
4262
+ operation: "profile-save"
4263
+ });
4264
+ if (!result.ok) {
4265
+ const out = { ok: false, code: result.code, message: result.message };
4266
+ if (result.hint !== void 0) out.hint = result.hint;
4267
+ return out;
4268
+ }
4269
+ const raw = result.classification.raw ?? "";
4270
+ const errors = raw.match(/"errors":\[([^\]]+)\]/)?.[1];
4271
+ if (errors !== void 0) {
4272
+ return {
4273
+ ok: false,
4274
+ code: "INVALID_INPUT",
4275
+ message: `LinkedIn refused the save: ${errors.slice(0, 300)}`
4276
+ };
4277
+ }
4278
+ return { ok: true };
4279
+ }
4280
+
4066
4281
  // src/engine/sdui-write.ts
4067
4282
  var SDUI_ACTION3 = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
4068
4283
  var SCREEN_ID4 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
@@ -4634,6 +4849,91 @@ async function runEditPost(urn, text2, now, deps) {
4634
4849
  const result = await editPost(gated.confirmed, createLiveClient(ctx.transport.session));
4635
4850
  return result.ok ? ok("edit", { edited: urn }) : err("edit", result.code, result.message, result.hint);
4636
4851
  }
4852
+ function liveProfile(session) {
4853
+ const client = createLiveClient(session);
4854
+ return {
4855
+ vanity: async () => {
4856
+ const me = await createEngine(session).whoami();
4857
+ if (!me.ok) return me;
4858
+ const id = me.value?.publicIdentifier ?? null;
4859
+ return typeof id === "string" && id !== "" ? { ok: true, vanity: id } : { ok: false, code: "SCHEMA_DRIFT", message: "whoami returned no public profile id" };
4860
+ },
4861
+ open: (field, vanity) => fetchProfileForm(field, vanity, client),
4862
+ send: (form, body) => sendProfileSave(form, body, client)
4863
+ };
4864
+ }
4865
+ var PROFILE_HINT = `profile fields: ${Object.keys(PROFILE_FIELDS).join(", ")}`;
4866
+ async function runEditProfile(name, text2, now = Date.now(), deps = terminalDeps(), surface) {
4867
+ const field = PROFILE_FIELDS[name];
4868
+ if (field === void 0) {
4869
+ return err(
4870
+ "edit",
4871
+ "INVALID_INPUT",
4872
+ `'${name}' is not a profile field this edits`,
4873
+ PROFILE_HINT
4874
+ );
4875
+ }
4876
+ if (text2 === void 0 || text2.trim() === "") {
4877
+ return err(
4878
+ "edit",
4879
+ "INVALID_INPUT",
4880
+ `the new ${name} is required`,
4881
+ `lnrelay edit ${name} "<text>"`
4882
+ );
4883
+ }
4884
+ if (text2.length > field.maxLength) {
4885
+ return err(
4886
+ "edit",
4887
+ "INVALID_INPUT",
4888
+ `the ${name} is ${text2.length} characters; LinkedIn allows ${field.maxLength}`
4889
+ );
4890
+ }
4891
+ const unapprovable = refuseUnapprovable("edit", "editing", deps);
4892
+ if (unapprovable !== null) return unapprovable;
4893
+ const ctx = prepare("edit", now, "voyager");
4894
+ if ("ok" in ctx) return ctx;
4895
+ if (ctx.transport.kind !== "voyager") {
4896
+ return err("edit", "NOT_IMPLEMENTED", "profile edits go over the browser session only");
4897
+ }
4898
+ const profile = surface ?? liveProfile(ctx.transport.session);
4899
+ const me = await profile.vanity();
4900
+ if (!me.ok) return err("edit", me.code, me.message, me.hint);
4901
+ const form = await profile.open(field, me.vanity);
4902
+ if (!form.ok) return err("edit", form.code, form.message, form.hint);
4903
+ const was = currentValue(form, field) ?? "";
4904
+ if (was === text2) {
4905
+ return err("edit", "INVALID_INPUT", `your ${name} already reads exactly that; nothing to save`);
4906
+ }
4907
+ const built = saveBody(form, field, text2);
4908
+ if (!built.ok) return err("edit", built.code, built.message, built.hint);
4909
+ const plan = {
4910
+ action: `change your ${name}`,
4911
+ payload: { field: name, was, text: text2 },
4912
+ summary: [
4913
+ authorLine(ctx.transport),
4914
+ `field ${name}`,
4915
+ `was "${was}"`,
4916
+ `new "${text2}"`
4917
+ ],
4918
+ reversibility: "editable again, but the old text is kept only in this preview and the audit log (~/.lnrelay/writes.jsonl). Every other profile field is sent back as LinkedIn holds it.",
4919
+ transport: "voyager"
4920
+ };
4921
+ const gated = await gate("edit", plan, ctx, deps);
4922
+ if ("ok" in gated) return gated;
4923
+ const sent = await profile.send(form, built.body);
4924
+ if (!sent.ok) return err("edit", sent.code, sent.message, sent.hint);
4925
+ const after = await profile.open(field, me.vanity);
4926
+ const reads = after.ok ? currentValue(after, field) : void 0;
4927
+ if (reads !== text2) {
4928
+ return err(
4929
+ "edit",
4930
+ "SCHEMA_DRIFT",
4931
+ `LinkedIn accepted the save, but your ${name} does not read back as the new text`,
4932
+ after.ok ? `It reads: "${reads ?? ""}"` : `The read-back failed: ${after.message}`
4933
+ );
4934
+ }
4935
+ return ok("edit", { field: name, verified: true });
4936
+ }
4637
4937
  function activityIdOf(urn) {
4638
4938
  return /^urn:li:(?:activity|ugcPost|share):(\d+)$/.exec(urn)?.[1] ?? null;
4639
4939
  }
@@ -4727,6 +5027,9 @@ async function runEdit(commentUrn, text2, now = Date.now(), deps = terminalDeps(
4727
5027
  );
4728
5028
  }
4729
5029
  const ref = parseCommentUrn(commentUrn);
5030
+ if (ref === null && !commentUrn.startsWith("urn:")) {
5031
+ return runEditProfile(commentUrn, text2, now, deps);
5032
+ }
4730
5033
  if (ref === null) {
4731
5034
  if (/^urn:li:(share|ugcPost):\d+$/.test(commentUrn)) {
4732
5035
  return runEditPost(commentUrn, text2, now, deps);
@@ -5044,6 +5347,22 @@ async function write(command, args, now) {
5044
5347
  if (wasApproved()) auditOutcome(command, mode.mode, envelope);
5045
5348
  return envelope;
5046
5349
  }
5350
+ function edit(args, now, deps) {
5351
+ const [target, inline] = args.positionals;
5352
+ if (args.flags.file === true) return err("edit", "INVALID_INPUT", "--file needs a path");
5353
+ const file = str(args, "file");
5354
+ if (file === void 0) return runEdit(target, inline, now, deps);
5355
+ if (inline !== void 0) {
5356
+ return err("edit", "INVALID_INPUT", "pass the new text inline or with --file, not both");
5357
+ }
5358
+ let text2;
5359
+ try {
5360
+ text2 = readFileSync3(file, "utf-8").replace(/\n$/, "");
5361
+ } catch {
5362
+ return err("edit", "INVALID_INPUT", `cannot read ${file}`);
5363
+ }
5364
+ return runEdit(target, text2, now, deps);
5365
+ }
5047
5366
  function runWrite(command, args, now, deps) {
5048
5367
  const [first, second] = args.positionals;
5049
5368
  switch (command) {
@@ -5052,7 +5371,7 @@ function runWrite(command, args, now, deps) {
5052
5371
  case "comment":
5053
5372
  return runComment(first, second, now, deps);
5054
5373
  case "edit":
5055
- return runEdit(first, second, now, deps);
5374
+ return edit(args, now, deps);
5056
5375
  case "reply":
5057
5376
  return runReply(first, second, now, deps);
5058
5377
  case "react":