dp-worker 0.1.24 → 0.1.26
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/bird/sidecar-entry.js +16 -2
- package/dist/bird/sidecar-entry.js.map +1 -1
- package/dist/chrome-extension/omni-flow/manifest.json +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.d.ts +94 -0
- package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.js +108 -0
- package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/task-history-contracts.d.ts +2 -2
- package/package.json +4 -2
- package/vendor/bird/LICENSE +21 -0
- package/vendor/bird/README.md +116 -0
- package/vendor/bird/dist/cli/pagination.d.ts +35 -0
- package/vendor/bird/dist/cli/pagination.js +43 -0
- package/vendor/bird/dist/cli/program.d.ts +5 -0
- package/vendor/bird/dist/cli/program.js +113 -0
- package/vendor/bird/dist/cli/shared.d.ts +77 -0
- package/vendor/bird/dist/cli/shared.js +327 -0
- package/vendor/bird/dist/cli.d.ts +12 -0
- package/vendor/bird/dist/cli.js +29 -0
- package/vendor/bird/dist/commands/bookmarks.d.ts +4 -0
- package/vendor/bird/dist/commands/bookmarks.js +189 -0
- package/vendor/bird/dist/commands/check.d.ts +4 -0
- package/vendor/bird/dist/commands/check.js +43 -0
- package/vendor/bird/dist/commands/follow.d.ts +4 -0
- package/vendor/bird/dist/commands/follow.js +91 -0
- package/vendor/bird/dist/commands/help.d.ts +4 -0
- package/vendor/bird/dist/commands/help.js +19 -0
- package/vendor/bird/dist/commands/home.d.ts +4 -0
- package/vendor/bird/dist/commands/home.js +43 -0
- package/vendor/bird/dist/commands/lists.d.ts +4 -0
- package/vendor/bird/dist/commands/lists.js +125 -0
- package/vendor/bird/dist/commands/news.d.ts +4 -0
- package/vendor/bird/dist/commands/news.js +131 -0
- package/vendor/bird/dist/commands/post.d.ts +4 -0
- package/vendor/bird/dist/commands/post.js +101 -0
- package/vendor/bird/dist/commands/query-ids.d.ts +4 -0
- package/vendor/bird/dist/commands/query-ids.js +80 -0
- package/vendor/bird/dist/commands/read.d.ts +4 -0
- package/vendor/bird/dist/commands/read.js +152 -0
- package/vendor/bird/dist/commands/search.d.ts +4 -0
- package/vendor/bird/dist/commands/search.js +115 -0
- package/vendor/bird/dist/commands/unbookmark.d.ts +4 -0
- package/vendor/bird/dist/commands/unbookmark.js +36 -0
- package/vendor/bird/dist/commands/user-tweets.d.ts +4 -0
- package/vendor/bird/dist/commands/user-tweets.js +109 -0
- package/vendor/bird/dist/commands/users.d.ts +4 -0
- package/vendor/bird/dist/commands/users.js +295 -0
- package/vendor/bird/dist/index.d.ts +2 -0
- package/vendor/bird/dist/index.js +2 -0
- package/vendor/bird/dist/lib/cli-args.d.ts +7 -0
- package/vendor/bird/dist/lib/cli-args.js +25 -0
- package/vendor/bird/dist/lib/cookies.d.ts +31 -0
- package/vendor/bird/dist/lib/cookies.js +81 -0
- package/vendor/bird/dist/lib/extract-bookmark-folder-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-bookmark-folder-id.js +20 -0
- package/vendor/bird/dist/lib/extract-list-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-list-id.js +19 -0
- package/vendor/bird/dist/lib/extract-tweet-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-tweet-id.js +14 -0
- package/vendor/bird/dist/lib/features.json +17 -0
- package/vendor/bird/dist/lib/index.d.ts +10 -0
- package/vendor/bird/dist/lib/index.js +4 -0
- package/vendor/bird/dist/lib/normalize-handle.d.ts +6 -0
- package/vendor/bird/dist/lib/normalize-handle.js +31 -0
- package/vendor/bird/dist/lib/output.d.ts +29 -0
- package/vendor/bird/dist/lib/output.js +88 -0
- package/vendor/bird/dist/lib/paginate-cursor.d.ts +27 -0
- package/vendor/bird/dist/lib/paginate-cursor.js +37 -0
- package/vendor/bird/dist/lib/query-ids.json +20 -0
- package/vendor/bird/dist/lib/runtime-features.d.ts +19 -0
- package/vendor/bird/dist/lib/runtime-features.js +151 -0
- package/vendor/bird/dist/lib/runtime-query-ids.d.ts +33 -0
- package/vendor/bird/dist/lib/runtime-query-ids.js +264 -0
- package/vendor/bird/dist/lib/thread-filters.d.ts +8 -0
- package/vendor/bird/dist/lib/thread-filters.js +124 -0
- package/vendor/bird/dist/lib/twitter-client-base.d.ts +38 -0
- package/vendor/bird/dist/lib/twitter-client-base.js +129 -0
- package/vendor/bird/dist/lib/twitter-client-bookmarks.d.ts +7 -0
- package/vendor/bird/dist/lib/twitter-client-bookmarks.js +61 -0
- package/vendor/bird/dist/lib/twitter-client-constants.d.ts +43 -0
- package/vendor/bird/dist/lib/twitter-client-constants.js +50 -0
- package/vendor/bird/dist/lib/twitter-client-engagement.d.ts +16 -0
- package/vendor/bird/dist/lib/twitter-client-engagement.js +81 -0
- package/vendor/bird/dist/lib/twitter-client-features.d.ts +14 -0
- package/vendor/bird/dist/lib/twitter-client-features.js +347 -0
- package/vendor/bird/dist/lib/twitter-client-follow.d.ts +8 -0
- package/vendor/bird/dist/lib/twitter-client-follow.js +178 -0
- package/vendor/bird/dist/lib/twitter-client-home.d.ts +13 -0
- package/vendor/bird/dist/lib/twitter-client-home.js +138 -0
- package/vendor/bird/dist/lib/twitter-client-lists.d.ts +11 -0
- package/vendor/bird/dist/lib/twitter-client-lists.js +321 -0
- package/vendor/bird/dist/lib/twitter-client-media.d.ts +11 -0
- package/vendor/bird/dist/lib/twitter-client-media.js +136 -0
- package/vendor/bird/dist/lib/twitter-client-news.d.ts +47 -0
- package/vendor/bird/dist/lib/twitter-client-news.js +283 -0
- package/vendor/bird/dist/lib/twitter-client-posting.d.ts +8 -0
- package/vendor/bird/dist/lib/twitter-client-posting.js +218 -0
- package/vendor/bird/dist/lib/twitter-client-search.d.ts +19 -0
- package/vendor/bird/dist/lib/twitter-client-search.js +157 -0
- package/vendor/bird/dist/lib/twitter-client-timelines.d.ts +23 -0
- package/vendor/bird/dist/lib/twitter-client-timelines.js +471 -0
- package/vendor/bird/dist/lib/twitter-client-tweet-detail.d.ts +25 -0
- package/vendor/bird/dist/lib/twitter-client-tweet-detail.js +295 -0
- package/vendor/bird/dist/lib/twitter-client-types.d.ts +407 -0
- package/vendor/bird/dist/lib/twitter-client-types.js +2 -0
- package/vendor/bird/dist/lib/twitter-client-user-lookup.d.ts +16 -0
- package/vendor/bird/dist/lib/twitter-client-user-lookup.js +224 -0
- package/vendor/bird/dist/lib/twitter-client-user-tweets.d.ts +22 -0
- package/vendor/bird/dist/lib/twitter-client-user-tweets.js +154 -0
- package/vendor/bird/dist/lib/twitter-client-users.d.ts +9 -0
- package/vendor/bird/dist/lib/twitter-client-users.js +358 -0
- package/vendor/bird/dist/lib/twitter-client-utils.d.ts +173 -0
- package/vendor/bird/dist/lib/twitter-client-utils.js +511 -0
- package/vendor/bird/dist/lib/twitter-client.d.ts +23 -0
- package/vendor/bird/dist/lib/twitter-client.js +21 -0
- package/vendor/bird/dist/lib/version.d.ts +6 -0
- package/vendor/bird/dist/lib/version.js +174 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# vendor/bird — `@steipete/bird` 0.8.0 的内置副本
|
|
2
|
+
|
|
3
|
+
**这不是依赖,是我们自己维护的代码。** 改这里的文件是允许的,也是预期的。
|
|
4
|
+
|
|
5
|
+
## 为什么拷进来
|
|
6
|
+
|
|
7
|
+
`@steipete/bird` 的公开分发在 2026-01 停了,而且不是"项目死了":
|
|
8
|
+
|
|
9
|
+
| 事实 | 值 |
|
|
10
|
+
|---|---|
|
|
11
|
+
| npm `@steipete/bird` | **全版本 deprecated**,冻结在 0.8.0 / 2026-01-19 |
|
|
12
|
+
| `github.com/steipete/bird` | HTTP 404 |
|
|
13
|
+
| `github.com/steipete/birdclaw`(对照) | HTTP 200,且 npm 上没 deprecated |
|
|
14
|
+
| bird.fast 官网 | 原文写着 "release: private GitHub repo steipete/bird" / "Private release" |
|
|
15
|
+
| 新版分发形态 | macOS universal **二进制 tarball** —— 不是 Node 库 |
|
|
16
|
+
|
|
17
|
+
所以作者还在做 bird,只是**我们拿不到新版**;而且就算拿到,发的是二进制,也塞不进
|
|
18
|
+
我们的 sidecar(那里需要 `import { TwitterClient }`)。
|
|
19
|
+
|
|
20
|
+
### 源码其实拿得到 —— 一开始的判断是错的
|
|
21
|
+
|
|
22
|
+
第一版这份文档写的是"源码没了,只能维护编译产物"。**那句话是错的**,纠正如下,
|
|
23
|
+
免得后面的人重复这个弯路:
|
|
24
|
+
|
|
25
|
+
原仓库 `steipete/bird` 被删/转私有之后,GitHub 把 fork 网络里的一个 fork 提升成了
|
|
26
|
+
新的根节点(这是标准行为),于是 `jawond/bird` 看上去像"原始仓库"——它其实是个
|
|
27
|
+
批量镜像号(560 个仓库、4 个关注者、清一色 fork),停在 **v0.1.0 / 2025-12-05**,
|
|
28
|
+
只有 5 个 lib 文件,**没有 queryId 自愈机制**(那时候还是一张静态的 `query-ids.json`)。
|
|
29
|
+
|
|
30
|
+
真正有用的在 fork 网络更深处。按最后提交时间翻一遍 219 个 fork,找到:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
clifton/bird pushed 2026-02-06 version 0.8.0 src/lib 33 个 .ts
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**33 个 `.ts` 跟我们 `dist/lib` 的 33 个 `.js` 文件名一一对应** —— 这就是我们正在跑的
|
|
37
|
+
那个版本的完整 TypeScript 源码,已存进 `upstream-src/`。
|
|
38
|
+
|
|
39
|
+
教训:判断一个包"源码没了",光探 `api.github.com/repos/<猜的路径>` 不够;
|
|
40
|
+
fork 网络往往留着完整快照,而且**按 pushed_at 排序**才能找到版本最新的那个
|
|
41
|
+
(默认排序会把一堆 v0.1.0 的镜像排在前面)。
|
|
42
|
+
|
|
43
|
+
两个后果决定了必须内置:
|
|
44
|
+
|
|
45
|
+
1. **没有升级路径。** 这个库打的是 X 的私有 GraphQL 端点,bird 自己的官网都写着
|
|
46
|
+
"X can change things anytime"。X 一改,不会有人来修 —— 只能我们自己修,那就必须
|
|
47
|
+
能改源码。
|
|
48
|
+
2. **npm 上是 deprecated 状态,作者随时可以 unpublish。** 那天到来时,我们连
|
|
49
|
+
`npm install` 都跑不过去,整个 worker 构建挂掉 —— 而这跟 Bird 功能本身没关系,
|
|
50
|
+
会连带把发帖、任务这些正事一起拖停。
|
|
51
|
+
|
|
52
|
+
许可证是 MIT(见 LICENSE),明确允许。
|
|
53
|
+
|
|
54
|
+
## 里面是什么
|
|
55
|
+
|
|
56
|
+
| 路径 | 来源 | 用途 | 会不会发到 worker |
|
|
57
|
+
|---|---|---|---|
|
|
58
|
+
| `dist/` | npm tarball `@steipete/bird@0.8.0` | **运行时真正加载的** | 会 |
|
|
59
|
+
| `upstream-src/` | `clifton/bird` @ 0.8.0 | **维护参考** —— 带类型和注释的 TS 源码 | 不会 |
|
|
60
|
+
| `upstream-tsconfig.json` / `upstream-package.json` | 同上 | 出处存档 + 真要重建时的编译配置 | 不会 |
|
|
61
|
+
| `LICENSE` | 上游 | MIT | 会 |
|
|
62
|
+
|
|
63
|
+
`dist/` 是 npm 的官方构建产物,所以它是权威的运行时形态 —— 不自己从源码重编,
|
|
64
|
+
避免引入"我们编的跟上游编的不一样"这类没必要的差异。`upstream-src/` 不参与构建,
|
|
65
|
+
它的作用是让**改**这件事可行:改一个用类型和注释写的 TS 文件,比改一坨编译产物
|
|
66
|
+
可靠得多。改完照着 `upstream-tsconfig.json` 编出来替换 `dist/` 对应文件即可。
|
|
67
|
+
|
|
68
|
+
`package.json` 的 `files` 只列 `vendor/bird/dist`、`LICENSE`、`README.md` ——
|
|
69
|
+
480K 的源码是给我们看的,没必要跟着装到每台 worker 上。
|
|
70
|
+
|
|
71
|
+
`dist/` 里的 `.map` 删掉了:sourcemap 没带 `sourcesContent`,留着只会指向不存在的
|
|
72
|
+
`../../src/*.ts`;现在真源码就在隔壁 `upstream-src/`,更没必要留。
|
|
73
|
+
|
|
74
|
+
## 我们实际用到的
|
|
75
|
+
|
|
76
|
+
只用**只读**部分。写操作(`createTweet` / `postStatusUpdate`)在这份副本里仍然存在,
|
|
77
|
+
但 `dp-worker/src/bird/ops.ts` 的 op 白名单永远不会调用它们 —— 见 dp-shared 里
|
|
78
|
+
`BIRD_OPS` 上关于 I1 的那段说明。
|
|
79
|
+
|
|
80
|
+
真正承重的是三块:
|
|
81
|
+
|
|
82
|
+
| 文件 | 作用 | 为什么关键 |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| `lib/runtime-query-ids.js` | 从 X 的网页 bundle 里刮 queryId 并缓存 | X 每隔几周轮换一次 queryId。**这是这个库能活到今天的唯一原因** |
|
|
85
|
+
| `lib/twitter-client-features.js` | 每个端点要带的 feature flag | 少一个 flag X 就回 400 |
|
|
86
|
+
| `lib/twitter-client-utils.js` | 响应解析 | 我们**已经基本不依赖它** —— `ops.ts` 自己从 `_raw` 挖字段,因为它没声明浏览量/粉丝数/转发这些我们要的东西 |
|
|
87
|
+
|
|
88
|
+
也就是说,真出问题时要改的大概率是 queryId 和 feature flag 那两处,解析层我们早就自己
|
|
89
|
+
接管了。这是我们暴露面比看上去小的原因。
|
|
90
|
+
|
|
91
|
+
## 升级/替换
|
|
92
|
+
|
|
93
|
+
**没有版本升级可拿** —— 上游新版是私有仓库里的 macOS 二进制。所以路只有两条:
|
|
94
|
+
|
|
95
|
+
1. **自己改。** 现在有 `upstream-src/` 的 TS 源码,这条路是通的。X 改版时大概率
|
|
96
|
+
要动的就是上面那张表里的 `runtime-query-ids` 和 `twitter-client-features`。
|
|
97
|
+
2. **换实现。** 重写 `dp-worker/src/bird/ops.ts` 里的 `BirdClientLike` 适配层
|
|
98
|
+
(约 200 行,刻意定义成结构化接口、不依赖 bird 的类型),上面所有业务代码 ——
|
|
99
|
+
作业系统、sink、分析引擎、竞品拆解、互关目标池、全部 UI —— 一行不动。
|
|
100
|
+
真要换的话候选是 `twscrape`(Python,活跃维护)。
|
|
101
|
+
|
|
102
|
+
什么时候知道该动手:center 的健康探针每 2 小时打一次 `whoami`,连续失败会推
|
|
103
|
+
Telegram 并在概览页顶部挂横幅,错误码 `api_shape_changed` 就是"X 改版了,该改这里"。
|
|
104
|
+
见 `dp-center-worker/src/lib/bird/health.ts`。
|
|
105
|
+
|
|
106
|
+
## 一条不该被优化掉的裁剪
|
|
107
|
+
|
|
108
|
+
`dist/lib/cookies.js` **不是上游原版**,是我们换掉的桩。上游那版会通过
|
|
109
|
+
`@steipete/sweet-cookie` 去读**本机浏览器**(Safari/Chrome/Firefox)里的 x.com cookie。
|
|
110
|
+
|
|
111
|
+
砍掉它的主要理由不是"用不上"(虽然确实用不上 —— 凭据只来自 center 同步的 session
|
|
112
|
+
文件),而是**一个跑在生产机上的进程不该具备"翻这台机器上任意浏览器登录态"这种
|
|
113
|
+
本事**。哪怕现在没人调用,它也是一条随时可能被误用的路径。
|
|
114
|
+
|
|
115
|
+
如果将来有人从 `upstream-src/` 重新编译整个 `dist/`,记得把这个裁剪重新打上,
|
|
116
|
+
否则这条路会悄悄回来。
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type PaginationCmdOpts = {
|
|
2
|
+
all?: boolean;
|
|
3
|
+
maxPages?: string;
|
|
4
|
+
cursor?: string;
|
|
5
|
+
delay?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function parsePositiveIntFlag(raw: string | undefined, flagName: string): {
|
|
8
|
+
ok: true;
|
|
9
|
+
value: number | undefined;
|
|
10
|
+
} | {
|
|
11
|
+
ok: false;
|
|
12
|
+
error: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function parseNonNegativeIntFlag(raw: string | undefined, flagName: string, defaultValue: number): {
|
|
15
|
+
ok: true;
|
|
16
|
+
value: number;
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function parsePaginationFlags(cmdOpts: PaginationCmdOpts, opts?: {
|
|
22
|
+
maxPagesImpliesPagination?: boolean;
|
|
23
|
+
defaultDelayMs?: number;
|
|
24
|
+
includeDelay?: boolean;
|
|
25
|
+
}): {
|
|
26
|
+
ok: true;
|
|
27
|
+
usePagination: boolean;
|
|
28
|
+
maxPages?: number;
|
|
29
|
+
cursor?: string;
|
|
30
|
+
pageDelayMs?: number;
|
|
31
|
+
} | {
|
|
32
|
+
ok: false;
|
|
33
|
+
error: string;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function parsePositiveIntFlag(raw, flagName) {
|
|
2
|
+
if (raw === undefined) {
|
|
3
|
+
return { ok: true, value: undefined };
|
|
4
|
+
}
|
|
5
|
+
const value = Number.parseInt(raw, 10);
|
|
6
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
7
|
+
return { ok: false, error: `Invalid ${flagName}. Expected a positive integer.` };
|
|
8
|
+
}
|
|
9
|
+
return { ok: true, value };
|
|
10
|
+
}
|
|
11
|
+
export function parseNonNegativeIntFlag(raw, flagName, defaultValue) {
|
|
12
|
+
const value = Number.parseInt(raw ?? String(defaultValue), 10);
|
|
13
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
14
|
+
return { ok: false, error: `Invalid ${flagName}. Expected a non-negative integer.` };
|
|
15
|
+
}
|
|
16
|
+
return { ok: true, value };
|
|
17
|
+
}
|
|
18
|
+
export function parsePaginationFlags(cmdOpts, opts) {
|
|
19
|
+
const maxPagesImpliesPagination = opts?.maxPagesImpliesPagination ?? false;
|
|
20
|
+
const includeDelay = opts?.includeDelay ?? false;
|
|
21
|
+
const defaultDelayMs = opts?.defaultDelayMs ?? 1000;
|
|
22
|
+
const maxPages = parsePositiveIntFlag(cmdOpts.maxPages, '--max-pages');
|
|
23
|
+
if (!maxPages.ok) {
|
|
24
|
+
return maxPages;
|
|
25
|
+
}
|
|
26
|
+
const usePagination = Boolean(cmdOpts.all || cmdOpts.cursor || (maxPagesImpliesPagination && maxPages.value !== undefined));
|
|
27
|
+
let pageDelayMs;
|
|
28
|
+
if (includeDelay) {
|
|
29
|
+
const delay = parseNonNegativeIntFlag(cmdOpts.delay, '--delay', defaultDelayMs);
|
|
30
|
+
if (!delay.ok) {
|
|
31
|
+
return delay;
|
|
32
|
+
}
|
|
33
|
+
pageDelayMs = delay.value;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
ok: true,
|
|
37
|
+
usePagination,
|
|
38
|
+
maxPages: maxPages.value,
|
|
39
|
+
cursor: cmdOpts.cursor,
|
|
40
|
+
pageDelayMs,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=pagination.js.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { registerBookmarksCommand } from '../commands/bookmarks.js';
|
|
3
|
+
import { registerCheckCommand } from '../commands/check.js';
|
|
4
|
+
import { registerFollowCommands } from '../commands/follow.js';
|
|
5
|
+
import { registerHelpCommand } from '../commands/help.js';
|
|
6
|
+
import { registerHomeCommand } from '../commands/home.js';
|
|
7
|
+
import { registerListsCommand } from '../commands/lists.js';
|
|
8
|
+
import { registerNewsCommand } from '../commands/news.js';
|
|
9
|
+
import { registerPostCommands } from '../commands/post.js';
|
|
10
|
+
import { registerQueryIdsCommand } from '../commands/query-ids.js';
|
|
11
|
+
import { registerReadCommands } from '../commands/read.js';
|
|
12
|
+
import { registerSearchCommands } from '../commands/search.js';
|
|
13
|
+
import { registerUnbookmarkCommand } from '../commands/unbookmark.js';
|
|
14
|
+
import { registerUserTweetsCommand } from '../commands/user-tweets.js';
|
|
15
|
+
import { registerUserCommands } from '../commands/users.js';
|
|
16
|
+
import { getCliVersion } from '../lib/version.js';
|
|
17
|
+
import { collectCookieSource } from './shared.js';
|
|
18
|
+
export const KNOWN_COMMANDS = new Set([
|
|
19
|
+
'tweet',
|
|
20
|
+
'reply',
|
|
21
|
+
'query-ids',
|
|
22
|
+
'read',
|
|
23
|
+
'replies',
|
|
24
|
+
'thread',
|
|
25
|
+
'search',
|
|
26
|
+
'mentions',
|
|
27
|
+
'bookmarks',
|
|
28
|
+
'unbookmark',
|
|
29
|
+
'follow',
|
|
30
|
+
'unfollow',
|
|
31
|
+
'following',
|
|
32
|
+
'followers',
|
|
33
|
+
'likes',
|
|
34
|
+
'lists',
|
|
35
|
+
'list-timeline',
|
|
36
|
+
'home',
|
|
37
|
+
'user-tweets',
|
|
38
|
+
'news',
|
|
39
|
+
'trending',
|
|
40
|
+
'help',
|
|
41
|
+
'whoami',
|
|
42
|
+
'check',
|
|
43
|
+
]);
|
|
44
|
+
export function createProgram(ctx) {
|
|
45
|
+
const program = new Command();
|
|
46
|
+
program.configureHelp({
|
|
47
|
+
showGlobalOptions: true,
|
|
48
|
+
styleTitle: (t) => ctx.colors.section(t),
|
|
49
|
+
styleUsage: (t) => ctx.colors.description(t),
|
|
50
|
+
styleCommandText: (t) => ctx.colors.command(t),
|
|
51
|
+
styleCommandDescription: (t) => ctx.colors.muted(t),
|
|
52
|
+
styleOptionTerm: (t) => ctx.colors.option(t),
|
|
53
|
+
styleOptionText: (t) => ctx.colors.option(t),
|
|
54
|
+
styleOptionDescription: (t) => ctx.colors.muted(t),
|
|
55
|
+
styleArgumentTerm: (t) => ctx.colors.argument(t),
|
|
56
|
+
styleArgumentText: (t) => ctx.colors.argument(t),
|
|
57
|
+
styleArgumentDescription: (t) => ctx.colors.muted(t),
|
|
58
|
+
styleSubcommandTerm: (t) => ctx.colors.command(t),
|
|
59
|
+
styleSubcommandText: (t) => ctx.colors.command(t),
|
|
60
|
+
styleSubcommandDescription: (t) => ctx.colors.muted(t),
|
|
61
|
+
styleDescriptionText: (t) => ctx.colors.muted(t),
|
|
62
|
+
});
|
|
63
|
+
const collect = (value, previous = []) => {
|
|
64
|
+
previous.push(value);
|
|
65
|
+
return previous;
|
|
66
|
+
};
|
|
67
|
+
program.addHelpText('beforeAll', () => `${ctx.colors.banner('bird')} ${ctx.colors.muted(getCliVersion())} ${ctx.colors.subtitle('— fast X CLI for tweeting, replying, and reading')}`);
|
|
68
|
+
program.name('bird').description('Post tweets and replies via Twitter/X GraphQL API').version(getCliVersion());
|
|
69
|
+
const formatExample = (command, description) => `${ctx.colors.command(` ${command}`)}\n${ctx.colors.muted(` ${description}`)}`;
|
|
70
|
+
program.addHelpText('afterAll', () => `\n${ctx.colors.section('Examples')}\n${[
|
|
71
|
+
formatExample('bird whoami', 'Show the logged-in account via GraphQL cookies'),
|
|
72
|
+
formatExample('bird --firefox-profile default-release whoami', 'Use Firefox profile cookies'),
|
|
73
|
+
formatExample('bird tweet "hello from bird"', 'Send a tweet'),
|
|
74
|
+
formatExample('bird 1234567890123456789 --json', 'Read a tweet (ID or URL shorthand for `read`) and print JSON'),
|
|
75
|
+
].join('\n\n')}\n\n${ctx.colors.section('Shortcuts')}\n${[
|
|
76
|
+
formatExample('bird <tweet-id-or-url> [--json]', 'Shorthand for `bird read <tweet-id-or-url>`'),
|
|
77
|
+
].join('\n\n')}\n\n${ctx.colors.section('JSON Output')}\n${ctx.colors.muted(` Add ${ctx.colors.option('--json')} to: read, replies, thread, search, mentions, bookmarks, likes, following, followers, about, lists, list-timeline, user-tweets, query-ids`)}\n${ctx.colors.muted(` Add ${ctx.colors.option('--json-full')} to include raw API response in ${ctx.colors.argument('_raw')} field (tweet commands only)`)}\n${ctx.colors.muted(` (Run ${ctx.colors.command('bird <command> --help')} to see per-command flags.)`)}`);
|
|
78
|
+
program.addHelpText('afterAll', () => `\n\n${ctx.colors.section('Config')}\n${ctx.colors.muted(` Reads ${ctx.colors.argument('~/.config/bird/config.json5')} and ${ctx.colors.argument('./.birdrc.json5')} (JSON5)`)}\n${ctx.colors.muted(` Supports: chromeProfile, chromeProfileDir, firefoxProfile, cookieSource, cookieTimeoutMs, timeoutMs, quoteDepth`)}\n\n${ctx.colors.section('Env')}\n${ctx.colors.muted(` ${ctx.colors.option('NO_COLOR')}, ${ctx.colors.option('BIRD_TIMEOUT_MS')}, ${ctx.colors.option('BIRD_COOKIE_TIMEOUT_MS')}, ${ctx.colors.option('BIRD_QUOTE_DEPTH')}`)}`);
|
|
79
|
+
program
|
|
80
|
+
.option('--auth-token <token>', 'Twitter auth_token cookie')
|
|
81
|
+
.option('--ct0 <token>', 'Twitter ct0 cookie')
|
|
82
|
+
.option('--chrome-profile <name>', 'Chrome profile name for cookie extraction', ctx.config.chromeProfile)
|
|
83
|
+
.option('--chrome-profile-dir <path>', 'Chrome/Chromium profile directory or cookie DB path for cookie extraction', ctx.config.chromeProfileDir)
|
|
84
|
+
.option('--firefox-profile <name>', 'Firefox profile name for cookie extraction', ctx.config.firefoxProfile)
|
|
85
|
+
.option('--cookie-timeout <ms>', 'Cookie extraction timeout in milliseconds (keychain/OS helpers)')
|
|
86
|
+
.option('--cookie-source <source>', 'Cookie source for browser cookie extraction (repeatable)', collectCookieSource)
|
|
87
|
+
.option('--media <path>', 'Attach media file (repeatable, up to 4 images or 1 video)', collect)
|
|
88
|
+
.option('--alt <text>', 'Alt text for the corresponding --media (repeatable)', collect)
|
|
89
|
+
.option('--timeout <ms>', 'Request timeout in milliseconds')
|
|
90
|
+
.option('--quote-depth <depth>', 'Max quoted tweet depth (default: 1; 0 disables)')
|
|
91
|
+
.option('--plain', 'Plain output (stable, no emoji, no color)')
|
|
92
|
+
.option('--no-emoji', 'Disable emoji output')
|
|
93
|
+
.option('--no-color', 'Disable ANSI colors (or set NO_COLOR)');
|
|
94
|
+
program.hook('preAction', (_thisCommand, actionCommand) => {
|
|
95
|
+
ctx.applyOutputFromCommand(actionCommand);
|
|
96
|
+
});
|
|
97
|
+
registerHelpCommand(program, ctx);
|
|
98
|
+
registerQueryIdsCommand(program, ctx);
|
|
99
|
+
registerPostCommands(program, ctx);
|
|
100
|
+
registerReadCommands(program, ctx);
|
|
101
|
+
registerSearchCommands(program, ctx);
|
|
102
|
+
registerBookmarksCommand(program, ctx);
|
|
103
|
+
registerUnbookmarkCommand(program, ctx);
|
|
104
|
+
registerFollowCommands(program, ctx);
|
|
105
|
+
registerListsCommand(program, ctx);
|
|
106
|
+
registerHomeCommand(program, ctx);
|
|
107
|
+
registerUserCommands(program, ctx);
|
|
108
|
+
registerUserTweetsCommand(program, ctx);
|
|
109
|
+
registerNewsCommand(program, ctx);
|
|
110
|
+
registerCheckCommand(program, ctx);
|
|
111
|
+
return program;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=program.js.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import { type CookieSource, resolveCredentials } from '../lib/cookies.js';
|
|
3
|
+
import { labelPrefix, type OutputConfig, statusPrefix } from '../lib/output.js';
|
|
4
|
+
import type { TweetData } from '../lib/twitter-client.js';
|
|
5
|
+
export type BirdConfig = {
|
|
6
|
+
chromeProfile?: string;
|
|
7
|
+
chromeProfileDir?: string;
|
|
8
|
+
firefoxProfile?: string;
|
|
9
|
+
cookieSource?: CookieSource | CookieSource[];
|
|
10
|
+
cookieTimeoutMs?: number;
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
quoteDepth?: number;
|
|
13
|
+
};
|
|
14
|
+
export type MediaSpec = {
|
|
15
|
+
path: string;
|
|
16
|
+
alt?: string;
|
|
17
|
+
mime: string;
|
|
18
|
+
buffer: Buffer;
|
|
19
|
+
};
|
|
20
|
+
export type CliContext = {
|
|
21
|
+
isTty: boolean;
|
|
22
|
+
getOutput: () => OutputConfig;
|
|
23
|
+
colors: {
|
|
24
|
+
banner: (t: string) => string;
|
|
25
|
+
subtitle: (t: string) => string;
|
|
26
|
+
section: (t: string) => string;
|
|
27
|
+
bullet: (t: string) => string;
|
|
28
|
+
command: (t: string) => string;
|
|
29
|
+
option: (t: string) => string;
|
|
30
|
+
argument: (t: string) => string;
|
|
31
|
+
description: (t: string) => string;
|
|
32
|
+
muted: (t: string) => string;
|
|
33
|
+
accent: (t: string) => string;
|
|
34
|
+
};
|
|
35
|
+
p: (kind: Parameters<typeof statusPrefix>[0]) => string;
|
|
36
|
+
l: (kind: Parameters<typeof labelPrefix>[0]) => string;
|
|
37
|
+
config: BirdConfig;
|
|
38
|
+
applyOutputFromCommand: (command: Command) => void;
|
|
39
|
+
resolveTimeoutFromOptions: (options: {
|
|
40
|
+
timeout?: string | number;
|
|
41
|
+
}) => number | undefined;
|
|
42
|
+
resolveQuoteDepthFromOptions: (options: {
|
|
43
|
+
quoteDepth?: string | number;
|
|
44
|
+
}) => number | undefined;
|
|
45
|
+
resolveCredentialsFromOptions: (opts: CredentialsOptions) => ReturnType<typeof resolveCredentials>;
|
|
46
|
+
loadMedia: (opts: {
|
|
47
|
+
media: string[];
|
|
48
|
+
alts: string[];
|
|
49
|
+
}) => MediaSpec[];
|
|
50
|
+
printTweets: (tweets: TweetData[], opts?: {
|
|
51
|
+
json?: boolean;
|
|
52
|
+
emptyMessage?: string;
|
|
53
|
+
showSeparator?: boolean;
|
|
54
|
+
}) => void;
|
|
55
|
+
printTweetsResult: (result: {
|
|
56
|
+
tweets?: TweetData[];
|
|
57
|
+
nextCursor?: string;
|
|
58
|
+
}, opts: {
|
|
59
|
+
json: boolean;
|
|
60
|
+
usePagination: boolean;
|
|
61
|
+
emptyMessage: string;
|
|
62
|
+
}) => void;
|
|
63
|
+
extractTweetId: (tweetIdOrUrl: string) => string;
|
|
64
|
+
};
|
|
65
|
+
export declare const collectCookieSource: (value: string, previous?: CookieSource[]) => CookieSource[];
|
|
66
|
+
type CredentialsOptions = {
|
|
67
|
+
authToken?: string;
|
|
68
|
+
ct0?: string;
|
|
69
|
+
chromeProfile?: string;
|
|
70
|
+
chromeProfileDir?: string;
|
|
71
|
+
firefoxProfile?: string;
|
|
72
|
+
cookieSource?: CookieSource[];
|
|
73
|
+
cookieTimeout?: string | number;
|
|
74
|
+
};
|
|
75
|
+
export declare function createCliContext(normalizedArgs: string[], env?: NodeJS.ProcessEnv): CliContext;
|
|
76
|
+
export {};
|
|
77
|
+
//# sourceMappingURL=shared.d.ts.map
|