linkedin-relay-mcp 1.6.0 → 1.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.
package/dist/cli.js CHANGED
@@ -695,6 +695,21 @@ function retain(source, items) {
695
695
  }
696
696
  }
697
697
 
698
+ // src/engine/auth.ts
699
+ function csrfToken(jsessionId) {
700
+ return jsessionId.replace(/"/g, "");
701
+ }
702
+ function buildHeaders(session) {
703
+ return {
704
+ cookie: `li_at=${session.liAt}; JSESSIONID=${session.jsessionId}`,
705
+ "csrf-token": csrfToken(session.jsessionId),
706
+ "x-restli-protocol-version": "2.0.0",
707
+ accept: "application/vnd.linkedin.normalized+json+2.1",
708
+ "x-li-lang": "en_US",
709
+ "user-agent": session.userAgent
710
+ };
711
+ }
712
+
698
713
  // src/progress.ts
699
714
  function progressReporter(quiet, write = (s) => {
700
715
  process.stderr.write(s);
@@ -800,21 +815,6 @@ function activeCooldown(cooldown, now) {
800
815
  return now < cooldown.until;
801
816
  }
802
817
 
803
- // src/engine/auth.ts
804
- function csrfToken(jsessionId) {
805
- return jsessionId.replace(/"/g, "");
806
- }
807
- function buildHeaders(session) {
808
- return {
809
- cookie: `li_at=${session.liAt}; JSESSIONID=${session.jsessionId}`,
810
- "csrf-token": csrfToken(session.jsessionId),
811
- "x-restli-protocol-version": "2.0.0",
812
- accept: "application/vnd.linkedin.normalized+json+2.1",
813
- "x-li-lang": "en_US",
814
- "user-agent": session.userAgent
815
- };
816
- }
817
-
818
818
  // src/engine/classify.ts
819
819
  var CHALLENGE_MARKERS = /checkpoint|challenge|captcha|security verification|unusual activity/i;
820
820
  var LOGIN_REDIRECT = /\/login|\/uas\/login|session_redirect/i;
@@ -1565,6 +1565,247 @@ function totalResultCount(json) {
1565
1565
  return found?.[1] === void 0 ? void 0 : Number(found[1]);
1566
1566
  }
1567
1567
 
1568
+ // src/engine/sdui-harvest.ts
1569
+ function zigzag(n) {
1570
+ return n << 1n ^ n >> 63n;
1571
+ }
1572
+ function varint(n) {
1573
+ const out = [];
1574
+ let v = n;
1575
+ while (v > 0x7fn) {
1576
+ out.push(Number(v & 0x7fn | 0x80n));
1577
+ v >>= 7n;
1578
+ }
1579
+ out.push(Number(v));
1580
+ return out;
1581
+ }
1582
+ function activityIdSegment(activityId) {
1583
+ if (!/^\d+$/.test(activityId)) {
1584
+ throw new Error(`'${activityId}' is not a numeric activity id`);
1585
+ }
1586
+ const inner = [8, ...varint(zigzag(BigInt(activityId)))];
1587
+ const message = Uint8Array.from([10, inner.length, ...inner]);
1588
+ return btoa(String.fromCharCode(...message)).replace(/=+$/, "");
1589
+ }
1590
+ function keyMatchesPost(bindingKey, activityId) {
1591
+ try {
1592
+ return bindingKey.startsWith(`commentBoxText-${activityIdSegment(activityId)}-`);
1593
+ } catch {
1594
+ return false;
1595
+ }
1596
+ }
1597
+ var NOT_THE_POST = /checkpoint\/challenge|\/uas\/login|authwall|"status"\s*:\s*999/i;
1598
+ var TRACKING_PROXIMITY = 400;
1599
+ function updateTrackingId(html, activityId) {
1600
+ const idAt = [...html.matchAll(new RegExp(activityId, "g"))].map((m) => m.index ?? 0);
1601
+ if (idAt.length === 0) return null;
1602
+ const pattern = /trackingId(?:&quot;|\\?")+\s*:\s*(?:&quot;|\\?")+([A-Za-z0-9+/=]{16,32})/g;
1603
+ let best = null;
1604
+ for (const m of html.matchAll(pattern)) {
1605
+ const at = m.index ?? 0;
1606
+ const distance = Math.min(...idAt.map((p) => Math.abs(p - at)));
1607
+ if (best === null || distance < best.distance) best = { value: m[1], distance };
1608
+ }
1609
+ return best !== null && best.distance <= TRACKING_PROXIMITY ? best.value : null;
1610
+ }
1611
+ function extractCommentTokens(html, activityId) {
1612
+ if (NOT_THE_POST.test(html)) {
1613
+ return {
1614
+ ok: false,
1615
+ message: "the page returned was a challenge or sign-in wall, not the post",
1616
+ hint: "Re-mint the session with `lnrelay login`, then check `lnrelay risk`."
1617
+ };
1618
+ }
1619
+ let expected;
1620
+ try {
1621
+ expected = activityIdSegment(activityId);
1622
+ } catch (e) {
1623
+ return { ok: false, message: e.message };
1624
+ }
1625
+ const keyPattern = new RegExp(
1626
+ `commentBoxText-${expected.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-[A-Za-z0-9+/_=-]*FeedType_[A-Z_]+`
1627
+ );
1628
+ const key = keyPattern.exec(html)?.[0];
1629
+ if (key === void 0) {
1630
+ return {
1631
+ ok: false,
1632
+ message: `no comment-box binding key for post ${activityId} was found in the page`,
1633
+ 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."
1634
+ };
1635
+ }
1636
+ const trackingId = updateTrackingId(html, activityId);
1637
+ if (trackingId === null) {
1638
+ return {
1639
+ ok: false,
1640
+ message: `no trackingId adjacent to post ${activityId} was found in the page`,
1641
+ 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."
1642
+ };
1643
+ }
1644
+ return { ok: true, bindingKey: key, trackingId };
1645
+ }
1646
+
1647
+ // src/engine/sdui-menu.ts
1648
+ var SDUI_ACTION = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
1649
+ var MENU_OP = "com.linkedin.sdui.requests.comments.commentControlMenuRequest";
1650
+ var SCREEN_ID = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
1651
+ var DELETE_OP = "com.linkedin.sdui.comments.deleteComment";
1652
+ var UPDATE_OP = "com.linkedin.sdui.comments.updateComment";
1653
+ function actionUrl(operation) {
1654
+ return `${SDUI_ACTION}?sduiid=${operation}`;
1655
+ }
1656
+ function sduiEnvelope(operation, payload, states2 = []) {
1657
+ const args = {
1658
+ $type: "proto.sdui.actions.requests.RequestedArguments",
1659
+ requestedStateKeys: [],
1660
+ payload,
1661
+ requestMetadata: { $type: "proto.sdui.common.RequestMetadata" }
1662
+ };
1663
+ return {
1664
+ requestId: operation,
1665
+ serverRequest: {
1666
+ requestId: operation,
1667
+ requestedArguments: args,
1668
+ isApfcEnabled: false,
1669
+ isStreaming: false,
1670
+ rumPageKey: ""
1671
+ },
1672
+ states: states2,
1673
+ requestedArguments: { ...args, states: states2, screenId: SCREEN_ID, knownTemplateIds: [] }
1674
+ };
1675
+ }
1676
+ function menuBody(activityId, commentId, trackingId) {
1677
+ const activityUrn = { activityUrn: { activityId } };
1678
+ return sduiEnvelope(MENU_OP, {
1679
+ commentUrn: { commentId, thread: `urn:li:activity:${activityId}` },
1680
+ updateKey: {
1681
+ feedType: 3,
1682
+ items: [{ feedUpdateUrn: { updateUrnActivityUrn: activityUrn }, trackingId }],
1683
+ aggregationType: 0,
1684
+ isVideoCarousel: false
1685
+ },
1686
+ menuContentRef: `auto-component-${crypto.randomUUID()}`
1687
+ });
1688
+ }
1689
+ function extractActionPayload(stream, operation) {
1690
+ const at = stream.indexOf(operation);
1691
+ if (at === -1) return null;
1692
+ const key = stream.indexOf('"payload":', at);
1693
+ if (key === -1) return null;
1694
+ const start = stream.indexOf("{", key);
1695
+ if (start === -1) return null;
1696
+ let depth = 0;
1697
+ let inString = false;
1698
+ let escaped = false;
1699
+ for (let i = start; i < stream.length; i++) {
1700
+ const ch = stream[i];
1701
+ if (escaped) {
1702
+ escaped = false;
1703
+ } else if (ch === "\\") {
1704
+ escaped = true;
1705
+ } else if (ch === '"') {
1706
+ inString = !inString;
1707
+ } else if (!inString && ch === "{") {
1708
+ depth++;
1709
+ } else if (!inString && ch === "}") {
1710
+ depth--;
1711
+ if (depth === 0) {
1712
+ try {
1713
+ return JSON.parse(stream.slice(start, i + 1));
1714
+ } catch {
1715
+ return null;
1716
+ }
1717
+ }
1718
+ }
1719
+ }
1720
+ return null;
1721
+ }
1722
+ async function fetchCommentMenu(activityId, commentId, trackingId, client) {
1723
+ const result = await client.request({
1724
+ url: actionUrl(MENU_OP),
1725
+ method: "POST",
1726
+ body: menuBody(activityId, commentId, trackingId),
1727
+ spendClass: "page",
1728
+ operation: "commentMenu"
1729
+ });
1730
+ if (!result.ok) {
1731
+ const out = { ok: false, code: result.code, message: result.message };
1732
+ if (result.hint !== void 0) out.hint = result.hint;
1733
+ return out;
1734
+ }
1735
+ const stream = result.classification.raw ?? "";
1736
+ return { ok: true, stream };
1737
+ }
1738
+ function editStates(payload, text2) {
1739
+ const named = (field) => {
1740
+ const slot = payload[field];
1741
+ return typeof slot?.key === "string" ? slot.key : null;
1742
+ };
1743
+ const plain = named("commentary");
1744
+ const rich = named("richTextCommentary");
1745
+ if (plain === null || rich === null) return [];
1746
+ const entry2 = (key, value, protoCase) => ({
1747
+ key,
1748
+ namespace: "MemoryNamespace",
1749
+ value,
1750
+ originalProtoCase: protoCase,
1751
+ protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id: key } }
1752
+ });
1753
+ return [
1754
+ entry2(plain, text2, "stringValue"),
1755
+ entry2(rich, { text: text2, attribute: [], $type: "TextModel", source: "local" }, "textModelForWrite")
1756
+ ];
1757
+ }
1758
+ async function runCommentAction(ref, operation, trackingId, client, newText) {
1759
+ const menu = await fetchCommentMenu(ref.activityId, ref.commentId, trackingId, client);
1760
+ if (!menu.ok) return { ok: false, code: menu.code, message: menu.message };
1761
+ const payload = extractActionPayload(menu.stream, operation);
1762
+ if (payload === null) {
1763
+ return {
1764
+ ok: false,
1765
+ code: "NOT_IMPLEMENTED",
1766
+ message: `LinkedIn did not offer '${operation.split(".").pop()}' on this comment`,
1767
+ hint: "The menu lists only what the server permits \u2014 you may not own this comment, or the action may not exist on this surface. Nothing was sent."
1768
+ };
1769
+ }
1770
+ const echoed = payload.commentUrn?.commentId;
1771
+ if (echoed !== ref.commentId) {
1772
+ return {
1773
+ ok: false,
1774
+ code: "SCHEMA_DRIFT",
1775
+ message: `the menu described comment ${String(echoed)} but we asked about ${ref.commentId}`,
1776
+ hint: "Refusing to send \u2014 this is how an action lands on the wrong comment."
1777
+ };
1778
+ }
1779
+ const states2 = operation === UPDATE_OP && newText !== void 0 ? editStates(payload, newText) : [];
1780
+ if (operation === UPDATE_OP && states2.length === 0) {
1781
+ return {
1782
+ ok: false,
1783
+ code: "SCHEMA_DRIFT",
1784
+ message: "the menu did not name the comment-text state keys, so an edit cannot be built"
1785
+ };
1786
+ }
1787
+ const result = await client.request({
1788
+ url: actionUrl(operation),
1789
+ method: "POST",
1790
+ body: sduiEnvelope(operation, payload, states2),
1791
+ spendClass: "write",
1792
+ operation: operation.split(".").pop() ?? operation
1793
+ });
1794
+ if (!result.ok) {
1795
+ const out = { ok: false, code: result.code, message: result.message };
1796
+ if (result.hint !== void 0) out.hint = result.hint;
1797
+ return out;
1798
+ }
1799
+ return { ok: true, operation };
1800
+ }
1801
+ function parseCommentUrn(urn) {
1802
+ const fsd = /^urn:li:fsd_comment:\((\d+),urn:li:activity:(\d+)\)$/.exec(urn);
1803
+ if (fsd !== null) return { commentId: fsd[1], activityId: fsd[2] };
1804
+ const plain = /^urn:li:comment:\((?:urn:li:)?activity:(\d+),(\d+)\)$/.exec(urn);
1805
+ if (plain !== null) return { activityId: plain[1], commentId: plain[2] };
1806
+ return null;
1807
+ }
1808
+
1568
1809
  // src/engine/session.ts
1569
1810
  var SESSION_FILE = "session.json";
1570
1811
  function loadSession() {
@@ -1866,6 +2107,62 @@ function evict(urn, now) {
1866
2107
  throw e;
1867
2108
  }
1868
2109
  }
2110
+ async function deleteComment(ref, urn, now, deps) {
2111
+ if (!deps.isTty) {
2112
+ return err(
2113
+ "delete",
2114
+ "CONFIRMATION_REQUIRED",
2115
+ "deleting needs a human to confirm it at an interactive terminal",
2116
+ "No terminal is attached, so nothing was sent and no network call was made."
2117
+ );
2118
+ }
2119
+ const session = loadSession();
2120
+ if (session.state !== "ok") {
2121
+ return err("delete", "AUTH_FAILED", "no LinkedIn session", LAUNCH_HINT);
2122
+ }
2123
+ const refused = reserve("delete", now);
2124
+ if (refused !== null) return refused;
2125
+ const headers2 = buildHeaders(session.session);
2126
+ let html;
2127
+ try {
2128
+ const res = await fetch(
2129
+ `https://www.linkedin.com/feed/update/urn:li:activity:${ref.activityId}/`,
2130
+ {
2131
+ headers: {
2132
+ cookie: headers2.cookie ?? "",
2133
+ "user-agent": headers2["user-agent"] ?? "",
2134
+ accept: "text/html"
2135
+ },
2136
+ redirect: "manual"
2137
+ }
2138
+ );
2139
+ if (res.status !== 200) {
2140
+ return err("delete", "FETCH_FAILED", `the parent post page returned ${res.status}`);
2141
+ }
2142
+ html = await res.text();
2143
+ } catch (e) {
2144
+ return err("delete", "FETCH_FAILED", `could not load the parent post: ${e.message}`);
2145
+ }
2146
+ recordHarvestSpend(now);
2147
+ const tokens = extractCommentTokens(html, ref.activityId);
2148
+ if (!tokens.ok) return err("delete", "SCHEMA_DRIFT", tokens.message, tokens.hint);
2149
+ const plan = {
2150
+ action: "delete your comment",
2151
+ payload: { urn },
2152
+ summary: [`comment ${urn}`, `on post urn:li:activity:${ref.activityId}`],
2153
+ reversibility: "NONE. A deleted comment is gone, with its replies and reactions.",
2154
+ transport: "voyager"
2155
+ };
2156
+ const gated = await gateWrite("delete", plan, now, deps, { commitSpend: false });
2157
+ if ("ok" in gated) return gated;
2158
+ const result = await runCommentAction(
2159
+ ref,
2160
+ DELETE_OP,
2161
+ tokens.trackingId,
2162
+ createLiveClient(session.session)
2163
+ );
2164
+ return result.ok ? ok("delete", { deleted: urn, kind: "comment" }) : err("delete", result.code, result.message, result.hint);
2165
+ }
1869
2166
  async function runDelete(urn, now = Date.now(), deps, quiet = false) {
1870
2167
  if (urn === void 0 || urn === "") {
1871
2168
  return err(
@@ -1875,12 +2172,14 @@ async function runDelete(urn, now = Date.now(), deps, quiet = false) {
1875
2172
  "lnrelay delete <urn:li:share:\u2026 | urn:li:activity:\u2026>"
1876
2173
  );
1877
2174
  }
2175
+ const asComment = parseCommentUrn(urn);
2176
+ if (asComment !== null) return deleteComment(asComment, urn, now, deps ?? terminalDeps());
1878
2177
  if (!isDeletableUrn(urn)) {
1879
2178
  return err(
1880
2179
  "delete",
1881
2180
  "INVALID_INPUT",
1882
2181
  `'${urn}' does not identify a post`,
1883
- "Expected urn:li:share:<id>, urn:li:activity:<id> or urn:li:ugcPost:<id>. Refusing before encoding it, because a well-formed request naming the wrong kind of entity is a request to destroy the wrong kind of thing."
2182
+ "Expected a post urn (urn:li:share|activity|ugcPost:<id>) or a comment urn. Refusing before encoding it, because a well-formed request naming the wrong kind of entity is a request to destroy the wrong kind of thing."
1884
2183
  );
1885
2184
  }
1886
2185
  const session = loadSession();
@@ -2672,8 +2971,8 @@ var COMMANDS = [
2672
2971
  {
2673
2972
  name: "comment",
2674
2973
  cost: "1 call \u2014 write",
2675
- summary: "Comment on a post. Harvests the binding tokens from the rendered page first \u2014 no browser needed, but it costs one heavy read.",
2676
- 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.',
2974
+ summary: "Add a comment, or edit one of yours \u2014 the urn decides which. Harvests its binding tokens from the rendered page; no browser needed, but it costs one heavy read.",
2975
+ usage: 'lnrelay comment <activity-urn> "<text>" # add a comment\n lnrelay comment <comment-urn> "<text>" # EDIT that comment\n The urn decides which. Fetches the post page (~2.8 MB) to harvest a binding key and\n trackingId, and proves the key belongs to that post before asking.',
2677
2976
  audience: ["cli"],
2678
2977
  risk: "write",
2679
2978
  implemented: true
@@ -2681,8 +2980,8 @@ var COMMANDS = [
2681
2980
  {
2682
2981
  name: "delete",
2683
2982
  cost: "1 read + 1 write",
2684
- summary: "Delete one of your own posts. Reads it first and shows you its text \u2014 this is the one action that cannot be undone.",
2685
- usage: "lnrelay delete <urn:li:share:\u2026 | urn:li:activity:\u2026>",
2983
+ summary: "Delete one of your own posts or comments. Reads a post back and shows its text first \u2014 this is the one action that cannot be undone.",
2984
+ usage: "lnrelay delete <activity-urn> # a post; shows you its text before destroying it\n lnrelay delete <comment-urn> # a comment; the server decides if you may",
2686
2985
  audience: ["cli"],
2687
2986
  risk: "write",
2688
2987
  implemented: true
@@ -2916,89 +3215,10 @@ function share2(confirmed, token, deps) {
2916
3215
  );
2917
3216
  }
2918
3217
 
2919
- // src/engine/sdui-harvest.ts
2920
- function zigzag(n) {
2921
- return n << 1n ^ n >> 63n;
2922
- }
2923
- function varint(n) {
2924
- const out = [];
2925
- let v = n;
2926
- while (v > 0x7fn) {
2927
- out.push(Number(v & 0x7fn | 0x80n));
2928
- v >>= 7n;
2929
- }
2930
- out.push(Number(v));
2931
- return out;
2932
- }
2933
- function activityIdSegment(activityId) {
2934
- if (!/^\d+$/.test(activityId)) {
2935
- throw new Error(`'${activityId}' is not a numeric activity id`);
2936
- }
2937
- const inner = [8, ...varint(zigzag(BigInt(activityId)))];
2938
- const message = Uint8Array.from([10, inner.length, ...inner]);
2939
- return btoa(String.fromCharCode(...message)).replace(/=+$/, "");
2940
- }
2941
- function keyMatchesPost(bindingKey, activityId) {
2942
- try {
2943
- return bindingKey.startsWith(`commentBoxText-${activityIdSegment(activityId)}-`);
2944
- } catch {
2945
- return false;
2946
- }
2947
- }
2948
- var NOT_THE_POST = /checkpoint\/challenge|\/uas\/login|authwall|"status"\s*:\s*999/i;
2949
- var TRACKING_PROXIMITY = 400;
2950
- function updateTrackingId(html, activityId) {
2951
- const idAt = [...html.matchAll(new RegExp(activityId, "g"))].map((m) => m.index ?? 0);
2952
- if (idAt.length === 0) return null;
2953
- const pattern = /trackingId(?:&quot;|\\?")+\s*:\s*(?:&quot;|\\?")+([A-Za-z0-9+/=]{16,32})/g;
2954
- let best = null;
2955
- for (const m of html.matchAll(pattern)) {
2956
- const at = m.index ?? 0;
2957
- const distance = Math.min(...idAt.map((p) => Math.abs(p - at)));
2958
- if (best === null || distance < best.distance) best = { value: m[1], distance };
2959
- }
2960
- return best !== null && best.distance <= TRACKING_PROXIMITY ? best.value : null;
2961
- }
2962
- function extractCommentTokens(html, activityId) {
2963
- if (NOT_THE_POST.test(html)) {
2964
- return {
2965
- ok: false,
2966
- message: "the page returned was a challenge or sign-in wall, not the post",
2967
- hint: "Re-mint the session with `lnrelay login`, then check `lnrelay risk`."
2968
- };
2969
- }
2970
- let expected;
2971
- try {
2972
- expected = activityIdSegment(activityId);
2973
- } catch (e) {
2974
- return { ok: false, message: e.message };
2975
- }
2976
- const keyPattern = new RegExp(
2977
- `commentBoxText-${expected.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-[A-Za-z0-9+/_=-]*FeedType_[A-Z_]+`
2978
- );
2979
- const key = keyPattern.exec(html)?.[0];
2980
- if (key === void 0) {
2981
- return {
2982
- ok: false,
2983
- message: `no comment-box binding key for post ${activityId} was found in the page`,
2984
- 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."
2985
- };
2986
- }
2987
- const trackingId = updateTrackingId(html, activityId);
2988
- if (trackingId === null) {
2989
- return {
2990
- ok: false,
2991
- message: `no trackingId adjacent to post ${activityId} was found in the page`,
2992
- 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."
2993
- };
2994
- }
2995
- return { ok: true, bindingKey: key, trackingId };
2996
- }
2997
-
2998
3218
  // src/engine/sdui-comment.ts
2999
- var SDUI_ACTION = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
3000
- var COMMENT_URL = `${SDUI_ACTION}?sduiid=com.linkedin.sdui.comments.createComment`;
3001
- var SCREEN_ID = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
3219
+ var SDUI_ACTION2 = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
3220
+ var COMMENT_URL = `${SDUI_ACTION2}?sduiid=com.linkedin.sdui.comments.createComment`;
3221
+ var SCREEN_ID2 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
3002
3222
  var STATE_PREFIXES = [
3003
3223
  "commentBoxText",
3004
3224
  "richCommentBoxText",
@@ -3089,7 +3309,7 @@ function commentBody(activityId, text2, tokens, feedType) {
3089
3309
  requestedArguments: {
3090
3310
  ...args,
3091
3311
  states: states(text2, body),
3092
- screenId: SCREEN_ID,
3312
+ screenId: SCREEN_ID2,
3093
3313
  knownTemplateIds: []
3094
3314
  }
3095
3315
  };
@@ -3129,8 +3349,8 @@ async function comment(confirmed, client) {
3129
3349
  }
3130
3350
 
3131
3351
  // src/engine/sdui-write.ts
3132
- var SDUI_ACTION2 = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
3133
- var SCREEN_ID2 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
3352
+ var SDUI_ACTION3 = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
3353
+ var SCREEN_ID3 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
3134
3354
  var REACTIONS = [
3135
3355
  "LIKE",
3136
3356
  "PRAISE",
@@ -3151,7 +3371,7 @@ function reactionLabel(reaction) {
3151
3371
  return LABELS[reaction];
3152
3372
  }
3153
3373
  function reactionUrl(op) {
3154
- return `${SDUI_ACTION2}?sduiid=com.linkedin.sdui.reactions.${op}`;
3374
+ return `${SDUI_ACTION3}?sduiid=com.linkedin.sdui.reactions.${op}`;
3155
3375
  }
3156
3376
  function targetFor(urn) {
3157
3377
  const comment2 = /^urn:li:comment:\((urn:li:activity:\d+),(\d+)\)$/.exec(urn);
@@ -3207,7 +3427,7 @@ function sduiBody(op, target, reaction) {
3207
3427
  requestedArguments: {
3208
3428
  ...args,
3209
3429
  states: [],
3210
- screenId: SCREEN_ID2,
3430
+ screenId: SCREEN_ID3,
3211
3431
  knownTemplateIds: []
3212
3432
  }
3213
3433
  };
@@ -3380,9 +3600,15 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
3380
3600
  'lnrelay comment <urn> "<text>"'
3381
3601
  );
3382
3602
  }
3383
- const activityId = activityIdOf(postUrn2);
3603
+ const editing = parseCommentUrn(postUrn2);
3604
+ const activityId = editing?.activityId ?? activityIdOf(postUrn2);
3384
3605
  if (activityId === null) {
3385
- return err("comment", "INVALID_INPUT", `'${postUrn2}' does not identify a post`);
3606
+ return err(
3607
+ "comment",
3608
+ "INVALID_INPUT",
3609
+ `'${postUrn2}' identifies neither a post nor a comment`,
3610
+ "Pass urn:li:activity:<id> to comment, or a comment urn to edit that comment."
3611
+ );
3386
3612
  }
3387
3613
  if (!deps.isTty) {
3388
3614
  return err(
@@ -3401,19 +3627,26 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
3401
3627
  if ("ok" in harvested && harvested.ok !== true) return harvested;
3402
3628
  if (!("tokens" in harvested)) return harvested;
3403
3629
  const plan = {
3404
- action: "comment on a post",
3405
- payload: { activityId, text: text2, tokens: harvested.tokens },
3406
- summary: [authorLine(ctx.transport), `on ${postUrn2}`, `content "${text2}"`],
3407
- reversibility: "deletable from the LinkedIn UI; the author is notified immediately and cannot un-see it",
3630
+ action: editing === null ? "comment on a post" : "edit your comment",
3631
+ payload: {
3632
+ activityId,
3633
+ text: text2,
3634
+ tokens: harvested.tokens,
3635
+ ...editing === null ? {} : { edit: editing }
3636
+ },
3637
+ summary: [
3638
+ authorLine(ctx.transport),
3639
+ `on ${postUrn2}`,
3640
+ `${editing === null ? "content " : "new text"} "${text2}"`
3641
+ ],
3642
+ reversibility: editing === null ? "deletable with `lnrelay delete <comment-urn>`; the author is notified immediately" : "editable again; LinkedIn marks the comment edited and the original is not recoverable here",
3408
3643
  transport: "voyager"
3409
3644
  };
3410
3645
  const gated = await gate("comment", plan, ctx, deps);
3411
3646
  if ("ok" in gated) return gated;
3412
- const result = await comment(
3413
- gated.confirmed,
3414
- createLiveClient(ctx.transport.session)
3415
- );
3416
- return result.ok ? ok("comment", { id: result.id, on: postUrn2 }) : err("comment", result.code, result.message, result.hint);
3647
+ const client = createLiveClient(ctx.transport.session);
3648
+ const result = editing === null ? await comment(gated.confirmed, client) : await runCommentAction(editing, UPDATE_OP, harvested.tokens.trackingId, client, text2);
3649
+ return result.ok ? ok("comment", { on: postUrn2, edited: editing !== null }) : err("comment", result.code, result.message, result.hint);
3417
3650
  }
3418
3651
  var REACTIONS2 = REACTIONS;
3419
3652
  async function runReact(postUrn2, type, now = Date.now(), deps = terminalDeps(), remove = false) {