leaflink 0.1.0__tar.gz

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 (50) hide show
  1. leaflink-0.1.0/LICENSE.txt +201 -0
  2. leaflink-0.1.0/MANIFEST.in +15 -0
  3. leaflink-0.1.0/PKG-INFO +440 -0
  4. leaflink-0.1.0/README.en.md +397 -0
  5. leaflink-0.1.0/README.md +392 -0
  6. leaflink-0.1.0/examples/leafignore.example +13 -0
  7. leaflink-0.1.0/pyproject.toml +66 -0
  8. leaflink-0.1.0/resource/leaflink.png +0 -0
  9. leaflink-0.1.0/setup.cfg +4 -0
  10. leaflink-0.1.0/src/leaflink/__init__.py +5 -0
  11. leaflink-0.1.0/src/leaflink/__main__.py +3 -0
  12. leaflink-0.1.0/src/leaflink/auth/__init__.py +1 -0
  13. leaflink-0.1.0/src/leaflink/auth/browser_login.py +165 -0
  14. leaflink-0.1.0/src/leaflink/auth/cookie_import.py +26 -0
  15. leaflink-0.1.0/src/leaflink/auth/manager.py +100 -0
  16. leaflink-0.1.0/src/leaflink/cli.py +513 -0
  17. leaflink-0.1.0/src/leaflink/client/__init__.py +1 -0
  18. leaflink-0.1.0/src/leaflink/client/models.py +97 -0
  19. leaflink-0.1.0/src/leaflink/client/overleaf_client.py +642 -0
  20. leaflink-0.1.0/src/leaflink/client/playwright_bridge.py +261 -0
  21. leaflink-0.1.0/src/leaflink/config.py +62 -0
  22. leaflink-0.1.0/src/leaflink/exceptions.py +42 -0
  23. leaflink-0.1.0/src/leaflink/project/__init__.py +1 -0
  24. leaflink-0.1.0/src/leaflink/project/metadata.py +55 -0
  25. leaflink-0.1.0/src/leaflink/sync/__init__.py +1 -0
  26. leaflink-0.1.0/src/leaflink/sync/conflict.py +172 -0
  27. leaflink-0.1.0/src/leaflink/sync/diff.py +62 -0
  28. leaflink-0.1.0/src/leaflink/sync/engine.py +534 -0
  29. leaflink-0.1.0/src/leaflink/sync/ignore.py +61 -0
  30. leaflink-0.1.0/src/leaflink/sync/state.py +116 -0
  31. leaflink-0.1.0/src/leaflink/sync/watcher.py +91 -0
  32. leaflink-0.1.0/src/leaflink/utils/__init__.py +1 -0
  33. leaflink-0.1.0/src/leaflink/utils/console.py +59 -0
  34. leaflink-0.1.0/src/leaflink/utils/hashing.py +23 -0
  35. leaflink-0.1.0/src/leaflink/utils/locks.py +57 -0
  36. leaflink-0.1.0/src/leaflink/utils/logging.py +10 -0
  37. leaflink-0.1.0/src/leaflink/utils/paths.py +31 -0
  38. leaflink-0.1.0/src/leaflink/utils/time.py +25 -0
  39. leaflink-0.1.0/src/leaflink.egg-info/SOURCES.txt +47 -0
  40. leaflink-0.1.0/tests/bootstrap.py +10 -0
  41. leaflink-0.1.0/tests/test_browser_login.py +64 -0
  42. leaflink-0.1.0/tests/test_cli_smoke.py +157 -0
  43. leaflink-0.1.0/tests/test_conflict.py +36 -0
  44. leaflink-0.1.0/tests/test_diff.py +49 -0
  45. leaflink-0.1.0/tests/test_hashing.py +20 -0
  46. leaflink-0.1.0/tests/test_ignore.py +21 -0
  47. leaflink-0.1.0/tests/test_overleaf_client.py +149 -0
  48. leaflink-0.1.0/tests/test_playwright_bridge.py +160 -0
  49. leaflink-0.1.0/tests/test_state.py +31 -0
  50. leaflink-0.1.0/tests/test_sync_engine.py +137 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2026] [skyxz]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,15 @@
1
+ include README.md
2
+ include README.en.md
3
+ include LICENSE.txt
4
+ include pyproject.toml
5
+ recursive-include src/leaflink *.py
6
+ recursive-include resource *.png
7
+ recursive-include examples *.example
8
+ recursive-include tests *.py
9
+ prune build
10
+ prune dist
11
+ prune src/leafsync.egg-info
12
+ prune src/leaflink.egg-info
13
+ global-exclude __pycache__
14
+ global-exclude *.py[cod]
15
+ global-exclude .DS_Store
@@ -0,0 +1,440 @@
1
+ Metadata-Version: 2.4
2
+ Name: leaflink
3
+ Version: 0.1.0
4
+ Summary: A modern CLI for syncing local directories with Overleaf projects.
5
+ Author: leaflink contributors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/xiongqi123123/LeafLink
8
+ Project-URL: Repository, https://github.com/xiongqi123123/LeafLink
9
+ Project-URL: Issues, https://github.com/xiongqi123123/LeafLink/issues
10
+ Keywords: overleaf,latex,cli,sync
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Software Development :: Version Control
21
+ Classifier: Topic :: Text Processing :: Markup :: LaTeX
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE.txt
25
+ Requires-Dist: merge3>=0.0.16
26
+ Provides-Extra: browser
27
+ Requires-Dist: playwright>=1.42.0; extra == "browser"
28
+ Provides-Extra: watch
29
+ Requires-Dist: watchdog>=4.0.0; extra == "watch"
30
+ Provides-Extra: html
31
+ Requires-Dist: beautifulsoup4>=4.12.0; extra == "html"
32
+ Provides-Extra: http
33
+ Requires-Dist: httpx>=0.27.0; extra == "http"
34
+ Provides-Extra: dev
35
+ Requires-Dist: build>=1.2.2; extra == "dev"
36
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
37
+ Requires-Dist: twine>=5.1.1; extra == "dev"
38
+ Provides-Extra: all
39
+ Requires-Dist: merge3>=0.0.16; extra == "all"
40
+ Requires-Dist: playwright>=1.42.0; extra == "all"
41
+ Requires-Dist: watchdog>=4.0.0; extra == "all"
42
+ Requires-Dist: beautifulsoup4>=4.12.0; extra == "all"
43
+ Requires-Dist: httpx>=0.27.0; extra == "all"
44
+ Requires-Dist: build>=1.2.2; extra == "all"
45
+ Requires-Dist: pytest>=8.0.0; extra == "all"
46
+ Requires-Dist: twine>=5.1.1; extra == "all"
47
+ Dynamic: license-file
48
+
49
+ <p align="center">
50
+ <img src="https://raw.githubusercontent.com/xiongqi123123/LeafLink/main/resource/leaflink.png" alt="LeafLink Logo" width="220" />
51
+ </p>
52
+
53
+ <h1 align="center">LeafLink</h1>
54
+
55
+ <p align="center">本地目录与 Overleaf / cn.overleaf 项目同步 CLI</p>
56
+
57
+ <p align="center">
58
+ <a href="https://pypi.org/project/leaflink/"><img src="https://img.shields.io/pypi/v/leaflink?label=PyPI" alt="PyPI" /></a>
59
+ <a href="https://pypi.org/project/leaflink/"><img src="https://img.shields.io/pypi/pyversions/leaflink" alt="Python" /></a>
60
+ <a href="https://github.com/xiongqi123123/LeafLink/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/xiongqi123123/LeafLink/ci.yml?branch=main&label=CI" alt="CI" /></a>
61
+ <a href="https://github.com/xiongqi123123/LeafLink"><img src="https://img.shields.io/github/stars/xiongqi123123/LeafLink?style=flat" alt="GitHub stars" /></a>
62
+ <a href="https://github.com/xiongqi123123/LeafLink/blob/main/LICENSE.txt"><img src="https://img.shields.io/github/license/xiongqi123123/LeafLink" alt="License" /></a>
63
+ </p>
64
+
65
+ <p align="center">
66
+ <a href="./README.en.md">English</a> |
67
+ <a href="https://github.com/xiongqi123123/LeafLink">GitHub</a> |
68
+ <a href="https://pypi.org/project/leaflink/">PyPI</a>
69
+ </p>
70
+
71
+ <p align="center"><strong>浏览器登录、本地拉取、远端推送、PDF 下载、伪实时协作同步,一套命令完成。</strong></p>
72
+
73
+ ## 项目简介
74
+
75
+ LeafLink 是一个开源命令行工具,用于在本地目录和 Overleaf 项目之间同步文件,不依赖 Overleaf 的付费 Git 集成。
76
+
77
+ 它参考了 `overleaf-sync` 的产品形态与命令体验,但不是 fork,而是从零重写的现代化实现,目标是:
78
+
79
+ - 更清晰的工程分层
80
+ - 更稳定的浏览器登录与会话持久化
81
+ - 更可靠的本地/远端状态追踪
82
+ - 更适合扩展的同步引擎与测试结构
83
+
84
+ ## 为什么重写,而不是 fork
85
+
86
+ - 希望从一开始就把认证、远端 client、同步引擎、CLI 解耦
87
+ - 需要优先支持 `overleaf.com` 和 `cn.overleaf.com`
88
+ - 需要新增 `sync` 命令来做“本地 watch + 远端轮询”的伪实时协作
89
+ - 需要更容易发布到 PyPI、接入 CI、编写单元测试和长期维护
90
+
91
+ ## 功能概览
92
+
93
+ - 浏览器登录并持久化会话 Cookie
94
+ - 手动导入 Cookie 作为后备认证方案
95
+ - 列出账号下项目
96
+ - 通过项目 URL / 项目 ID / 项目名克隆项目
97
+ - 拉取远端变更到本地
98
+ - 推送本地变更到远端
99
+ - 下载最新编译 PDF
100
+ - 查看本地与远端差异
101
+ - `sync` 伪实时同步:本地监听 + 远端轮询 + 冲突处理
102
+ - 文本冲突使用 `merge3` 三方合并
103
+ - 二进制文件安全同步,不假设所有文件都是文本
104
+
105
+ ## 支持的网址
106
+
107
+ - `https://www.overleaf.com/project/...`
108
+ - `https://cn.overleaf.com/project/...`
109
+
110
+ ## 安装方式
111
+
112
+ ### 通过 PyPI 安装
113
+
114
+ ```bash
115
+ pip install leaflink
116
+ ```
117
+
118
+ 安装后可直接使用:
119
+
120
+ ```bash
121
+ leaflink --help
122
+ ```
123
+
124
+ ### 安装可选依赖
125
+
126
+ ```bash
127
+ pip install "leaflink[browser,watch]"
128
+ ```
129
+
130
+ - `browser`:安装 Playwright,用于浏览器登录和部分远端发现能力
131
+ - `watch`:安装 `watchdog`,用于 `leaflink sync`
132
+
133
+ ### 从源码安装
134
+
135
+ ```bash
136
+ git clone https://github.com/xiongqi123123/LeafLink.git
137
+ cd LeafLink
138
+ pip install .
139
+ ```
140
+
141
+ ### 首次使用 Playwright
142
+
143
+ ```bash
144
+ playwright install chromium
145
+ ```
146
+
147
+ ## 认证方式
148
+
149
+ LeafLink 不保存用户名或密码明文,只保存必要的会话信息。
150
+
151
+ 默认配置目录:
152
+
153
+ - `~/.config/leaflink/auth.json`
154
+ - `~/.config/leaflink/config.toml`
155
+
156
+ ### 浏览器登录
157
+
158
+ ```bash
159
+ leaflink login
160
+ leaflink login --base-url https://cn.overleaf.com
161
+ ```
162
+
163
+ 示意输出:
164
+
165
+ ```text
166
+ [auth] Complete login in the browser window. leaflink will detect the session automatically and close the browser.
167
+ [ok] Saved session for https://cn.overleaf.com
168
+ ```
169
+
170
+ ### 手动导入 Cookie
171
+
172
+ ```bash
173
+ leaflink auth import --base-url https://www.overleaf.com --cookie-file cookies.json
174
+ ```
175
+
176
+ 示意输出:
177
+
178
+ ```text
179
+ [ok] Imported cookies for https://www.overleaf.com
180
+ ```
181
+
182
+ ### 登出
183
+
184
+ ```bash
185
+ leaflink logout
186
+ ```
187
+
188
+ 示意输出:
189
+
190
+ ```text
191
+ [ok] Removed saved auth session.
192
+ ```
193
+
194
+ ## 快速开始
195
+
196
+ ```bash
197
+ leaflink login --base-url https://cn.overleaf.com
198
+ leaflink list
199
+ leaflink clone "Sample Paper Draft"
200
+ cd sample-paper-draft
201
+ leaflink status
202
+ leaflink pull
203
+ leaflink push
204
+ leaflink download --output build/output.pdf
205
+ leaflink sync
206
+ ```
207
+
208
+ ## 命令与示例输出
209
+
210
+ 以下所有项目名、项目 ID、路径和文件内容都只是演示示例。
211
+
212
+ ### `leaflink list`
213
+
214
+ 用于列出当前账号下可访问的 Overleaf 项目,适合在 clone 前先确认项目名称、项目 ID 和最近更新时间。
215
+
216
+ ```bash
217
+ leaflink list
218
+ ```
219
+
220
+ ```text
221
+ Name Project ID Updated
222
+ --------------------------- ------------------------ ------------------------
223
+ Sample Paper Draft a1b2c3d4e5f60718293a4b5c 2026-03-27T09:16:42.180Z
224
+ Research Notes b2c3d4e5f60718293a4b5c6d 2026-03-24T12:08:09.011Z
225
+ Resume Template CN c3d4e5f60718293a4b5c6d7e 2026-03-21T07:45:33.501Z
226
+ ```
227
+
228
+ ### `leaflink clone`
229
+
230
+ 用于将远端项目完整拉取到本地目录,同时初始化 `.leaflink/` 元数据,建立本地目录与远端项目的映射关系。
231
+
232
+ ```bash
233
+ leaflink clone a1b2c3d4e5f60718293a4b5c
234
+ leaflink clone "Sample Paper Draft"
235
+ leaflink clone https://www.overleaf.com/project/a1b2c3d4e5f60718293a4b5c ./paper-demo
236
+ ```
237
+
238
+ ```text
239
+ [ok] Cloned Sample Paper Draft into sample-paper-draft
240
+ ```
241
+
242
+ ### `leaflink status`
243
+
244
+ 用于只做分析,不执行同步。它会检查本地和远端的新增、修改、删除以及潜在冲突,适合在 pull 或 push 之前先预览差异。
245
+
246
+ ```bash
247
+ leaflink status
248
+ ```
249
+
250
+ ```text
251
+ [local] added: figures/overview.pdf
252
+ [local] modified: main.tex
253
+ [local] deleted: -
254
+ [remote] added: appendix.tex
255
+ [remote] modified: refs.bib
256
+ [remote] deleted: drafts/old-outline.tex
257
+ [conflicts] -
258
+ ```
259
+
260
+ ### `leaflink pull`
261
+
262
+ 用于把远端项目中的最新变更同步到本地目录。它会处理新增、修改、删除,并在检测到重叠文本编辑时进入冲突处理流程。
263
+
264
+ ```bash
265
+ leaflink pull
266
+ leaflink pull --conflict-strategy keep-remote
267
+ ```
268
+
269
+ ```text
270
+ [2026-03-27 14:06:11] [remote] changed: refs.bib (saved 2026-03-27 14:05:57, by collaborator)
271
+ [2026-03-27 14:06:11] [pull] updated: refs.bib (saved 2026-03-27 14:05:57, by collaborator)
272
+ [2026-03-27 14:06:11] [pull] added: appendix.tex
273
+ ```
274
+
275
+ 冲突示意:
276
+
277
+ ```text
278
+ [2026-03-27 14:06:11] [conflict] main.tex
279
+ Local and remote edits overlap in the same text region.
280
+ ...
281
+ <<<<<<< local/main.tex
282
+ \title{Sample Paper Draft v2}
283
+ ||||||| base/main.tex
284
+ \title{Sample Paper Draft}
285
+ =======
286
+ \title{Sample Paper Draft Revised}
287
+ >>>>>>> remote/main.tex
288
+ Choose a resolution:
289
+ 1. keep remote
290
+ 2. keep local
291
+ 3. duplicate both
292
+ ```
293
+
294
+ ### `leaflink push`
295
+
296
+ 用于把本地目录中的变更上传到远端项目。它会尽量只上传发生变化的文件,并兼容常见二进制资源文件。
297
+
298
+ ```bash
299
+ leaflink push
300
+ leaflink push --dry-run
301
+ ```
302
+
303
+ ```text
304
+ [2026-03-27 14:07:42] [push] uploaded: main.tex (saved 2026-03-27 14:07:38)
305
+ [2026-03-27 14:07:42] [push] uploaded: figures/overview.pdf (saved 2026-03-27 14:07:11)
306
+ ```
307
+
308
+ ### `leaflink download`
309
+
310
+ 用于下载远端项目最近一次成功编译生成的 PDF,适合在本地归档、投递或集成到其他构建流程中。
311
+
312
+ ```bash
313
+ leaflink download
314
+ leaflink download --output build/paper.pdf
315
+ ```
316
+
317
+ ```text
318
+ [ok] Downloaded PDF to /path/to/project/build/paper.pdf
319
+ ```
320
+
321
+ ### `leaflink sync`
322
+
323
+ 用于启动“伪实时同步”模式。它会监听本地文件变化并自动 push,同时按固定间隔轮询远端变化并自动 pull,在协作写作场景下尤其有用。
324
+
325
+ ```bash
326
+ leaflink sync
327
+ leaflink sync --interval 15 --debounce 2.0
328
+ leaflink sync --once
329
+ ```
330
+
331
+ ```text
332
+ [2026-03-27 13:21:23] [sync] Preparing sync service for Sample Paper Draft.
333
+ [2026-03-27 13:21:23] [sync] Project lock acquired for Sample Paper Draft.
334
+ [2026-03-27 13:21:23] [sync] Starting local watcher.
335
+ [2026-03-27 13:21:23] [sync] Sync service started. Watching /path/to/project (remote poll: 10.0s, debounce: 1.5s).
336
+ [2026-03-27 13:21:31] [local] modified: main.tex (saved 2026-03-27 13:21:30)
337
+ [2026-03-27 13:21:33] [push] uploaded: main.tex (saved 2026-03-27 13:21:30)
338
+ [2026-03-27 13:21:43] [sync] Checking remote changes.
339
+ [2026-03-27 13:21:44] [remote] changed: refs.bib (saved 2026-03-27 13:21:40, by collaborator)
340
+ [2026-03-27 13:21:44] [pull] updated: refs.bib (saved 2026-03-27 13:21:40, by collaborator)
341
+ ```
342
+
343
+ ## `.leafignore` 示例
344
+
345
+ ```gitignore
346
+ # LeafLink metadata
347
+ .leaflink/
348
+
349
+ # Git
350
+ .git/
351
+
352
+ # macOS
353
+ .DS_Store
354
+
355
+ # LaTeX temporary files
356
+ *.aux
357
+ *.log
358
+ *.out
359
+ *.fls
360
+ *.fdb_latexmk
361
+ *.synctex.gz
362
+ *.synctex(busy)
363
+
364
+ # Custom rules
365
+ build/
366
+ dist/
367
+ ```
368
+
369
+ 完整示例见 [examples/leafignore.example](examples/leafignore.example)。
370
+
371
+ ## 冲突处理说明
372
+
373
+ LeafLink 使用共同基线、本地版本、远端版本进行三方合并:
374
+
375
+ - 不同位置的文本修改会尽量自动合并
376
+ - 重叠修改会进入冲突流程
377
+ - 二进制文件不会尝试自动 merge
378
+
379
+ 冲突时可选择:
380
+
381
+ 1. `keep remote`:使用云端版本覆盖本地
382
+ 2. `keep local`:使用本地版本覆盖云端
383
+ 3. `duplicate both`:保留本地版本,并将远端版本写成冲突副本
384
+
385
+ ## `sync` 的原理与限制
386
+
387
+ `leaflink sync` 是“伪实时同步”,不是严格意义上的实时多人协同编辑。
388
+
389
+ 它的工作方式是:
390
+
391
+ - 使用 `watchdog` 监听本地目录变更
392
+ - 用 debounce 合并短时间内的多次本地写入
393
+ - 定期轮询远端项目变化
394
+ - 尽量自动 push / pull
395
+ - 遇到重叠编辑时进入冲突处理
396
+
397
+ 限制说明:
398
+
399
+ - 远端变化不是通过服务端推送,而是通过轮询获取
400
+ - 文本文件更适合自动合并,二进制文件冲突需要人工选择策略
401
+ - 如果远端私有接口变更,个别写入链路可能需要随 Overleaf 前端更新而调整
402
+
403
+ ## 本地元数据目录
404
+
405
+ 每个已 clone 的项目都会在根目录生成:
406
+
407
+ ```text
408
+ .leaflink/
409
+ project.json
410
+ state.json
411
+ lock
412
+ cache/
413
+ logs/
414
+ ```
415
+
416
+ LeafLink 的元数据不会散落在项目根目录其他位置。
417
+
418
+ ## 安全说明
419
+
420
+ - 不保存用户名密码明文
421
+ - 只保存必要的会话 Cookie / session
422
+ - 日志输出默认不会打印敏感认证信息
423
+ - 建议仅在个人可信设备上保存会话
424
+
425
+ ## Star 统计
426
+
427
+ [![Star History Chart](https://api.star-history.com/svg?repos=xiongqi123123/LeafLink&type=Date)](https://star-history.com/#xiongqi123123/LeafLink&Date)
428
+
429
+ ## 开发与发布
430
+
431
+ - 安装开发依赖:`pip install -e ".[dev,browser,watch]"`
432
+ - 运行测试:`python -m unittest discover -s tests -v`
433
+ - 本地打包:`python scripts/build_dist.py`
434
+ - GitHub Actions:
435
+ - CI: [`.github/workflows/ci.yml`](.github/workflows/ci.yml)
436
+ - 发布: [`.github/workflows/publish.yml`](.github/workflows/publish.yml)
437
+
438
+ ## 开源协议
439
+
440
+ 本项目采用 [Apache License 2.0](LICENSE.txt)。