linkedin-relay-mcp 3.1.0 → 3.2.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/.claude/skills/linkedin-relay/SKILL.md +24 -11
- package/dist/cli.js +324 -143
- package/dist/cli.js.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp-shim.js +10 -1
- package/dist/mcp-shim.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -45,9 +45,9 @@ function num(args, name) {
|
|
|
45
45
|
return Number.isFinite(n) ? n : void 0;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
// src/
|
|
49
|
-
import {
|
|
50
|
-
import {
|
|
48
|
+
// src/commands/approval.ts
|
|
49
|
+
import { appendFileSync, mkdirSync as mkdirSync2 } from "fs";
|
|
50
|
+
import { dirname as dirname2 } from "path";
|
|
51
51
|
|
|
52
52
|
// src/cache/store.ts
|
|
53
53
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
@@ -90,7 +90,224 @@ function saveJson(path, value) {
|
|
|
90
90
|
renameSync(tmp, path);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
// src/output.ts
|
|
94
|
+
function ok(command, data) {
|
|
95
|
+
return { ok: true, command, data };
|
|
96
|
+
}
|
|
97
|
+
function err(command, code, message, hint, status, retryAfterMs) {
|
|
98
|
+
const error = { code, message };
|
|
99
|
+
if (hint !== void 0) error.hint = hint;
|
|
100
|
+
if (status !== void 0) error.status = status;
|
|
101
|
+
if (retryAfterMs !== void 0) error.retryAfterMs = retryAfterMs;
|
|
102
|
+
return { ok: false, command, error };
|
|
103
|
+
}
|
|
104
|
+
function toJson(envelope) {
|
|
105
|
+
return JSON.stringify(envelope, null, 2);
|
|
106
|
+
}
|
|
107
|
+
function exitCodeFor(envelope) {
|
|
108
|
+
if (envelope.ok) return 0;
|
|
109
|
+
return envelope.error.code === "UNKNOWN_COMMAND" ? 2 : 1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/commands/confirm.ts
|
|
113
|
+
import { createHash } from "crypto";
|
|
114
|
+
var APPROVAL_MODES = ["interactive", "agent", "unattended"];
|
|
115
|
+
function confirmToken(action, payload) {
|
|
116
|
+
return createHash("sha256").update(`${action}:${JSON.stringify(payload)}`).digest("hex").slice(0, 4);
|
|
117
|
+
}
|
|
118
|
+
function riskLines(transport) {
|
|
119
|
+
return transport === "oauth" ? [
|
|
120
|
+
" This write itself is sanctioned \u2014 it uses LinkedIn's own",
|
|
121
|
+
" w_member_social scope. The reads this tool performs are not."
|
|
122
|
+
] : [
|
|
123
|
+
" This goes over the PRIVATE API, not a sanctioned one. It breaches",
|
|
124
|
+
" LinkedIn User Agreement \xA78.2 and can permanently restrict this account."
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
function planToken(plan) {
|
|
128
|
+
return confirmToken(plan.action, plan.tokenBasis ?? plan.payload);
|
|
129
|
+
}
|
|
130
|
+
function previewLines(plan, budgetLine2) {
|
|
131
|
+
return [
|
|
132
|
+
`ABOUT TO ${plan.action.toUpperCase()} ON LINKEDIN`,
|
|
133
|
+
...plan.summary,
|
|
134
|
+
`via ${plan.transport === "oauth" ? "official OAuth (w_member_social)" : "Voyager (private API)"}`,
|
|
135
|
+
`undo ${plan.reversibility}`,
|
|
136
|
+
...riskLines(plan.transport).map((l) => l.trim()),
|
|
137
|
+
budgetLine2
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
function renderPlan(plan, budgetLine2) {
|
|
141
|
+
const token = planToken(plan);
|
|
142
|
+
const lines = [
|
|
143
|
+
"",
|
|
144
|
+
` ABOUT TO ${plan.action.toUpperCase()} ON LINKEDIN`,
|
|
145
|
+
` ${"\u2500".repeat(58)}`,
|
|
146
|
+
...plan.summary.map((l) => ` ${l}`),
|
|
147
|
+
` via ${plan.transport === "oauth" ? "official OAuth (w_member_social)" : "Voyager (private API)"}`,
|
|
148
|
+
` undo ${plan.reversibility}`,
|
|
149
|
+
"",
|
|
150
|
+
...riskLines(plan.transport),
|
|
151
|
+
` ${budgetLine2}`,
|
|
152
|
+
"",
|
|
153
|
+
` Type ${token} to confirm, anything else to abort: `
|
|
154
|
+
];
|
|
155
|
+
return lines.join("\n");
|
|
156
|
+
}
|
|
157
|
+
function canApprove(deps) {
|
|
158
|
+
const a = deps.approval ?? { mode: "interactive" };
|
|
159
|
+
if (a.planOnly === true || a.mode === "unattended") return true;
|
|
160
|
+
if (a.mode === "agent" && a.token !== void 0) return true;
|
|
161
|
+
return deps.isTty;
|
|
162
|
+
}
|
|
163
|
+
var refuse = (message, hint) => ({ ok: false, code: "CONFIRMATION_REQUIRED", message, hint });
|
|
164
|
+
async function confirmWrite(plan, budgetLine2, deps) {
|
|
165
|
+
const a = deps.approval ?? { mode: "interactive" };
|
|
166
|
+
const token = planToken(plan);
|
|
167
|
+
const mint = () => ({
|
|
168
|
+
ok: true,
|
|
169
|
+
confirmed: { action: plan.action, payload: plan.payload, token }
|
|
170
|
+
});
|
|
171
|
+
if (a.planOnly === true) {
|
|
172
|
+
return { ok: false, code: "PLANNED", token, preview: previewLines(plan, budgetLine2) };
|
|
173
|
+
}
|
|
174
|
+
if (a.token !== void 0) {
|
|
175
|
+
if (a.mode === "interactive") {
|
|
176
|
+
return refuse(
|
|
177
|
+
`--confirm is not accepted in interactive approval mode; nothing was sent`,
|
|
178
|
+
"In this mode only a human at a terminal approves a write. The owner can allow agents to confirm on their word with `lnrelay approval set agent`, run at a terminal."
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
if (a.token !== token) {
|
|
182
|
+
return refuse(
|
|
183
|
+
"the content changed since it was previewed \u2014 the token no longer matches; nothing was sent",
|
|
184
|
+
"Run again with --plan, show the new preview, and confirm with the new token."
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
return mint();
|
|
188
|
+
}
|
|
189
|
+
if (a.mode === "unattended") return mint();
|
|
190
|
+
if (!deps.isTty) {
|
|
191
|
+
return a.mode === "agent" ? refuse(
|
|
192
|
+
`'${plan.action}' needs the owner's approval of this exact content`,
|
|
193
|
+
"Nothing was sent. Run the same command with --plan, show the preview to the owner, and when they approve re-run it with --confirm <token>."
|
|
194
|
+
) : refuse(
|
|
195
|
+
`'${plan.action}' needs a human to confirm it at an interactive terminal`,
|
|
196
|
+
"No terminal is attached, so nothing was sent and no network call was made. Run this command yourself in a shell. There is no --yes flag; only the owner can change how writes are approved, with `lnrelay approval set`, at a terminal."
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
const answer = (await deps.prompt(renderPlan(plan, budgetLine2))).trim();
|
|
200
|
+
if (answer !== token) {
|
|
201
|
+
return refuse(
|
|
202
|
+
"aborted \u2014 the confirmation token did not match",
|
|
203
|
+
"Nothing was sent. Re-run and type the token shown in the prompt."
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return mint();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/commands/approval.ts
|
|
210
|
+
var MEANING = {
|
|
211
|
+
interactive: "every write waits for a human to type a token at a terminal",
|
|
212
|
+
agent: "an agent may write after the owner approves the exact content: --plan to preview, --confirm <token> once they say so",
|
|
213
|
+
unattended: "agents may write without asking; budget caps, cooldowns and the audit log still apply"
|
|
214
|
+
};
|
|
215
|
+
var isMode = (v) => typeof v === "string" && APPROVAL_MODES.includes(v);
|
|
216
|
+
function loadApprovalMode() {
|
|
217
|
+
const loaded = loadJson(cachePath("config.json"));
|
|
218
|
+
if (loaded.state === "missing") return { ok: true, mode: "interactive" };
|
|
219
|
+
if (loaded.state === "corrupt") {
|
|
220
|
+
return {
|
|
221
|
+
ok: false,
|
|
222
|
+
message: "the approval setting was unreadable and has been quarantined",
|
|
223
|
+
hint: `Moved to ${loaded.quarantinedTo}. Writes fall back to interactive from the next run; set another mode with \`lnrelay approval set\`.`
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const mode = loaded.value.approval ?? "interactive";
|
|
227
|
+
if (!isMode(mode)) {
|
|
228
|
+
return {
|
|
229
|
+
ok: false,
|
|
230
|
+
message: `unknown approval mode '${String(mode)}' in config.json`,
|
|
231
|
+
hint: `one of: ${APPROVAL_MODES.join(", ")}. Set it with \`lnrelay approval set <mode>\`.`
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return { ok: true, mode };
|
|
235
|
+
}
|
|
236
|
+
function setToken(mode) {
|
|
237
|
+
return confirmToken("set approval mode", mode);
|
|
238
|
+
}
|
|
239
|
+
function append(entry2) {
|
|
240
|
+
const path = cachePath("writes.jsonl");
|
|
241
|
+
mkdirSync2(dirname2(path), { recursive: true });
|
|
242
|
+
appendFileSync(path, `${JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), ...entry2 })}
|
|
243
|
+
`, {
|
|
244
|
+
mode: 384
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
var approvedInThisRun = false;
|
|
248
|
+
function wasApproved() {
|
|
249
|
+
return approvedInThisRun;
|
|
250
|
+
}
|
|
251
|
+
function auditApproval(command, mode, summary, token) {
|
|
252
|
+
approvedInThisRun = true;
|
|
253
|
+
append({ event: "approved", command, mode, summary, token });
|
|
254
|
+
}
|
|
255
|
+
function auditOutcome(command, mode, envelope) {
|
|
256
|
+
append(
|
|
257
|
+
envelope.ok ? { event: "outcome", command, mode, ok: true, data: envelope.data } : { event: "outcome", command, mode, ok: false, error: envelope.error }
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
function runApprovalShow() {
|
|
261
|
+
const loaded = loadApprovalMode();
|
|
262
|
+
if (!loaded.ok) return err("approval", "CACHE_CORRUPT", loaded.message, loaded.hint);
|
|
263
|
+
return ok("approval", {
|
|
264
|
+
mode: loaded.mode,
|
|
265
|
+
meaning: MEANING[loaded.mode],
|
|
266
|
+
audit: cachePath("writes.jsonl")
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
async function runApprovalSet(mode, deps) {
|
|
270
|
+
if (!isMode(mode)) {
|
|
271
|
+
return err(
|
|
272
|
+
"approval",
|
|
273
|
+
"INVALID_INPUT",
|
|
274
|
+
`unknown approval mode '${mode ?? ""}'`,
|
|
275
|
+
`one of: ${APPROVAL_MODES.map((m) => `${m} (${MEANING[m]})`).join("; ")}`
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
if (!deps.isTty) {
|
|
279
|
+
return err(
|
|
280
|
+
"approval",
|
|
281
|
+
"CONFIRMATION_REQUIRED",
|
|
282
|
+
"the approval mode can only be changed by a human at an interactive terminal",
|
|
283
|
+
"Nothing was changed. An agent cannot choose how its own writes are approved."
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
const token = setToken(mode);
|
|
287
|
+
const answer = (await deps.prompt(
|
|
288
|
+
[
|
|
289
|
+
"",
|
|
290
|
+
` SET LINKEDIN WRITE APPROVAL TO: ${mode.toUpperCase()}`,
|
|
291
|
+
` ${MEANING[mode]}`,
|
|
292
|
+
"",
|
|
293
|
+
` Type ${token} to confirm, anything else to abort: `
|
|
294
|
+
].join("\n")
|
|
295
|
+
)).trim();
|
|
296
|
+
if (answer !== token) {
|
|
297
|
+
return err("approval", "CONFIRMATION_REQUIRED", "aborted \u2014 nothing was changed");
|
|
298
|
+
}
|
|
299
|
+
const current = loadJson(cachePath("config.json"));
|
|
300
|
+
saveJson(cachePath("config.json"), {
|
|
301
|
+
...current.state === "ok" ? current.value : {},
|
|
302
|
+
approval: mode
|
|
303
|
+
});
|
|
304
|
+
append({ event: "mode", mode });
|
|
305
|
+
return ok("approval", { mode, meaning: MEANING[mode] });
|
|
306
|
+
}
|
|
307
|
+
|
|
93
308
|
// src/cache/db.ts
|
|
309
|
+
import { Database } from "bun:sqlite";
|
|
310
|
+
import { mkdirSync as mkdirSync3, renameSync as renameSync2 } from "fs";
|
|
94
311
|
var DB_FILE = "cache.db";
|
|
95
312
|
var THIRD_PARTY_TTL_MS = 30 * 864e5;
|
|
96
313
|
function fold(value) {
|
|
@@ -130,7 +347,7 @@ var CacheCorrupt = class extends Error {
|
|
|
130
347
|
quarantinedTo;
|
|
131
348
|
};
|
|
132
349
|
function openDb(now = Date.now()) {
|
|
133
|
-
|
|
350
|
+
mkdirSync3(cacheDir(), { recursive: true });
|
|
134
351
|
const path = cachePath(DB_FILE);
|
|
135
352
|
let db;
|
|
136
353
|
try {
|
|
@@ -166,7 +383,7 @@ function quarantine2(path, reason, now) {
|
|
|
166
383
|
const stamp = new Date(now).toISOString().replace(/[:.]/g, "-");
|
|
167
384
|
const target = cachePath("quarantine", stamp, DB_FILE);
|
|
168
385
|
try {
|
|
169
|
-
|
|
386
|
+
mkdirSync3(cachePath("quarantine", stamp), { recursive: true });
|
|
170
387
|
renameSync2(path, target);
|
|
171
388
|
} catch {
|
|
172
389
|
}
|
|
@@ -187,7 +404,7 @@ function upsert(db, source, rows, now = Date.now()) {
|
|
|
187
404
|
let added = 0;
|
|
188
405
|
let updated = 0;
|
|
189
406
|
const exists = db.query("SELECT 1 FROM records WHERE urn = ? AND source = ?");
|
|
190
|
-
const
|
|
407
|
+
const write2 = db.query(
|
|
191
408
|
`INSERT INTO records (urn, source, body, text, textFold, firstSeenAt, updatedAt, expiresAt)
|
|
192
409
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
193
410
|
ON CONFLICT(urn, source) DO UPDATE SET
|
|
@@ -198,7 +415,7 @@ function upsert(db, source, rows, now = Date.now()) {
|
|
|
198
415
|
for (const row of rows) {
|
|
199
416
|
if (exists.get(row.urn, source) === null) added++;
|
|
200
417
|
else updated++;
|
|
201
|
-
|
|
418
|
+
write2.run(
|
|
202
419
|
row.urn,
|
|
203
420
|
source,
|
|
204
421
|
JSON.stringify(row.body),
|
|
@@ -556,25 +773,6 @@ function compactRows(rows) {
|
|
|
556
773
|
});
|
|
557
774
|
}
|
|
558
775
|
|
|
559
|
-
// src/output.ts
|
|
560
|
-
function ok(command, data) {
|
|
561
|
-
return { ok: true, command, data };
|
|
562
|
-
}
|
|
563
|
-
function err(command, code, message, hint, status, retryAfterMs) {
|
|
564
|
-
const error = { code, message };
|
|
565
|
-
if (hint !== void 0) error.hint = hint;
|
|
566
|
-
if (status !== void 0) error.status = status;
|
|
567
|
-
if (retryAfterMs !== void 0) error.retryAfterMs = retryAfterMs;
|
|
568
|
-
return { ok: false, command, error };
|
|
569
|
-
}
|
|
570
|
-
function toJson(envelope) {
|
|
571
|
-
return JSON.stringify(envelope, null, 2);
|
|
572
|
-
}
|
|
573
|
-
function exitCodeFor(envelope) {
|
|
574
|
-
if (envelope.ok) return 0;
|
|
575
|
-
return envelope.error.code === "UNKNOWN_COMMAND" ? 2 : 1;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
776
|
// src/commands/cache.ts
|
|
579
777
|
var SOURCES = ["connections", "my-posts", "third-party"];
|
|
580
778
|
function corruptEnvelope(command, e) {
|
|
@@ -715,11 +913,11 @@ function buildHeaders(session) {
|
|
|
715
913
|
}
|
|
716
914
|
|
|
717
915
|
// src/progress.ts
|
|
718
|
-
function progressReporter(quiet,
|
|
916
|
+
function progressReporter(quiet, write2 = (s) => {
|
|
719
917
|
process.stderr.write(s);
|
|
720
918
|
}) {
|
|
721
919
|
return (msg) => {
|
|
722
|
-
if (!quiet)
|
|
920
|
+
if (!quiet) write2(`${msg}
|
|
723
921
|
`);
|
|
724
922
|
};
|
|
725
923
|
}
|
|
@@ -1935,7 +2133,7 @@ function getAllCookies(wsUrl) {
|
|
|
1935
2133
|
}
|
|
1936
2134
|
|
|
1937
2135
|
// src/engine/voyager-write.ts
|
|
1938
|
-
import { createHash } from "crypto";
|
|
2136
|
+
import { createHash as createHash2 } from "crypto";
|
|
1939
2137
|
|
|
1940
2138
|
// src/engine/voyager-media.ts
|
|
1941
2139
|
var MEDIA_UPLOAD_URL = "https://www.linkedin.com/voyager/api/voyagerVideoDashMediaUploadMetadata?action=upload";
|
|
@@ -2035,7 +2233,7 @@ function sharePayload(text2, visibility, media = []) {
|
|
|
2035
2233
|
};
|
|
2036
2234
|
}
|
|
2037
2235
|
function mediaDigest(bytes) {
|
|
2038
|
-
return
|
|
2236
|
+
return createHash2("sha256").update(bytes).digest("hex");
|
|
2039
2237
|
}
|
|
2040
2238
|
var POST_URN = /urn:li:(share|activity|ugcPost):\d+/;
|
|
2041
2239
|
function isDeletableUrn(urn) {
|
|
@@ -2115,64 +2313,6 @@ async function share(confirmed, client, bytes) {
|
|
|
2115
2313
|
|
|
2116
2314
|
// src/commands/gate.ts
|
|
2117
2315
|
import { createInterface } from "readline/promises";
|
|
2118
|
-
|
|
2119
|
-
// src/commands/confirm.ts
|
|
2120
|
-
import { createHash as createHash2 } from "crypto";
|
|
2121
|
-
function confirmToken(action, payload) {
|
|
2122
|
-
return createHash2("sha256").update(`${action}:${JSON.stringify(payload)}`).digest("hex").slice(0, 4);
|
|
2123
|
-
}
|
|
2124
|
-
function riskLines(transport) {
|
|
2125
|
-
return transport === "oauth" ? [
|
|
2126
|
-
" This write itself is sanctioned \u2014 it uses LinkedIn's own",
|
|
2127
|
-
" w_member_social scope. The reads this tool performs are not."
|
|
2128
|
-
] : [
|
|
2129
|
-
" This goes over the PRIVATE API, not a sanctioned one. It breaches",
|
|
2130
|
-
" LinkedIn User Agreement \xA78.2 and can permanently restrict this account."
|
|
2131
|
-
];
|
|
2132
|
-
}
|
|
2133
|
-
function renderPlan(plan, budgetLine2) {
|
|
2134
|
-
const token = confirmToken(plan.action, plan.payload);
|
|
2135
|
-
const lines = [
|
|
2136
|
-
"",
|
|
2137
|
-
` ABOUT TO ${plan.action.toUpperCase()} ON LINKEDIN`,
|
|
2138
|
-
` ${"\u2500".repeat(58)}`,
|
|
2139
|
-
...plan.summary.map((l) => ` ${l}`),
|
|
2140
|
-
` via ${plan.transport === "oauth" ? "official OAuth (w_member_social)" : "Voyager (private API)"}`,
|
|
2141
|
-
` undo ${plan.reversibility}`,
|
|
2142
|
-
"",
|
|
2143
|
-
...riskLines(plan.transport),
|
|
2144
|
-
` ${budgetLine2}`,
|
|
2145
|
-
"",
|
|
2146
|
-
` Type ${token} to confirm, anything else to abort: `
|
|
2147
|
-
];
|
|
2148
|
-
return lines.join("\n");
|
|
2149
|
-
}
|
|
2150
|
-
async function confirmWrite(plan, budgetLine2, deps) {
|
|
2151
|
-
if (!deps.isTty) {
|
|
2152
|
-
return {
|
|
2153
|
-
ok: false,
|
|
2154
|
-
code: "CONFIRMATION_REQUIRED",
|
|
2155
|
-
message: `'${plan.action}' needs a human to confirm it at an interactive terminal`,
|
|
2156
|
-
hint: "No terminal is attached, so nothing was sent and no network call was made. Run this command yourself in a shell. There is deliberately no --yes flag: an agent that could set one would not be confirming anything."
|
|
2157
|
-
};
|
|
2158
|
-
}
|
|
2159
|
-
const token = confirmToken(plan.action, plan.payload);
|
|
2160
|
-
const answer = (await deps.prompt(renderPlan(plan, budgetLine2))).trim();
|
|
2161
|
-
if (answer !== token) {
|
|
2162
|
-
return {
|
|
2163
|
-
ok: false,
|
|
2164
|
-
code: "CONFIRMATION_REQUIRED",
|
|
2165
|
-
message: "aborted \u2014 the confirmation token did not match",
|
|
2166
|
-
hint: "Nothing was sent. Re-run and type the token shown in the prompt."
|
|
2167
|
-
};
|
|
2168
|
-
}
|
|
2169
|
-
return {
|
|
2170
|
-
ok: true,
|
|
2171
|
-
confirmed: { action: plan.action, payload: plan.payload, token }
|
|
2172
|
-
};
|
|
2173
|
-
}
|
|
2174
|
-
|
|
2175
|
-
// src/commands/gate.ts
|
|
2176
2316
|
function ledger() {
|
|
2177
2317
|
const result = loadJson(cachePath("budget.json"));
|
|
2178
2318
|
return result.state === "ok" ? result.value : emptyLedger();
|
|
@@ -2181,6 +2321,20 @@ function budgetLine(now) {
|
|
|
2181
2321
|
const s = summarise(ledger(), "write", now);
|
|
2182
2322
|
return `${s.remaining} of ${s.cap} writes left today.`;
|
|
2183
2323
|
}
|
|
2324
|
+
function refuseUnapprovable(command, action, deps) {
|
|
2325
|
+
if (canApprove(deps)) return null;
|
|
2326
|
+
return deps.approval?.mode === "agent" ? err(
|
|
2327
|
+
command,
|
|
2328
|
+
"CONFIRMATION_REQUIRED",
|
|
2329
|
+
`${action} needs the owner's approval of this exact content`,
|
|
2330
|
+
"Nothing was sent and no network call was made. Run the same command with --plan, show the preview to the owner, and when they approve re-run it with --confirm <token>."
|
|
2331
|
+
) : err(
|
|
2332
|
+
command,
|
|
2333
|
+
"CONFIRMATION_REQUIRED",
|
|
2334
|
+
`${action} needs a human to confirm it at an interactive terminal`,
|
|
2335
|
+
"No terminal is attached, so nothing was sent and no network call was made."
|
|
2336
|
+
);
|
|
2337
|
+
}
|
|
2184
2338
|
function terminalDeps() {
|
|
2185
2339
|
return {
|
|
2186
2340
|
isTty: process.stdin.isTTY === true && process.stdout.isTTY === true,
|
|
@@ -2210,7 +2364,21 @@ function reserve(command, now, calls = 1) {
|
|
|
2210
2364
|
}
|
|
2211
2365
|
async function gateWrite(command, plan, now, deps, opts = {}) {
|
|
2212
2366
|
const outcome = await confirmWrite(plan, budgetLine(now), deps);
|
|
2367
|
+
if (!outcome.ok && outcome.code === "PLANNED") {
|
|
2368
|
+
return ok(command, {
|
|
2369
|
+
planned: true,
|
|
2370
|
+
token: outcome.token,
|
|
2371
|
+
preview: outcome.preview,
|
|
2372
|
+
next: `show this to the owner; on their approval re-run the same command with --confirm ${outcome.token}`
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2213
2375
|
if (!outcome.ok) return err(command, outcome.code, outcome.message, outcome.hint);
|
|
2376
|
+
auditApproval(
|
|
2377
|
+
command,
|
|
2378
|
+
deps.approval?.mode ?? "interactive",
|
|
2379
|
+
plan.summary,
|
|
2380
|
+
outcome.confirmed.token
|
|
2381
|
+
);
|
|
2214
2382
|
if (opts.commitSpend !== false) {
|
|
2215
2383
|
const attempt = spend(ledger(), "write", now);
|
|
2216
2384
|
if ("permit" in attempt) saveJson(cachePath("budget.json"), attempt.ledger);
|
|
@@ -2231,7 +2399,7 @@ function findOwnPost(posts, urn) {
|
|
|
2231
2399
|
(p) => typeof p.urn === "string" && postId(p.urn) === id || p.shareUrn === urn
|
|
2232
2400
|
);
|
|
2233
2401
|
}
|
|
2234
|
-
function
|
|
2402
|
+
function previewLines2(post) {
|
|
2235
2403
|
if (post === void 0) {
|
|
2236
2404
|
return [
|
|
2237
2405
|
"content COULD NOT READ THIS POST.",
|
|
@@ -2270,14 +2438,8 @@ function evict(urn, now) {
|
|
|
2270
2438
|
}
|
|
2271
2439
|
}
|
|
2272
2440
|
async function deleteComment(ref, urn, now, deps) {
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
"delete",
|
|
2276
|
-
"CONFIRMATION_REQUIRED",
|
|
2277
|
-
"deleting needs a human to confirm it at an interactive terminal",
|
|
2278
|
-
"No terminal is attached, so nothing was sent and no network call was made."
|
|
2279
|
-
);
|
|
2280
|
-
}
|
|
2441
|
+
const unapprovable = refuseUnapprovable("delete", "deleting", deps);
|
|
2442
|
+
if (unapprovable !== null) return unapprovable;
|
|
2281
2443
|
const session = loadSession();
|
|
2282
2444
|
if (session.state !== "ok") {
|
|
2283
2445
|
return err("delete", "AUTH_FAILED", "no LinkedIn session", LAUNCH_HINT);
|
|
@@ -2359,11 +2521,13 @@ async function runDelete(urn, now = Date.now(), deps, quiet = false) {
|
|
|
2359
2521
|
}
|
|
2360
2522
|
const refused = reserve("delete", now);
|
|
2361
2523
|
if (refused !== null) return refused;
|
|
2524
|
+
const unapprovable = refuseUnapprovable("delete", "deleting", deps ?? terminalDeps());
|
|
2525
|
+
if (unapprovable !== null) return unapprovable;
|
|
2362
2526
|
const post = await lookup(urn, quiet);
|
|
2363
2527
|
const plan = {
|
|
2364
2528
|
action: "delete a post",
|
|
2365
2529
|
payload: { urn },
|
|
2366
|
-
summary: [`post ${urn}`, ...
|
|
2530
|
+
summary: [`post ${urn}`, ...previewLines2(post)],
|
|
2367
2531
|
reversibility: "NONE. A deleted post is gone, with its comments and reactions.",
|
|
2368
2532
|
transport: "voyager"
|
|
2369
2533
|
};
|
|
@@ -3124,11 +3288,20 @@ var COMMANDS = [
|
|
|
3124
3288
|
risk: "local",
|
|
3125
3289
|
implemented: true
|
|
3126
3290
|
},
|
|
3291
|
+
{
|
|
3292
|
+
name: "approval",
|
|
3293
|
+
cost: "free \u2014 local",
|
|
3294
|
+
summary: "Show or set how writes are approved: interactive (a human at a terminal), agent (the owner approves a --plan preview in chat), or unattended. Only a terminal can change it.",
|
|
3295
|
+
usage: "lnrelay approval [show]\n lnrelay approval set <interactive|agent|unattended>\n Setting needs an interactive terminal and a typed token. Every approval and outcome\n is appended to ~/.lnrelay/writes.jsonl.",
|
|
3296
|
+
audience: ["cli"],
|
|
3297
|
+
risk: "local",
|
|
3298
|
+
implemented: true
|
|
3299
|
+
},
|
|
3127
3300
|
{
|
|
3128
3301
|
name: "share",
|
|
3129
3302
|
cost: "1 call \u2014 write",
|
|
3130
3303
|
summary: "Post to your own feed. Prefers LinkedIn's official OAuth scope, falls back to the private API when no token exists \u2014 the prompt always names which.",
|
|
3131
|
-
usage: 'lnrelay share "<text>" [--image <path> | --video <path>] [--visibility public|connections]\n [--via oauth|voyager]\n
|
|
3304
|
+
usage: 'lnrelay share "<text>" [--image <path> | --video <path>] [--visibility public|connections]\n [--via oauth|voyager]\n Approval follows `lnrelay approval`: --plan previews and returns a token without\n sending; --confirm <token> sends it in agent mode. In interactive mode it asks at a\n terminal. --image (png/jpg/gif/webp) or --video (mp4/mov) uploads the file first, over the\n private API only; the prompt shows its size and sha256.',
|
|
3132
3305
|
audience: ["cli"],
|
|
3133
3306
|
risk: "write",
|
|
3134
3307
|
implemented: true
|
|
@@ -3902,14 +4075,8 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
|
|
|
3902
4075
|
"Pass urn:li:activity:<id>."
|
|
3903
4076
|
);
|
|
3904
4077
|
}
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
"comment",
|
|
3908
|
-
"CONFIRMATION_REQUIRED",
|
|
3909
|
-
"commenting needs a human to confirm it at an interactive terminal",
|
|
3910
|
-
"No terminal is attached, so nothing was sent and no network call was made."
|
|
3911
|
-
);
|
|
3912
|
-
}
|
|
4078
|
+
const unapprovable = refuseUnapprovable("comment", "commenting", deps);
|
|
4079
|
+
if (unapprovable !== null) return unapprovable;
|
|
3913
4080
|
const ctx = prepare("comment", now, "voyager");
|
|
3914
4081
|
if ("ok" in ctx) return ctx;
|
|
3915
4082
|
if (ctx.transport.kind !== "voyager") {
|
|
@@ -3921,6 +4088,9 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
|
|
|
3921
4088
|
const plan = {
|
|
3922
4089
|
action: "comment on a post",
|
|
3923
4090
|
payload: { activityId, text: text2, tokens: harvested.tokens },
|
|
4091
|
+
// The harvested trackingId changes on every render, so --plan and --confirm
|
|
4092
|
+
// would never agree on a token derived from it. The intent is what's approved.
|
|
4093
|
+
tokenBasis: { activityId, text: text2 },
|
|
3924
4094
|
summary: [authorLine(ctx.transport), `on ${postUrn2}`, `content "${text2}"`],
|
|
3925
4095
|
reversibility: "deletable with `lnrelay delete <comment-urn>`; the author is notified immediately",
|
|
3926
4096
|
transport: "voyager"
|
|
@@ -3951,14 +4121,8 @@ async function runEdit(commentUrn, text2, now = Date.now(), deps = terminalDeps(
|
|
|
3951
4121
|
"Only comments can be edited here \u2014 a published post cannot. Get the urn from `lnrelay post <activity-urn>`."
|
|
3952
4122
|
);
|
|
3953
4123
|
}
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
"edit",
|
|
3957
|
-
"CONFIRMATION_REQUIRED",
|
|
3958
|
-
"editing needs a human to confirm it at an interactive terminal",
|
|
3959
|
-
"No terminal is attached, so nothing was sent and no network call was made."
|
|
3960
|
-
);
|
|
3961
|
-
}
|
|
4124
|
+
const unapprovable = refuseUnapprovable("edit", "editing", deps);
|
|
4125
|
+
if (unapprovable !== null) return unapprovable;
|
|
3962
4126
|
const ctx = prepare("edit", now, "voyager");
|
|
3963
4127
|
if ("ok" in ctx) return ctx;
|
|
3964
4128
|
if (ctx.transport.kind !== "voyager") {
|
|
@@ -4042,14 +4206,8 @@ async function runReply(commentUrn, text2, now = Date.now(), deps = terminalDeps
|
|
|
4042
4206
|
"To comment on a POST, use `lnrelay comment <activity-urn>`. Comment urns come from `lnrelay post <activity-urn>`."
|
|
4043
4207
|
);
|
|
4044
4208
|
}
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
"reply",
|
|
4048
|
-
"CONFIRMATION_REQUIRED",
|
|
4049
|
-
"replying needs a human to confirm it at an interactive terminal",
|
|
4050
|
-
"No terminal is attached, so nothing was sent and no network call was made."
|
|
4051
|
-
);
|
|
4052
|
-
}
|
|
4209
|
+
const unapprovable = refuseUnapprovable("reply", "replying", deps);
|
|
4210
|
+
if (unapprovable !== null) return unapprovable;
|
|
4053
4211
|
const ctx = prepare("reply", now, "voyager");
|
|
4054
4212
|
if ("ok" in ctx) return ctx;
|
|
4055
4213
|
if (ctx.transport.kind !== "voyager") {
|
|
@@ -4163,7 +4321,10 @@ async function dispatch(argv, now) {
|
|
|
4163
4321
|
`Usage when it lands: ${def.usage.split("\n")[0]}. See docs/PLAN.md for the phase it belongs to.`
|
|
4164
4322
|
);
|
|
4165
4323
|
}
|
|
4324
|
+
if (def.risk === "write") return write(command, args, now);
|
|
4166
4325
|
switch (command) {
|
|
4326
|
+
case "approval":
|
|
4327
|
+
return args.positionals[0] === "set" ? runApprovalSet(args.positionals[1], terminalDeps()) : runApprovalShow();
|
|
4167
4328
|
case "doctor":
|
|
4168
4329
|
return runDoctor(now, bool(args, "offline"));
|
|
4169
4330
|
case "budget":
|
|
@@ -4205,24 +4366,6 @@ async function dispatch(argv, now) {
|
|
|
4205
4366
|
return runLogin();
|
|
4206
4367
|
case "oauth":
|
|
4207
4368
|
return oauth(args);
|
|
4208
|
-
case "share":
|
|
4209
|
-
return share3(args, now);
|
|
4210
|
-
case "comment":
|
|
4211
|
-
return runComment(args.positionals[0], args.positionals[1], now);
|
|
4212
|
-
case "edit":
|
|
4213
|
-
return runEdit(args.positionals[0], args.positionals[1], now);
|
|
4214
|
-
case "reply":
|
|
4215
|
-
return runReply(args.positionals[0], args.positionals[1], now);
|
|
4216
|
-
case "react":
|
|
4217
|
-
return runReact(
|
|
4218
|
-
args.positionals[0],
|
|
4219
|
-
str(args, "type") ?? "LIKE",
|
|
4220
|
-
now,
|
|
4221
|
-
void 0,
|
|
4222
|
-
bool(args, "remove")
|
|
4223
|
-
);
|
|
4224
|
-
case "delete":
|
|
4225
|
-
return runDelete(args.positionals[0], now, void 0, bool(args, "quiet"));
|
|
4226
4369
|
case "whoami":
|
|
4227
4370
|
return runWhoami(bool(args, "raw"));
|
|
4228
4371
|
case "profile":
|
|
@@ -4263,7 +4406,45 @@ if (entry.run) {
|
|
|
4263
4406
|
`);
|
|
4264
4407
|
process.exit(exitCodeFor(envelope));
|
|
4265
4408
|
}
|
|
4266
|
-
function
|
|
4409
|
+
async function write(command, args, now) {
|
|
4410
|
+
if (args.flags.confirm === true) {
|
|
4411
|
+
return err(
|
|
4412
|
+
command,
|
|
4413
|
+
"INVALID_INPUT",
|
|
4414
|
+
"--confirm needs the token that --plan returned",
|
|
4415
|
+
`lnrelay ${command} \u2026 --plan, then the same command with --confirm <token>`
|
|
4416
|
+
);
|
|
4417
|
+
}
|
|
4418
|
+
const mode = loadApprovalMode();
|
|
4419
|
+
if (!mode.ok) return err(command, "CACHE_CORRUPT", mode.message, mode.hint);
|
|
4420
|
+
const deps = {
|
|
4421
|
+
...terminalDeps(),
|
|
4422
|
+
approval: { mode: mode.mode, token: str(args, "confirm"), planOnly: bool(args, "plan") }
|
|
4423
|
+
};
|
|
4424
|
+
const envelope = await runWrite(command, args, now, deps);
|
|
4425
|
+
if (wasApproved()) auditOutcome(command, mode.mode, envelope);
|
|
4426
|
+
return envelope;
|
|
4427
|
+
}
|
|
4428
|
+
function runWrite(command, args, now, deps) {
|
|
4429
|
+
const [first, second] = args.positionals;
|
|
4430
|
+
switch (command) {
|
|
4431
|
+
case "share":
|
|
4432
|
+
return share3(args, now, deps);
|
|
4433
|
+
case "comment":
|
|
4434
|
+
return runComment(first, second, now, deps);
|
|
4435
|
+
case "edit":
|
|
4436
|
+
return runEdit(first, second, now, deps);
|
|
4437
|
+
case "reply":
|
|
4438
|
+
return runReply(first, second, now, deps);
|
|
4439
|
+
case "react":
|
|
4440
|
+
return runReact(first, str(args, "type") ?? "LIKE", now, deps, bool(args, "remove"));
|
|
4441
|
+
case "delete":
|
|
4442
|
+
return runDelete(first, now, deps, bool(args, "quiet"));
|
|
4443
|
+
default:
|
|
4444
|
+
return err(command, "NOT_IMPLEMENTED", `'${command}' has no write runner`);
|
|
4445
|
+
}
|
|
4446
|
+
}
|
|
4447
|
+
function share3(args, now, deps) {
|
|
4267
4448
|
const surface = via(args);
|
|
4268
4449
|
if (surface === "invalid") {
|
|
4269
4450
|
return err(
|
|
@@ -4295,7 +4476,7 @@ function share3(args, now) {
|
|
|
4295
4476
|
args.positionals[0],
|
|
4296
4477
|
str(args, "visibility") ?? "public",
|
|
4297
4478
|
now,
|
|
4298
|
-
|
|
4479
|
+
deps,
|
|
4299
4480
|
surface,
|
|
4300
4481
|
media
|
|
4301
4482
|
);
|