linkedin-relay-mcp 1.0.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/index.js ADDED
@@ -0,0 +1,700 @@
1
+ // src/args.ts
2
+ function parseArgs(argv) {
3
+ const [command, ...rest] = argv;
4
+ const positionals = [];
5
+ const flags = {};
6
+ for (let i = 0; i < rest.length; i++) {
7
+ const token = rest[i];
8
+ if (token === void 0) continue;
9
+ if (token.startsWith("--")) {
10
+ const key = token.slice(2);
11
+ const next = rest[i + 1];
12
+ if (next !== void 0 && !next.startsWith("--")) {
13
+ flags[key] = next;
14
+ i++;
15
+ } else {
16
+ flags[key] = true;
17
+ }
18
+ } else if (token.startsWith("-") && token.length > 1) {
19
+ const key = token.slice(1);
20
+ const next = rest[i + 1];
21
+ if (next !== void 0 && !next.startsWith("-")) {
22
+ flags[key] = next;
23
+ i++;
24
+ } else {
25
+ flags[key] = true;
26
+ }
27
+ } else {
28
+ positionals.push(token);
29
+ }
30
+ }
31
+ return { command, positionals, flags };
32
+ }
33
+ function bool(args, name) {
34
+ return args.flags[name] === true || args.flags[name] === "true";
35
+ }
36
+ function str(args, name) {
37
+ const v = args.flags[name];
38
+ return typeof v === "string" ? v : void 0;
39
+ }
40
+ function num(args, name) {
41
+ const v = str(args, name);
42
+ if (v === void 0) return void 0;
43
+ const n = Number(v);
44
+ return Number.isFinite(n) ? n : void 0;
45
+ }
46
+
47
+ // src/cache/store.ts
48
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
49
+ import { homedir } from "os";
50
+ import { dirname, join } from "path";
51
+ function cacheDir() {
52
+ return process.env.LNRELAY_CACHE_DIR ?? join(homedir(), ".lnrelay");
53
+ }
54
+ function cachePath(...parts) {
55
+ return join(cacheDir(), ...parts);
56
+ }
57
+ function loadJson(path) {
58
+ if (!existsSync(path)) return { state: "missing" };
59
+ let raw;
60
+ try {
61
+ raw = readFileSync(path, "utf-8");
62
+ } catch (e) {
63
+ return quarantine(path, `unreadable: ${e.message}`);
64
+ }
65
+ try {
66
+ return { state: "ok", value: JSON.parse(raw) };
67
+ } catch (e) {
68
+ return quarantine(path, `unparseable JSON: ${e.message}`);
69
+ }
70
+ }
71
+ function quarantine(path, reason) {
72
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
73
+ const target = cachePath("quarantine", stamp, path.split("/").pop() ?? "file");
74
+ try {
75
+ mkdirSync(dirname(target), { recursive: true });
76
+ renameSync(path, target);
77
+ } catch {
78
+ }
79
+ return { state: "corrupt", quarantinedTo: target, reason };
80
+ }
81
+ function saveJson(path, value) {
82
+ mkdirSync(dirname(path), { recursive: true });
83
+ const tmp = `${path}.tmp`;
84
+ writeFileSync(tmp, JSON.stringify(value, null, 2), { encoding: "utf-8", mode: 384 });
85
+ renameSync(tmp, path);
86
+ }
87
+
88
+ // src/commands/local.ts
89
+ import { existsSync as existsSync2 } from "fs";
90
+ import { version as nodeVersion } from "process";
91
+
92
+ // src/engine/budget.ts
93
+ var HOUR = 36e5;
94
+ var DAY = 864e5;
95
+ var CAPS = {
96
+ profile: {
97
+ perDay: 30,
98
+ provenance: "vendor-lore",
99
+ note: "transplanted from jjuanrivvera/linkedin-cli's job-detail cap"
100
+ },
101
+ search: { perDay: 25, provenance: "guessed", note: "no corroborated figure exists" },
102
+ page: { perDay: 60, provenance: "guessed", note: "thread/feed pagination" },
103
+ write: {
104
+ perDay: 10,
105
+ provenance: "guessed",
106
+ note: "deliberately below the weakly-reported ~20/day connection lore"
107
+ },
108
+ global: { perDay: 250, provenance: "guessed", note: "all classes combined" }
109
+ };
110
+ var MIN_GAP_MS = 3e3;
111
+ function emptyLedger() {
112
+ return { spends: {} };
113
+ }
114
+ function within(times, now, window) {
115
+ if (times === void 0) return [];
116
+ return times.filter((t) => now - t < window);
117
+ }
118
+ function allSpends(ledger, now) {
119
+ return Object.values(ledger.spends).flatMap((times) => within(times, now, DAY));
120
+ }
121
+ function spend(ledger, cls, now) {
122
+ const recent = allSpends(ledger, now);
123
+ const last = recent.length > 0 ? Math.max(...recent) : void 0;
124
+ if (last !== void 0 && now - last < MIN_GAP_MS) {
125
+ return {
126
+ error: {
127
+ code: "BUDGET_EXHAUSTED",
128
+ message: `minimum gap of ${MIN_GAP_MS}ms between calls not met`,
129
+ hint: "requests are paced deliberately; wait and retry"
130
+ }
131
+ };
132
+ }
133
+ if (recent.length >= CAPS.global.perDay) {
134
+ return {
135
+ error: {
136
+ code: "BUDGET_EXHAUSTED",
137
+ message: `global daily cap of ${CAPS.global.perDay} calls reached`,
138
+ hint: "resets on a rolling 24h window; see `lnrelay budget`"
139
+ }
140
+ };
141
+ }
142
+ const cap = CAPS[cls];
143
+ const forClass = within(ledger.spends[cls], now, DAY);
144
+ if (forClass.length >= cap.perDay) {
145
+ return {
146
+ error: {
147
+ code: "BUDGET_EXHAUSTED",
148
+ message: `daily cap of ${cap.perDay} reached for '${cls}'`,
149
+ hint: `cap provenance: ${cap.provenance} (${cap.note}). See \`lnrelay budget\`.`
150
+ }
151
+ };
152
+ }
153
+ return {
154
+ permit: { class: cls, issuedAt: now },
155
+ ledger: { spends: { ...ledger.spends, [cls]: [...forClass, now] } }
156
+ };
157
+ }
158
+ function summarise(ledger, cls, now) {
159
+ const cap = CAPS[cls];
160
+ const spent = cls === "global" ? allSpends(ledger, now).length : within(ledger.spends[cls], now, DAY).length;
161
+ const remaining = Math.max(0, cap.perDay - spent);
162
+ const summary = {
163
+ class: cls,
164
+ spentInWindow: spent,
165
+ cap: cap.perDay,
166
+ remaining,
167
+ capProvenance: cap.provenance
168
+ };
169
+ if (remaining / cap.perDay < 0.25) {
170
+ summary.warning = `only ${remaining} of ${cap.perDay} '${cls}' calls left in this 24h window \u2014 consider stopping`;
171
+ }
172
+ return summary;
173
+ }
174
+ function openCooldown(reason, now) {
175
+ if (reason === "CHALLENGE_DETECTED") {
176
+ return { reason, since: now, until: null, clearRequires: "human" };
177
+ }
178
+ const duration = reason === "REQUEST_DENIED" ? 6 * HOUR : HOUR;
179
+ return { reason, since: now, until: now + duration, clearRequires: "time" };
180
+ }
181
+ function activeCooldown(cooldown, now) {
182
+ if (cooldown === null) return false;
183
+ if (cooldown.until === null) return true;
184
+ return now < cooldown.until;
185
+ }
186
+
187
+ // src/output.ts
188
+ function ok(command, data) {
189
+ return { ok: true, command, data };
190
+ }
191
+ function err(command, code, message, hint, status, retryAfterMs) {
192
+ const error = { code, message };
193
+ if (hint !== void 0) error.hint = hint;
194
+ if (status !== void 0) error.status = status;
195
+ if (retryAfterMs !== void 0) error.retryAfterMs = retryAfterMs;
196
+ return { ok: false, command, error };
197
+ }
198
+ function toJson(envelope) {
199
+ return JSON.stringify(envelope, null, 2);
200
+ }
201
+ var ERROR_CODES = [
202
+ // Raised before any network call is made.
203
+ "INVALID_INPUT",
204
+ "UNKNOWN_COMMAND",
205
+ "CONFIRMATION_REQUIRED",
206
+ "BUDGET_EXHAUSTED",
207
+ "COOLDOWN_ACTIVE",
208
+ "CACHE_CORRUPT",
209
+ "NOT_IMPLEMENTED",
210
+ // Raised from a response.
211
+ "AUTH_FAILED",
212
+ "RATE_LIMITED",
213
+ "REQUEST_DENIED",
214
+ // HTTP 999 — LinkedIn's non-standard bot block
215
+ "CHALLENGE_DETECTED",
216
+ "SCHEMA_DRIFT",
217
+ "NOT_FOUND",
218
+ "FETCH_FAILED",
219
+ "FETCH_TIMEOUT"
220
+ ];
221
+ function isRetryable(code) {
222
+ return code === "FETCH_TIMEOUT";
223
+ }
224
+ function exitCodeFor(envelope) {
225
+ if (envelope.ok) return 0;
226
+ return envelope.error.code === "UNKNOWN_COMMAND" ? 2 : 1;
227
+ }
228
+
229
+ // src/commands/local.ts
230
+ var LEDGER_FILE = "budget.json";
231
+ var COOLDOWN_FILE = "cooldown.json";
232
+ function loadState(file, fallback) {
233
+ const path = cachePath(file);
234
+ const result = loadJson(path);
235
+ if (result.state === "ok") return { value: result.value, corrupt: null };
236
+ if (result.state === "missing") return { value: fallback, corrupt: null };
237
+ return {
238
+ value: null,
239
+ corrupt: { path, quarantinedTo: result.quarantinedTo, reason: result.reason }
240
+ };
241
+ }
242
+ function loadLedger() {
243
+ return loadState(LEDGER_FILE, emptyLedger());
244
+ }
245
+ function loadCooldown() {
246
+ return loadState(COOLDOWN_FILE, null);
247
+ }
248
+ function runRisk(now) {
249
+ const { value: cooldown, corrupt } = loadCooldown();
250
+ if (corrupt !== null) {
251
+ return err(
252
+ "risk",
253
+ "CACHE_CORRUPT",
254
+ `cooldown state was unreadable and has been quarantined: ${corrupt.reason}`,
255
+ `moved to ${corrupt.quarantinedTo}. Inspect it, then re-run \u2014 a fresh cooldown file will be created.`
256
+ );
257
+ }
258
+ const blocked = activeCooldown(cooldown ?? null, now);
259
+ return ok("risk", {
260
+ state: blocked ? "blocked" : "ok",
261
+ cooldown: cooldown ?? null,
262
+ tosNotice: "Voyager reads breach LinkedIn User Agreement \xA78.2. This tool is not ToS-compliant and any account it touches can be restricted or permanently banned."
263
+ });
264
+ }
265
+ function runBudget(now, resetCooldown, confirmed) {
266
+ if (resetCooldown && !confirmed) {
267
+ return err(
268
+ "budget",
269
+ "CONFIRMATION_REQUIRED",
270
+ "clearing a cooldown requires --confirm",
271
+ "A cooldown means LinkedIn signalled a throttle, block or challenge. Log in through a real browser and confirm you are unblocked before clearing it. Re-run with --confirm."
272
+ );
273
+ }
274
+ if (resetCooldown) {
275
+ saveJson(cachePath(COOLDOWN_FILE), null);
276
+ }
277
+ const { value: ledger, corrupt } = loadLedger();
278
+ if (corrupt !== null) {
279
+ return err(
280
+ "budget",
281
+ "CACHE_CORRUPT",
282
+ `the spend ledger was unreadable and has been quarantined: ${corrupt.reason}`,
283
+ `moved to ${corrupt.quarantinedTo}. A corrupt ledger is NOT treated as an empty one \u2014 that would silently restore a full budget. Inspect it, then re-run.`
284
+ );
285
+ }
286
+ const classes = ["profile", "search", "page", "write", "global"];
287
+ const { value: cooldown } = loadCooldown();
288
+ return ok("budget", {
289
+ classes: classes.map((c) => ({
290
+ ...summarise(ledger ?? emptyLedger(), c, now),
291
+ note: CAPS[c].note
292
+ })),
293
+ cooldown: cooldown ?? null,
294
+ caveat: "Every cap is guessed or transplanted vendor lore \u2014 the field research found no corroborated LinkedIn rate limits. These are starting knobs, not safe thresholds. They also cannot see your manual browser activity."
295
+ });
296
+ }
297
+ function runDoctor(now, offline) {
298
+ const checks = [];
299
+ checks.push({
300
+ name: "runtime",
301
+ ok: true,
302
+ detail: `node ${nodeVersion}; cache dir ${cacheDir()}${existsSync2(cacheDir()) ? "" : " (not created yet)"}`
303
+ });
304
+ const { value: cooldown, corrupt: cooldownCorrupt } = loadCooldown();
305
+ if (cooldownCorrupt !== null) {
306
+ checks.push({
307
+ name: "cooldown",
308
+ ok: false,
309
+ detail: `state file was corrupt; quarantined to ${cooldownCorrupt.quarantinedTo}`
310
+ });
311
+ } else {
312
+ const blocked = activeCooldown(cooldown ?? null, now);
313
+ checks.push({
314
+ name: "cooldown",
315
+ ok: !blocked,
316
+ detail: blocked ? `BLOCKED \u2014 ${cooldown?.reason}, clears by ${cooldown?.clearRequires}${cooldown?.until === null ? " (indefinite)" : ` at ${new Date(cooldown?.until ?? 0).toISOString()}`}` : "clear"
317
+ });
318
+ }
319
+ const { value: ledger, corrupt: ledgerCorrupt } = loadLedger();
320
+ if (ledgerCorrupt !== null) {
321
+ checks.push({
322
+ name: "budget",
323
+ ok: false,
324
+ detail: `ledger was corrupt; quarantined to ${ledgerCorrupt.quarantinedTo}`
325
+ });
326
+ } else {
327
+ const g = summarise(ledger ?? emptyLedger(), "global", now);
328
+ checks.push({
329
+ name: "budget",
330
+ ok: g.remaining > 0,
331
+ detail: `${g.spentInWindow}/${g.cap} global calls used in the last 24h (cap provenance: ${g.capProvenance})`
332
+ });
333
+ }
334
+ const cookiePath = cachePath("cookies.json");
335
+ checks.push({
336
+ name: "session",
337
+ ok: false,
338
+ detail: existsSync2(cookiePath) ? "a cookie file exists, but the engine is not implemented yet (Phase 2)" : "no session yet \u2014 the Phase 0 capture gate has not been run. See docs/PLAN.md."
339
+ });
340
+ checks.push({
341
+ name: "engine",
342
+ ok: false,
343
+ detail: "not implemented. Phase 0 (three human-paced requests from a residential IP) must pass before engine code is written \u2014 see docs/PLAN.md."
344
+ });
345
+ if (!offline) {
346
+ checks.push({
347
+ name: "live",
348
+ ok: false,
349
+ detail: "no live checks available yet; --offline is currently the only meaningful mode"
350
+ });
351
+ }
352
+ return ok("doctor", {
353
+ healthy: checks.every((c) => c.ok),
354
+ phase: "Phase 1 \u2014 local scaffolding. No network capability exists yet, by design.",
355
+ checks
356
+ });
357
+ }
358
+
359
+ // src/commands/registry.ts
360
+ var COMMANDS = [
361
+ // ─── local / meta — no network, available today ────────────────────────────
362
+ {
363
+ name: "doctor",
364
+ cost: "free with --offline",
365
+ summary: "Diagnose setup: entry point, cache dir, cookies, cooldown, budget.",
366
+ usage: "lnrelay doctor [--offline]",
367
+ audience: ["cli", "mcp"],
368
+ risk: "local",
369
+ implemented: true
370
+ },
371
+ {
372
+ name: "budget",
373
+ cost: "free",
374
+ summary: "Spend ledger per class, with each cap's provenance. Reset a cooldown here.",
375
+ usage: "lnrelay budget [--reset-cooldown --confirm]",
376
+ audience: ["cli", "mcp"],
377
+ risk: "local",
378
+ implemented: true
379
+ },
380
+ {
381
+ name: "risk",
382
+ cost: "free",
383
+ summary: "Circuit-breaker state. Check this BEFORE spending budget on research.",
384
+ usage: "lnrelay risk",
385
+ audience: ["cli", "mcp"],
386
+ risk: "local",
387
+ implemented: true
388
+ },
389
+ // ─── session ───────────────────────────────────────────────────────────────
390
+ {
391
+ name: "login",
392
+ cost: "free \u2014 local browser",
393
+ summary: "Mint a session from a logged-in Chrome via DevTools. Stores cookies owner-only.",
394
+ usage: "lnrelay login\n Requires a Chrome started with remote debugging on port 9222 (see docs/PLAN.md).",
395
+ audience: ["cli"],
396
+ risk: "local",
397
+ implemented: true
398
+ },
399
+ // ─── reads — verified live 2026-08-01 ─────────────────────────────────────
400
+ {
401
+ name: "whoami",
402
+ cost: "1 call",
403
+ summary: "The authenticated member: name, headline, URN.",
404
+ usage: "lnrelay whoami",
405
+ audience: ["cli", "mcp"],
406
+ risk: "read",
407
+ implemented: true
408
+ },
409
+ {
410
+ name: "profile",
411
+ cost: "1 call (+1 per section)",
412
+ summary: "A member profile. Expensive sections are opt-in.",
413
+ usage: "lnrelay profile <public-id|urn|url> [--raw]\n Returns headline, location, current title, company and school. LinkedIn's profile\n projections do not return a name \u2014 use the identifier you passed in.",
414
+ audience: ["cli", "mcp"],
415
+ risk: "read",
416
+ implemented: true
417
+ },
418
+ {
419
+ name: "search",
420
+ cost: "cheap \u2014 the net",
421
+ summary: "Search people, companies or jobs. Cast wide, then deep-read the finalists.",
422
+ usage: 'lnrelay search people|companies|jobs "<query>" [--limit N]\n [--compact | --fields a,b,c] [--retain] [--raw]',
423
+ audience: ["cli", "mcp"],
424
+ risk: "read",
425
+ implemented: true
426
+ },
427
+ {
428
+ name: "post",
429
+ cost: "expensive \u2014 full read",
430
+ summary: "A post plus its comment thread, cursor-followed.",
431
+ usage: "lnrelay post <activity-urn|url> [--limit N] [--compact | --fields a,b] [--retain]\n Check meta.returnedCount / claimedCount / state. claimedCount > 0 with\n returnedCount 0 is a FAILED FETCH, not an empty thread.",
432
+ audience: ["cli", "mcp"],
433
+ risk: "read",
434
+ implemented: true
435
+ },
436
+ {
437
+ name: "reactions",
438
+ cost: "medium",
439
+ summary: "Who reacted to a post, and with which reaction.",
440
+ usage: "lnrelay reactions <activity-urn|url> [--limit N] [--compact | --fields a,b]",
441
+ audience: ["cli", "mcp"],
442
+ risk: "read",
443
+ implemented: true
444
+ },
445
+ {
446
+ name: "company",
447
+ cost: "medium",
448
+ summary: "A company page, optionally with a bounded sample of its updates.",
449
+ usage: "lnrelay company <universal-name|url> [--updates N]",
450
+ audience: ["cli", "mcp"],
451
+ risk: "read",
452
+ implemented: false
453
+ },
454
+ {
455
+ name: "job",
456
+ cost: "1 call",
457
+ summary: "A job posting detail.",
458
+ usage: "lnrelay job <job-id|url>",
459
+ audience: ["cli", "mcp"],
460
+ risk: "read",
461
+ implemented: false
462
+ },
463
+ {
464
+ name: "feed",
465
+ cost: "medium",
466
+ summary: "Your own chronological feed.",
467
+ usage: "lnrelay feed [--limit N] [--compact | --fields a,b,c] [--retain] [--raw]",
468
+ audience: ["cli", "mcp"],
469
+ risk: "read",
470
+ implemented: true
471
+ },
472
+ // ─── cache-backed — Phase 4 ────────────────────────────────────────────────
473
+ {
474
+ name: "sync",
475
+ cost: "medium \u2014 1-2 calls",
476
+ summary: "Pull your own posts or connections into the local cache for offline search.",
477
+ usage: "lnrelay sync my-posts|connections [--limit N] [--force]",
478
+ audience: ["cli"],
479
+ risk: "read",
480
+ implemented: true
481
+ },
482
+ {
483
+ name: "connections",
484
+ cost: "free \u2014 local cache",
485
+ summary: "Your connections, from the local cache. Fill it with `sync connections`.",
486
+ usage: 'lnrelay connections [-q "<query>"] [--limit N] [--compact | --fields a,b] # free; cache',
487
+ audience: ["cli", "mcp"],
488
+ risk: "read",
489
+ implemented: true
490
+ },
491
+ {
492
+ name: "my-posts",
493
+ cost: "free \u2014 local cache",
494
+ summary: "Your own authored posts, from the local cache. Fill it with `sync my-posts`.",
495
+ usage: 'lnrelay my-posts [-q "<query>"] [--limit N] [--compact | --fields a,b] # free; cache',
496
+ audience: ["cli", "mcp"],
497
+ risk: "read",
498
+ implemented: true
499
+ },
500
+ {
501
+ name: "local",
502
+ cost: "free \u2014 local cache",
503
+ summary: "Offline search across everything synced. The default research path after a sync.",
504
+ usage: 'lnrelay local "<query>" [--source connections,my-posts,third-party] [--since YYYY-MM-DD]\n [--limit N] [--compact | --fields a,b,c]',
505
+ audience: ["cli", "mcp"],
506
+ risk: "read",
507
+ implemented: true
508
+ },
509
+ {
510
+ name: "cache-status",
511
+ cost: "free \u2014 local cache",
512
+ summary: "What is cached, per source, with sync checkpoints and the retention policy.",
513
+ usage: "lnrelay cache-status",
514
+ audience: ["cli", "mcp"],
515
+ risk: "local",
516
+ implemented: true
517
+ },
518
+ {
519
+ name: "purge",
520
+ cost: "free",
521
+ summary: "Delete cached data. Never contacts LinkedIn.",
522
+ usage: "lnrelay purge [--all] --confirm # default scope: third-party only",
523
+ audience: ["cli"],
524
+ risk: "local",
525
+ implemented: true
526
+ },
527
+ // ─── writes — Phase 6, official OAuth only, never MCP ──────────────────────
528
+ {
529
+ name: "oauth",
530
+ cost: "free",
531
+ summary: "OAuth token status for writes. Never prints the token.",
532
+ usage: "lnrelay oauth",
533
+ audience: ["cli"],
534
+ risk: "local",
535
+ implemented: true
536
+ },
537
+ {
538
+ name: "share",
539
+ cost: "1 call \u2014 write",
540
+ summary: "Post to your own feed via LinkedIn's official OAuth scope.",
541
+ usage: 'lnrelay share "<text>" [--visibility public|connections]\n Stops and asks at an interactive terminal. No TTY = no write, and no network call.',
542
+ audience: ["cli"],
543
+ risk: "write",
544
+ implemented: true
545
+ },
546
+ {
547
+ name: "comment",
548
+ cost: "1 call \u2014 write",
549
+ summary: "Comment on a post via the official OAuth scope.",
550
+ usage: 'lnrelay comment <activity-urn> "<text>"',
551
+ audience: ["cli"],
552
+ risk: "write",
553
+ implemented: true
554
+ },
555
+ {
556
+ name: "react",
557
+ cost: "1 call \u2014 write",
558
+ summary: "React to a post via the official OAuth scope. Reversible.",
559
+ usage: "lnrelay react <activity-urn> [--type LIKE|PRAISE|EMPATHY|INTEREST|APPRECIATION]",
560
+ audience: ["cli"],
561
+ risk: "write",
562
+ implemented: true
563
+ }
564
+ ];
565
+ var commandNames = COMMANDS.map((c) => c.name);
566
+ function findCommand(name) {
567
+ return COMMANDS.find((c) => c.name === name);
568
+ }
569
+ function mcpCommands() {
570
+ return COMMANDS.filter((c) => c.audience.includes("mcp") && c.risk !== "write");
571
+ }
572
+ function helpText() {
573
+ const lines = ["lnrelay \u2014 deep research over LinkedIn from your own account", "", "Commands:"];
574
+ const width = Math.max(...commandNames.map((n) => n.length));
575
+ for (const c of COMMANDS) {
576
+ const flag = c.implemented ? " " : "\xB7";
577
+ lines.push(` ${flag} ${c.name.padEnd(width)} ${c.summary} [${c.cost}]`);
578
+ }
579
+ lines.push("", " \xB7 = specified in docs/DESIGN.md, not yet implemented");
580
+ lines.push("", "Run `lnrelay <command> --help` for usage.");
581
+ return lines.join("\n");
582
+ }
583
+
584
+ // src/engine/restli.ts
585
+ var ENCODED = {
586
+ "%": "%25",
587
+ // MUST be first — see below
588
+ "(": "%28",
589
+ ")": "%29",
590
+ ",": "%2C",
591
+ ":": "%3A",
592
+ "|": "%7C",
593
+ "&": "%26",
594
+ "#": "%23",
595
+ "+": "%2B",
596
+ " ": "%20"
597
+ };
598
+ var RESERVED = /[%(),:|&#+ ]/g;
599
+ function encodeScalar(value) {
600
+ if (typeof value !== "string") return String(value);
601
+ return value.replace(RESERVED, (c) => ENCODED[c] ?? c);
602
+ }
603
+ function encodeValue(value) {
604
+ if (value === void 0) return void 0;
605
+ if (Array.isArray(value)) {
606
+ const members = value.map(encodeValue).filter((m) => m !== void 0);
607
+ return `List(${members.join(",")})`;
608
+ }
609
+ if (typeof value === "object") return encodeObject(value);
610
+ return encodeScalar(value);
611
+ }
612
+ function encodeObject(obj) {
613
+ const parts = [];
614
+ for (const [key, value] of Object.entries(obj)) {
615
+ const encoded = encodeValue(value);
616
+ if (encoded !== void 0) parts.push(`${key}:${encoded}`);
617
+ }
618
+ return `(${parts.join(",")})`;
619
+ }
620
+ function encodeVariables(vars) {
621
+ return encodeObject(vars);
622
+ }
623
+ function parseTupleUrn(urn) {
624
+ const open = urn.indexOf(":(");
625
+ if (open === -1 || !urn.endsWith(")")) return null;
626
+ const namespace = urn.slice(0, open).split(":").pop();
627
+ if (namespace === void 0 || namespace === "") return null;
628
+ const body = urn.slice(open + 2, -1);
629
+ const members = [];
630
+ let depth = 0;
631
+ let current = "";
632
+ for (const char of body) {
633
+ if (char === "(") depth++;
634
+ else if (char === ")") depth--;
635
+ if (depth < 0) return null;
636
+ if (char === "," && depth === 0) {
637
+ members.push(current);
638
+ current = "";
639
+ } else {
640
+ current += char;
641
+ }
642
+ }
643
+ if (depth !== 0) return null;
644
+ members.push(current);
645
+ return { namespace, members };
646
+ }
647
+ function innerUrn(urn) {
648
+ const parsed = parseTupleUrn(urn);
649
+ const first = parsed?.members[0];
650
+ return first ?? urn;
651
+ }
652
+ var NAMESPACE_ALIASES = {
653
+ fs_miniProfile: "fsd_profile",
654
+ fs_profile: "fsd_profile"
655
+ };
656
+ function canonicalUrn(urn) {
657
+ const inner = innerUrn(urn);
658
+ const parts = inner.split(":");
659
+ const namespace = parts[2];
660
+ if (namespace === void 0) return inner;
661
+ const alias = NAMESPACE_ALIASES[namespace];
662
+ if (alias === void 0) return inner;
663
+ parts[2] = alias;
664
+ return parts.join(":");
665
+ }
666
+ export {
667
+ CAPS,
668
+ COMMANDS,
669
+ ERROR_CODES,
670
+ activeCooldown,
671
+ bool,
672
+ cacheDir,
673
+ cachePath,
674
+ canonicalUrn,
675
+ commandNames,
676
+ emptyLedger,
677
+ encodeVariables,
678
+ err,
679
+ exitCodeFor,
680
+ findCommand,
681
+ helpText,
682
+ innerUrn,
683
+ isRetryable,
684
+ loadJson,
685
+ mcpCommands,
686
+ num,
687
+ ok,
688
+ openCooldown,
689
+ parseArgs,
690
+ parseTupleUrn,
691
+ runBudget,
692
+ runDoctor,
693
+ runRisk,
694
+ saveJson,
695
+ spend,
696
+ str,
697
+ summarise,
698
+ toJson
699
+ };
700
+ //# sourceMappingURL=index.js.map