dp-worker 0.1.24 → 0.1.25

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.
Files changed (117) hide show
  1. package/dist/bird/sidecar-entry.js +16 -2
  2. package/dist/bird/sidecar-entry.js.map +1 -1
  3. package/dist/chrome-extension/omni-flow/manifest.json +1 -1
  4. package/node_modules/dp-shared/dist/bird-contracts.d.ts +3 -0
  5. package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
  6. package/node_modules/dp-shared/dist/bird-contracts.js +14 -0
  7. package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
  8. package/package.json +2 -2
  9. package/vendor/bird/LICENSE +21 -0
  10. package/vendor/bird/README.md +58 -0
  11. package/vendor/bird/dist/cli/pagination.d.ts +35 -0
  12. package/vendor/bird/dist/cli/pagination.js +43 -0
  13. package/vendor/bird/dist/cli/program.d.ts +5 -0
  14. package/vendor/bird/dist/cli/program.js +113 -0
  15. package/vendor/bird/dist/cli/shared.d.ts +77 -0
  16. package/vendor/bird/dist/cli/shared.js +327 -0
  17. package/vendor/bird/dist/cli.d.ts +12 -0
  18. package/vendor/bird/dist/cli.js +29 -0
  19. package/vendor/bird/dist/commands/bookmarks.d.ts +4 -0
  20. package/vendor/bird/dist/commands/bookmarks.js +189 -0
  21. package/vendor/bird/dist/commands/check.d.ts +4 -0
  22. package/vendor/bird/dist/commands/check.js +43 -0
  23. package/vendor/bird/dist/commands/follow.d.ts +4 -0
  24. package/vendor/bird/dist/commands/follow.js +91 -0
  25. package/vendor/bird/dist/commands/help.d.ts +4 -0
  26. package/vendor/bird/dist/commands/help.js +19 -0
  27. package/vendor/bird/dist/commands/home.d.ts +4 -0
  28. package/vendor/bird/dist/commands/home.js +43 -0
  29. package/vendor/bird/dist/commands/lists.d.ts +4 -0
  30. package/vendor/bird/dist/commands/lists.js +125 -0
  31. package/vendor/bird/dist/commands/news.d.ts +4 -0
  32. package/vendor/bird/dist/commands/news.js +131 -0
  33. package/vendor/bird/dist/commands/post.d.ts +4 -0
  34. package/vendor/bird/dist/commands/post.js +101 -0
  35. package/vendor/bird/dist/commands/query-ids.d.ts +4 -0
  36. package/vendor/bird/dist/commands/query-ids.js +80 -0
  37. package/vendor/bird/dist/commands/read.d.ts +4 -0
  38. package/vendor/bird/dist/commands/read.js +152 -0
  39. package/vendor/bird/dist/commands/search.d.ts +4 -0
  40. package/vendor/bird/dist/commands/search.js +115 -0
  41. package/vendor/bird/dist/commands/unbookmark.d.ts +4 -0
  42. package/vendor/bird/dist/commands/unbookmark.js +36 -0
  43. package/vendor/bird/dist/commands/user-tweets.d.ts +4 -0
  44. package/vendor/bird/dist/commands/user-tweets.js +109 -0
  45. package/vendor/bird/dist/commands/users.d.ts +4 -0
  46. package/vendor/bird/dist/commands/users.js +295 -0
  47. package/vendor/bird/dist/index.d.ts +2 -0
  48. package/vendor/bird/dist/index.js +2 -0
  49. package/vendor/bird/dist/lib/cli-args.d.ts +7 -0
  50. package/vendor/bird/dist/lib/cli-args.js +25 -0
  51. package/vendor/bird/dist/lib/cookies.d.ts +31 -0
  52. package/vendor/bird/dist/lib/cookies.js +81 -0
  53. package/vendor/bird/dist/lib/extract-bookmark-folder-id.d.ts +2 -0
  54. package/vendor/bird/dist/lib/extract-bookmark-folder-id.js +20 -0
  55. package/vendor/bird/dist/lib/extract-list-id.d.ts +2 -0
  56. package/vendor/bird/dist/lib/extract-list-id.js +19 -0
  57. package/vendor/bird/dist/lib/extract-tweet-id.d.ts +2 -0
  58. package/vendor/bird/dist/lib/extract-tweet-id.js +14 -0
  59. package/vendor/bird/dist/lib/features.json +17 -0
  60. package/vendor/bird/dist/lib/index.d.ts +10 -0
  61. package/vendor/bird/dist/lib/index.js +4 -0
  62. package/vendor/bird/dist/lib/normalize-handle.d.ts +6 -0
  63. package/vendor/bird/dist/lib/normalize-handle.js +31 -0
  64. package/vendor/bird/dist/lib/output.d.ts +29 -0
  65. package/vendor/bird/dist/lib/output.js +88 -0
  66. package/vendor/bird/dist/lib/paginate-cursor.d.ts +27 -0
  67. package/vendor/bird/dist/lib/paginate-cursor.js +37 -0
  68. package/vendor/bird/dist/lib/query-ids.json +20 -0
  69. package/vendor/bird/dist/lib/runtime-features.d.ts +19 -0
  70. package/vendor/bird/dist/lib/runtime-features.js +151 -0
  71. package/vendor/bird/dist/lib/runtime-query-ids.d.ts +33 -0
  72. package/vendor/bird/dist/lib/runtime-query-ids.js +264 -0
  73. package/vendor/bird/dist/lib/thread-filters.d.ts +8 -0
  74. package/vendor/bird/dist/lib/thread-filters.js +124 -0
  75. package/vendor/bird/dist/lib/twitter-client-base.d.ts +38 -0
  76. package/vendor/bird/dist/lib/twitter-client-base.js +129 -0
  77. package/vendor/bird/dist/lib/twitter-client-bookmarks.d.ts +7 -0
  78. package/vendor/bird/dist/lib/twitter-client-bookmarks.js +61 -0
  79. package/vendor/bird/dist/lib/twitter-client-constants.d.ts +43 -0
  80. package/vendor/bird/dist/lib/twitter-client-constants.js +50 -0
  81. package/vendor/bird/dist/lib/twitter-client-engagement.d.ts +16 -0
  82. package/vendor/bird/dist/lib/twitter-client-engagement.js +81 -0
  83. package/vendor/bird/dist/lib/twitter-client-features.d.ts +14 -0
  84. package/vendor/bird/dist/lib/twitter-client-features.js +347 -0
  85. package/vendor/bird/dist/lib/twitter-client-follow.d.ts +8 -0
  86. package/vendor/bird/dist/lib/twitter-client-follow.js +178 -0
  87. package/vendor/bird/dist/lib/twitter-client-home.d.ts +13 -0
  88. package/vendor/bird/dist/lib/twitter-client-home.js +138 -0
  89. package/vendor/bird/dist/lib/twitter-client-lists.d.ts +11 -0
  90. package/vendor/bird/dist/lib/twitter-client-lists.js +321 -0
  91. package/vendor/bird/dist/lib/twitter-client-media.d.ts +11 -0
  92. package/vendor/bird/dist/lib/twitter-client-media.js +136 -0
  93. package/vendor/bird/dist/lib/twitter-client-news.d.ts +47 -0
  94. package/vendor/bird/dist/lib/twitter-client-news.js +283 -0
  95. package/vendor/bird/dist/lib/twitter-client-posting.d.ts +8 -0
  96. package/vendor/bird/dist/lib/twitter-client-posting.js +218 -0
  97. package/vendor/bird/dist/lib/twitter-client-search.d.ts +19 -0
  98. package/vendor/bird/dist/lib/twitter-client-search.js +157 -0
  99. package/vendor/bird/dist/lib/twitter-client-timelines.d.ts +23 -0
  100. package/vendor/bird/dist/lib/twitter-client-timelines.js +471 -0
  101. package/vendor/bird/dist/lib/twitter-client-tweet-detail.d.ts +25 -0
  102. package/vendor/bird/dist/lib/twitter-client-tweet-detail.js +295 -0
  103. package/vendor/bird/dist/lib/twitter-client-types.d.ts +407 -0
  104. package/vendor/bird/dist/lib/twitter-client-types.js +2 -0
  105. package/vendor/bird/dist/lib/twitter-client-user-lookup.d.ts +16 -0
  106. package/vendor/bird/dist/lib/twitter-client-user-lookup.js +224 -0
  107. package/vendor/bird/dist/lib/twitter-client-user-tweets.d.ts +22 -0
  108. package/vendor/bird/dist/lib/twitter-client-user-tweets.js +154 -0
  109. package/vendor/bird/dist/lib/twitter-client-users.d.ts +9 -0
  110. package/vendor/bird/dist/lib/twitter-client-users.js +358 -0
  111. package/vendor/bird/dist/lib/twitter-client-utils.d.ts +173 -0
  112. package/vendor/bird/dist/lib/twitter-client-utils.js +511 -0
  113. package/vendor/bird/dist/lib/twitter-client.d.ts +23 -0
  114. package/vendor/bird/dist/lib/twitter-client.js +21 -0
  115. package/vendor/bird/dist/lib/version.d.ts +6 -0
  116. package/vendor/bird/dist/lib/version.js +174 -0
  117. package/vendor/bird/upstream-package.json +61 -0
@@ -0,0 +1,327 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import JSON5 from 'json5';
5
+ import kleur from 'kleur';
6
+ import { resolveCredentials } from '../lib/cookies.js';
7
+ import { extractTweetId } from '../lib/extract-tweet-id.js';
8
+ import { hyperlink, labelPrefix, resolveOutputConfigFromArgv, resolveOutputConfigFromCommander, statusPrefix, } from '../lib/output.js';
9
+ const COOKIE_SOURCES = ['safari', 'chrome', 'firefox'];
10
+ function parseCookieSource(value) {
11
+ const normalized = value.trim().toLowerCase();
12
+ if (normalized === 'safari' || normalized === 'chrome' || normalized === 'firefox') {
13
+ return normalized;
14
+ }
15
+ throw new Error(`Invalid --cookie-source "${value}". Allowed: safari, chrome, firefox.`);
16
+ }
17
+ export const collectCookieSource = (value, previous = []) => {
18
+ previous.push(parseCookieSource(value));
19
+ return previous;
20
+ };
21
+ function resolveCookieSourceOrder(input) {
22
+ if (typeof input === 'string') {
23
+ return [parseCookieSource(input)];
24
+ }
25
+ if (Array.isArray(input)) {
26
+ const result = [];
27
+ for (const entry of input) {
28
+ if (typeof entry !== 'string') {
29
+ continue;
30
+ }
31
+ result.push(parseCookieSource(entry));
32
+ }
33
+ return result.length > 0 ? result : undefined;
34
+ }
35
+ return undefined;
36
+ }
37
+ function resolveTimeoutMs(...values) {
38
+ for (const value of values) {
39
+ if (value === undefined || value === null || value === '') {
40
+ continue;
41
+ }
42
+ const parsed = typeof value === 'number' ? value : Number(value);
43
+ if (Number.isFinite(parsed) && parsed > 0) {
44
+ return parsed;
45
+ }
46
+ }
47
+ return undefined;
48
+ }
49
+ function resolveQuoteDepth(...values) {
50
+ for (const value of values) {
51
+ if (value === undefined || value === null || value === '') {
52
+ continue;
53
+ }
54
+ const parsed = typeof value === 'number' ? value : Number.parseInt(value, 10);
55
+ if (Number.isFinite(parsed) && parsed >= 0) {
56
+ return Math.floor(parsed);
57
+ }
58
+ }
59
+ return undefined;
60
+ }
61
+ function detectMime(path) {
62
+ const ext = path.toLowerCase();
63
+ if (ext.endsWith('.jpg') || ext.endsWith('.jpeg')) {
64
+ return 'image/jpeg';
65
+ }
66
+ if (ext.endsWith('.png')) {
67
+ return 'image/png';
68
+ }
69
+ if (ext.endsWith('.webp')) {
70
+ return 'image/webp';
71
+ }
72
+ if (ext.endsWith('.gif')) {
73
+ return 'image/gif';
74
+ }
75
+ if (ext.endsWith('.mp4') || ext.endsWith('.m4v')) {
76
+ return 'video/mp4';
77
+ }
78
+ if (ext.endsWith('.mov')) {
79
+ return 'video/quicktime';
80
+ }
81
+ return null;
82
+ }
83
+ function readConfigFile(path, warn) {
84
+ if (!existsSync(path)) {
85
+ return {};
86
+ }
87
+ try {
88
+ const raw = readFileSync(path, 'utf8');
89
+ const parsed = JSON5.parse(raw);
90
+ return parsed ?? {};
91
+ }
92
+ catch (error) {
93
+ warn(`Failed to parse config at ${path}: ${error instanceof Error ? error.message : String(error)}`);
94
+ return {};
95
+ }
96
+ }
97
+ function loadConfig(warn) {
98
+ const globalPath = join(homedir(), '.config', 'bird', 'config.json5');
99
+ const localPath = join(process.cwd(), '.birdrc.json5');
100
+ return {
101
+ ...readConfigFile(globalPath, warn),
102
+ ...readConfigFile(localPath, warn),
103
+ };
104
+ }
105
+ export function createCliContext(normalizedArgs, env = process.env) {
106
+ const isTty = process.stdout.isTTY;
107
+ let output = resolveOutputConfigFromArgv(normalizedArgs, env, isTty);
108
+ kleur.enabled = output.color;
109
+ const wrap = (styler) => (text) => isTty ? styler(text) : text;
110
+ const colors = {
111
+ banner: wrap((t) => kleur.bold().blue(t)),
112
+ subtitle: wrap((t) => kleur.dim(t)),
113
+ section: wrap((t) => kleur.bold().white(t)),
114
+ bullet: wrap((t) => kleur.blue(t)),
115
+ command: wrap((t) => kleur.bold().cyan(t)),
116
+ option: wrap((t) => kleur.cyan(t)),
117
+ argument: wrap((t) => kleur.magenta(t)),
118
+ description: wrap((t) => kleur.white(t)),
119
+ muted: wrap((t) => kleur.gray(t)),
120
+ accent: wrap((t) => kleur.green(t)),
121
+ };
122
+ const p = (kind) => {
123
+ const prefix = statusPrefix(kind, output);
124
+ if (output.plain || !output.color) {
125
+ return prefix;
126
+ }
127
+ if (kind === 'ok') {
128
+ return kleur.green(prefix);
129
+ }
130
+ if (kind === 'warn') {
131
+ return kleur.yellow(prefix);
132
+ }
133
+ if (kind === 'err') {
134
+ return kleur.red(prefix);
135
+ }
136
+ if (kind === 'info') {
137
+ return kleur.cyan(prefix);
138
+ }
139
+ return kleur.gray(prefix);
140
+ };
141
+ const l = (kind) => {
142
+ const prefix = labelPrefix(kind, output);
143
+ if (output.plain || !output.color) {
144
+ return prefix;
145
+ }
146
+ if (kind === 'url') {
147
+ return kleur.cyan(prefix);
148
+ }
149
+ if (kind === 'date') {
150
+ return kleur.magenta(prefix);
151
+ }
152
+ if (kind === 'source') {
153
+ return kleur.gray(prefix);
154
+ }
155
+ if (kind === 'engine') {
156
+ return kleur.blue(prefix);
157
+ }
158
+ if (kind === 'credentials') {
159
+ return kleur.yellow(prefix);
160
+ }
161
+ if (kind === 'user') {
162
+ return kleur.cyan(prefix);
163
+ }
164
+ if (kind === 'userId') {
165
+ return kleur.magenta(prefix);
166
+ }
167
+ if (kind === 'email') {
168
+ return kleur.green(prefix);
169
+ }
170
+ return kleur.gray(prefix);
171
+ };
172
+ const config = loadConfig((message) => {
173
+ console.error(colors.muted(`${p('warn')}${message}`));
174
+ });
175
+ function applyOutputFromCommand(command) {
176
+ const opts = command.optsWithGlobals();
177
+ output = resolveOutputConfigFromCommander(opts, env, isTty);
178
+ kleur.enabled = output.color;
179
+ }
180
+ function resolveTimeoutFromOptions(options) {
181
+ return resolveTimeoutMs(options.timeout, config.timeoutMs, env.BIRD_TIMEOUT_MS);
182
+ }
183
+ function resolveCookieTimeoutFromOptions(options) {
184
+ return resolveTimeoutMs(options.cookieTimeout, config.cookieTimeoutMs, env.BIRD_COOKIE_TIMEOUT_MS);
185
+ }
186
+ function resolveQuoteDepthFromOptions(options) {
187
+ return resolveQuoteDepth(options.quoteDepth, config.quoteDepth, env.BIRD_QUOTE_DEPTH);
188
+ }
189
+ function resolveCredentialsFromOptions(opts) {
190
+ const cookieSource = opts.cookieSource?.length
191
+ ? opts.cookieSource
192
+ : (resolveCookieSourceOrder(config.cookieSource) ?? COOKIE_SOURCES);
193
+ const chromeProfile = opts.chromeProfileDir || opts.chromeProfile || config.chromeProfileDir || config.chromeProfile;
194
+ return resolveCredentials({
195
+ authToken: opts.authToken,
196
+ ct0: opts.ct0,
197
+ cookieSource,
198
+ chromeProfile,
199
+ firefoxProfile: opts.firefoxProfile || config.firefoxProfile,
200
+ cookieTimeoutMs: resolveCookieTimeoutFromOptions(opts),
201
+ });
202
+ }
203
+ function loadMedia(opts) {
204
+ if (opts.media.length === 0) {
205
+ return [];
206
+ }
207
+ const specs = [];
208
+ for (const [index, path] of opts.media.entries()) {
209
+ const mime = detectMime(path);
210
+ if (!mime) {
211
+ throw new Error(`Unsupported media type for ${path}. Supported: jpg, jpeg, png, webp, gif, mp4, mov`);
212
+ }
213
+ const buffer = readFileSync(path);
214
+ specs.push({ path, mime, buffer, alt: opts.alts[index] });
215
+ }
216
+ const videoCount = specs.filter((m) => m.mime.startsWith('video/')).length;
217
+ if (videoCount > 1) {
218
+ throw new Error('Only one video can be attached');
219
+ }
220
+ if (videoCount === 1 && specs.length > 1) {
221
+ throw new Error('Video cannot be combined with other media');
222
+ }
223
+ if (specs.length > 4) {
224
+ throw new Error('Maximum 4 media attachments');
225
+ }
226
+ return specs;
227
+ }
228
+ function printTweets(tweets, opts = {}) {
229
+ if (opts.json) {
230
+ console.log(JSON.stringify(tweets, null, 2));
231
+ return;
232
+ }
233
+ if (tweets.length === 0) {
234
+ console.log(opts.emptyMessage ?? 'No tweets found.');
235
+ return;
236
+ }
237
+ const useEmoji = output.emoji && !output.plain;
238
+ const articleLabel = useEmoji ? '📰' : 'Article:';
239
+ const mediaLabel = (type) => {
240
+ if (useEmoji) {
241
+ return type === 'video' ? '🎬' : type === 'animated_gif' ? '🔄' : '🖼️';
242
+ }
243
+ return type === 'video' ? 'VIDEO:' : type === 'animated_gif' ? 'GIF:' : 'PHOTO:';
244
+ };
245
+ const quotePrefix = useEmoji ? { top: '┌─', mid: '│ ', bot: '└─' } : { top: '> ', mid: '> ', bot: '> ' };
246
+ for (const tweet of tweets) {
247
+ console.log(`\n@${tweet.author.username} (${tweet.author.name}):`);
248
+ // Display tweet text, with article indicator if present
249
+ if (tweet.article) {
250
+ // Full body mode: text starts with article title (from extractArticleText)
251
+ // Preview mode: text is short tweet intro that doesn't start with title
252
+ const hasFullBody = tweet.text.startsWith(tweet.article.title);
253
+ if (hasFullBody) {
254
+ console.log(`${articleLabel} ${tweet.text}`);
255
+ }
256
+ else {
257
+ console.log(`${articleLabel} ${tweet.article.title}`);
258
+ if (tweet.article.previewText) {
259
+ console.log(` ${tweet.article.previewText}`);
260
+ }
261
+ }
262
+ }
263
+ else {
264
+ console.log(tweet.text);
265
+ }
266
+ // Display media attachments
267
+ if (tweet.media && tweet.media.length > 0) {
268
+ for (const m of tweet.media) {
269
+ console.log(`${mediaLabel(m.type)} ${m.url}`);
270
+ }
271
+ }
272
+ // Display quoted tweet
273
+ if (tweet.quotedTweet) {
274
+ console.log(`${quotePrefix.top} QT @${tweet.quotedTweet.author.username}:`);
275
+ const qtText = tweet.quotedTweet.article
276
+ ? `${articleLabel} ${tweet.quotedTweet.article.title}`
277
+ : tweet.quotedTweet.text;
278
+ // Indent and truncate quoted tweet text
279
+ const maxLen = 280;
280
+ const truncated = qtText.length > maxLen ? `${qtText.slice(0, maxLen)}...` : qtText;
281
+ for (const line of truncated.split('\n').slice(0, 4)) {
282
+ console.log(`${quotePrefix.mid}${line}`);
283
+ }
284
+ // Display quoted tweet media
285
+ if (tweet.quotedTweet.media && tweet.quotedTweet.media.length > 0) {
286
+ for (const m of tweet.quotedTweet.media) {
287
+ console.log(`${quotePrefix.mid}${mediaLabel(m.type)} ${m.url}`);
288
+ }
289
+ }
290
+ console.log(`${quotePrefix.bot} https://x.com/${tweet.quotedTweet.author.username}/status/${tweet.quotedTweet.id}`);
291
+ }
292
+ if (tweet.createdAt) {
293
+ console.log(`${l('date')}${tweet.createdAt}`);
294
+ }
295
+ const tweetUrl = `https://x.com/${tweet.author.username}/status/${tweet.id}`;
296
+ console.log(`${l('url')}${hyperlink(tweetUrl, tweetUrl, output)}`);
297
+ if (opts.showSeparator ?? true) {
298
+ console.log('─'.repeat(50));
299
+ }
300
+ }
301
+ }
302
+ function printTweetsResult(result, opts) {
303
+ const tweets = result.tweets ?? [];
304
+ if (opts.json && opts.usePagination) {
305
+ console.log(JSON.stringify({ tweets, nextCursor: result.nextCursor ?? null }, null, 2));
306
+ return;
307
+ }
308
+ printTweets(tweets, { json: opts.json, emptyMessage: opts.emptyMessage });
309
+ }
310
+ return {
311
+ isTty,
312
+ getOutput: () => output,
313
+ colors,
314
+ p,
315
+ l,
316
+ config,
317
+ applyOutputFromCommand,
318
+ resolveTimeoutFromOptions,
319
+ resolveQuoteDepthFromOptions,
320
+ resolveCredentialsFromOptions,
321
+ loadMedia,
322
+ printTweets,
323
+ printTweetsResult,
324
+ extractTweetId,
325
+ };
326
+ }
327
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * bird - CLI tool for posting tweets and replies
4
+ *
5
+ * Usage:
6
+ * bird tweet "Hello world!"
7
+ * bird reply <tweet-id> "This is a reply"
8
+ * bird reply <tweet-url> "This is a reply"
9
+ * bird read <tweet-id-or-url>
10
+ */
11
+ export {};
12
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * bird - CLI tool for posting tweets and replies
4
+ *
5
+ * Usage:
6
+ * bird tweet "Hello world!"
7
+ * bird reply <tweet-id> "This is a reply"
8
+ * bird reply <tweet-url> "This is a reply"
9
+ * bird read <tweet-id-or-url>
10
+ */
11
+ import { createProgram, KNOWN_COMMANDS } from './cli/program.js';
12
+ import { createCliContext } from './cli/shared.js';
13
+ import { resolveCliInvocation } from './lib/cli-args.js';
14
+ const rawArgs = process.argv.slice(2);
15
+ const normalizedArgs = rawArgs[0] === '--' ? rawArgs.slice(1) : rawArgs;
16
+ const ctx = createCliContext(normalizedArgs);
17
+ const program = createProgram(ctx);
18
+ const { argv, showHelp } = resolveCliInvocation(normalizedArgs, KNOWN_COMMANDS);
19
+ if (showHelp) {
20
+ program.outputHelp();
21
+ process.exit(0);
22
+ }
23
+ if (argv) {
24
+ program.parse(argv);
25
+ }
26
+ else {
27
+ program.parse(['node', 'bird', ...normalizedArgs]);
28
+ }
29
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1,4 @@
1
+ import type { Command } from 'commander';
2
+ import type { CliContext } from '../cli/shared.js';
3
+ export declare function registerBookmarksCommand(program: Command, ctx: CliContext): void;
4
+ //# sourceMappingURL=bookmarks.d.ts.map
@@ -0,0 +1,189 @@
1
+ import { parsePaginationFlags } from '../cli/pagination.js';
2
+ import { extractBookmarkFolderId } from '../lib/extract-bookmark-folder-id.js';
3
+ import { addThreadMetadata, filterAuthorChain, filterAuthorOnly, filterFullChain } from '../lib/thread-filters.js';
4
+ import { TwitterClient } from '../lib/twitter-client.js';
5
+ export function registerBookmarksCommand(program, ctx) {
6
+ program
7
+ .command('bookmarks')
8
+ .description('Get your bookmarked tweets')
9
+ .option('-n, --count <number>', 'Number of bookmarks to fetch', '20')
10
+ .option('--folder-id <id>', 'Bookmark folder (collection) id')
11
+ .option('--all', 'Fetch all bookmarks (paged)')
12
+ .option('--max-pages <number>', 'Stop after N pages when using --all')
13
+ .option('--cursor <string>', 'Resume pagination from a cursor')
14
+ .option('--expand-root-only', 'Only expand threads when bookmarked tweet is root')
15
+ .option('--author-chain', 'Only include author self-reply chains connected to the bookmark')
16
+ .option('--author-only', 'Include all tweets from bookmarked tweet author in thread')
17
+ .option('--full-chain-only', 'Save entire reply chain connected to the bookmarked tweet')
18
+ .option('--include-ancestor-branches', 'Include sibling branches for ancestors when using --full-chain-only')
19
+ .option('--include-parent', 'Include direct parent tweet for non-root bookmarks')
20
+ .option('--thread-meta', 'Add metadata fields (isThread, threadPosition, etc.)')
21
+ .option('--sort-chronological', 'Sort output globally oldest -> newest')
22
+ .option('--json', 'Output as JSON')
23
+ .option('--json-full', 'Output as JSON with full raw API response in _raw field')
24
+ .action(async (cmdOpts) => {
25
+ const opts = program.opts();
26
+ const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
27
+ const count = Number.parseInt(cmdOpts.count || '20', 10);
28
+ const pagination = parsePaginationFlags(cmdOpts);
29
+ if (!pagination.ok) {
30
+ console.error(`${ctx.p('err')}${pagination.error}`);
31
+ process.exit(1);
32
+ }
33
+ const maxPages = pagination.maxPages;
34
+ const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
35
+ for (const warning of warnings) {
36
+ console.error(`${ctx.p('warn')}${warning}`);
37
+ }
38
+ if (!cookies.authToken || !cookies.ct0) {
39
+ console.error(`${ctx.p('err')}Missing required credentials`);
40
+ process.exit(1);
41
+ }
42
+ const usePagination = pagination.usePagination;
43
+ if (maxPages !== undefined && !usePagination) {
44
+ console.error(`${ctx.p('err')}--max-pages requires --all or --cursor.`);
45
+ process.exit(1);
46
+ }
47
+ if (!usePagination && (!Number.isFinite(count) || count <= 0)) {
48
+ console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
49
+ process.exit(1);
50
+ }
51
+ const client = new TwitterClient({ cookies, timeoutMs });
52
+ const folderId = cmdOpts.folderId ? extractBookmarkFolderId(cmdOpts.folderId) : null;
53
+ if (cmdOpts.folderId && !folderId) {
54
+ console.error(`${ctx.p('err')}Invalid --folder-id. Expected numeric ID or https://x.com/i/bookmarks/<id>.`);
55
+ process.exit(1);
56
+ }
57
+ const includeRaw = cmdOpts.jsonFull ?? false;
58
+ const timelineOptions = { includeRaw };
59
+ const paginationOptions = { includeRaw, maxPages, cursor: pagination.cursor };
60
+ const result = folderId
61
+ ? usePagination
62
+ ? await client.getAllBookmarkFolderTimeline(folderId, paginationOptions)
63
+ : await client.getBookmarkFolderTimeline(folderId, count, timelineOptions)
64
+ : usePagination
65
+ ? await client.getAllBookmarks(paginationOptions)
66
+ : await client.getBookmarks(count, timelineOptions);
67
+ if (!result.success) {
68
+ console.error(`${ctx.p('err')}Failed to fetch bookmarks: ${result.error}`);
69
+ process.exit(1);
70
+ }
71
+ if (cmdOpts.authorChain && (cmdOpts.authorOnly || cmdOpts.fullChainOnly)) {
72
+ console.error(`${ctx.p('warn')}--author-chain already limits to the connected self-reply chain; ` +
73
+ 'other chain filters are redundant.');
74
+ }
75
+ if (cmdOpts.includeAncestorBranches && !cmdOpts.fullChainOnly) {
76
+ console.error(`${ctx.p('warn')}--include-ancestor-branches only applies with --full-chain-only.`);
77
+ }
78
+ const bookmarks = result.tweets;
79
+ if (!bookmarks || bookmarks.length === 0) {
80
+ const emptyMessage = folderId ? 'No bookmarks found in folder.' : 'No bookmarks found.';
81
+ const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
82
+ ctx.printTweetsResult(result, { json: isJson, usePagination, emptyMessage });
83
+ return;
84
+ }
85
+ const expandedResults = [];
86
+ const threadCache = new Map();
87
+ const includeMeta = Boolean(cmdOpts.threadMeta);
88
+ const includeParent = Boolean(cmdOpts.includeParent);
89
+ const expandRootOnly = Boolean(cmdOpts.expandRootOnly);
90
+ const filterAuthorChainFlag = Boolean(cmdOpts.authorChain);
91
+ const filterAuthorOnlyFlag = Boolean(cmdOpts.authorOnly);
92
+ const filterFullChainFlag = Boolean(cmdOpts.fullChainOnly);
93
+ const includeAncestorBranches = Boolean(cmdOpts.includeAncestorBranches) && filterFullChainFlag;
94
+ const useChronologicalSort = Boolean(cmdOpts.sortChronological);
95
+ const shouldAttemptExpand = expandRootOnly || filterAuthorChainFlag || filterAuthorOnlyFlag || filterFullChainFlag;
96
+ const shouldFetchThread = shouldAttemptExpand || includeMeta;
97
+ const fetchThread = async (tweet) => {
98
+ const cachedKey = tweet.conversationId ?? tweet.id;
99
+ const cached = threadCache.get(cachedKey);
100
+ if (cached) {
101
+ return cached;
102
+ }
103
+ const threadResult = await client.getThread(tweet.id, { includeRaw });
104
+ if (!threadResult.success) {
105
+ console.error(`${ctx.p('warn')}Failed to expand thread for ${tweet.id}: ${threadResult.error ?? 'Unknown error'}`);
106
+ return null;
107
+ }
108
+ if (!threadResult.tweets) {
109
+ console.error(`${ctx.p('warn')}No thread tweets returned for ${tweet.id}.`);
110
+ return null;
111
+ }
112
+ const rootKey = threadResult.tweets[0]?.conversationId ?? cachedKey;
113
+ threadCache.set(rootKey, threadResult.tweets);
114
+ return threadResult.tweets;
115
+ };
116
+ const delayBetweenExpansionsMs = 1000;
117
+ for (let index = 0; index < bookmarks.length; index += 1) {
118
+ const bookmark = bookmarks[index];
119
+ const isRoot = !bookmark.inReplyToStatusId;
120
+ let threadTweets = null;
121
+ if (shouldFetchThread) {
122
+ if (!expandRootOnly || isRoot || includeMeta) {
123
+ if (index > 0) {
124
+ await new Promise((resolve) => setTimeout(resolve, delayBetweenExpansionsMs));
125
+ }
126
+ threadTweets = await fetchThread(bookmark);
127
+ }
128
+ }
129
+ let outputTweets = [bookmark];
130
+ if (shouldAttemptExpand) {
131
+ if (expandRootOnly && !isRoot) {
132
+ outputTweets = [bookmark];
133
+ }
134
+ else if (threadTweets) {
135
+ if (filterAuthorChainFlag) {
136
+ outputTweets = filterAuthorChain(threadTweets, bookmark);
137
+ }
138
+ else {
139
+ outputTweets = filterFullChainFlag
140
+ ? filterFullChain(threadTweets, bookmark, { includeAncestorBranches })
141
+ : threadTweets;
142
+ if (filterAuthorOnlyFlag) {
143
+ outputTweets = filterAuthorOnly(outputTweets, bookmark);
144
+ }
145
+ }
146
+ }
147
+ }
148
+ if (includeParent && bookmark.inReplyToStatusId) {
149
+ const alreadyIncluded = outputTweets.some((tweet) => tweet.id === bookmark.inReplyToStatusId);
150
+ if (!alreadyIncluded) {
151
+ const parentFromThread = threadTweets?.find((tweet) => tweet.id === bookmark.inReplyToStatusId);
152
+ if (parentFromThread) {
153
+ expandedResults.push(parentFromThread);
154
+ }
155
+ else {
156
+ const parentResult = await client.getTweet(bookmark.inReplyToStatusId, { includeRaw });
157
+ if (parentResult.success && parentResult.tweet) {
158
+ expandedResults.push(parentResult.tweet);
159
+ }
160
+ }
161
+ }
162
+ }
163
+ expandedResults.push(...outputTweets);
164
+ }
165
+ let finalResults = expandedResults;
166
+ if (includeMeta) {
167
+ finalResults = expandedResults.map((tweet) => {
168
+ const cacheKey = tweet.conversationId ?? tweet.id;
169
+ let conversationTweets = threadCache.get(cacheKey);
170
+ if (!conversationTweets) {
171
+ conversationTweets = [tweet];
172
+ }
173
+ return addThreadMetadata(tweet, conversationTweets);
174
+ });
175
+ }
176
+ const uniqueTweets = Array.from(new Map(finalResults.map((tweet) => [tweet.id, tweet])).values());
177
+ if (useChronologicalSort) {
178
+ uniqueTweets.sort((a, b) => {
179
+ const aTime = a.createdAt ? Date.parse(a.createdAt) : 0;
180
+ const bTime = b.createdAt ? Date.parse(b.createdAt) : 0;
181
+ return aTime - bTime;
182
+ });
183
+ }
184
+ const emptyMessage = folderId ? 'No bookmarks found in folder.' : 'No bookmarks found.';
185
+ const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
186
+ ctx.printTweetsResult({ tweets: uniqueTweets, nextCursor: result.nextCursor }, { json: isJson, usePagination, emptyMessage });
187
+ });
188
+ }
189
+ //# sourceMappingURL=bookmarks.js.map
@@ -0,0 +1,4 @@
1
+ import type { Command } from 'commander';
2
+ import type { CliContext } from '../cli/shared.js';
3
+ export declare function registerCheckCommand(program: Command, ctx: CliContext): void;
4
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1,43 @@
1
+ export function registerCheckCommand(program, ctx) {
2
+ program
3
+ .command('check')
4
+ .description('Check credential availability')
5
+ .action(async () => {
6
+ const opts = program.opts();
7
+ const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
8
+ console.log(`${ctx.p('info')}Credential check`);
9
+ console.log('─'.repeat(40));
10
+ if (cookies.authToken) {
11
+ console.log(`${ctx.p('ok')}auth_token: ${cookies.authToken.slice(0, 10)}...`);
12
+ }
13
+ else {
14
+ console.log(`${ctx.p('err')}auth_token: not found`);
15
+ }
16
+ if (cookies.ct0) {
17
+ console.log(`${ctx.p('ok')}ct0: ${cookies.ct0.slice(0, 10)}...`);
18
+ }
19
+ else {
20
+ console.log(`${ctx.p('err')}ct0: not found`);
21
+ }
22
+ if (cookies.source) {
23
+ console.log(`${ctx.l('source')}${cookies.source}`);
24
+ }
25
+ if (warnings.length > 0) {
26
+ console.log(`\n${ctx.p('warn')}Warnings:`);
27
+ for (const warning of warnings) {
28
+ console.log(` - ${warning}`);
29
+ }
30
+ }
31
+ if (cookies.authToken && cookies.ct0) {
32
+ console.log(`\n${ctx.p('ok')}Ready to tweet!`);
33
+ }
34
+ else {
35
+ console.log(`\n${ctx.p('err')}Missing credentials. Options:`);
36
+ console.log(' 1. Login to x.com in Safari/Chrome/Firefox');
37
+ console.log(' 2. Set AUTH_TOKEN and CT0 environment variables');
38
+ console.log(' 3. Use --auth-token and --ct0 flags');
39
+ process.exit(1);
40
+ }
41
+ });
42
+ }
43
+ //# sourceMappingURL=check.js.map
@@ -0,0 +1,4 @@
1
+ import type { Command } from 'commander';
2
+ import type { CliContext } from '../cli/shared.js';
3
+ export declare function registerFollowCommands(program: Command, ctx: CliContext): void;
4
+ //# sourceMappingURL=follow.d.ts.map