Cang-yan/texleaf-sync
Über uns
Git-safe CLI for syncing Overleaf CE projects.
EntwicklerwerkzeugeGemessener Sternzuwachs
- in 24h
- 0
- in 7 days
- +1
- in 15 days
- 0
- in 1 month
- Verlauf wird gesammelt
Nettoänderungen in überlappenden Zeiträumen, keine Tagessummen. Fehlende Messwerte bleiben leer. Sterne zeigen Interesse, nicht Qualität.
README.md
Originaltexleaf-sync
中文文档: README.zh-CN.md
Quick Start
1. Install the CLI
Node.js 20 or newer is required.
Automatic Chrome profile discovery and cookie import are available only on
macOS. On Windows and Linux, enter cookies manually with texleaf auth login.
Install from a release URL:
npm install -g https://github.com/Cang-yan/texleaf-sync/releases/download/v0.1.5/texleaf-sync-0.1.5.tgz
texleaf --version
Or install a downloaded release tarball:
npm install -g ./texleaf-sync-0.1.5.tgz
texleaf --version
Build from source:
git clone https://github.com/Cang-yan/texleaf-sync.git
cd texleaf-sync
npm install
npm run build
npm link
texleaf --version
2. Log in once
Run interactive login and choose a target:
texleaf auth login
The prompt offers:
1forcstcloud, CAS Cloud Overleaf Community Edition athttps://latex.cstcloud.cn. The interactive login asks forlatex-sessionandoverleaf.sid.2foroverleaf,https://www.overleaf.com. The interactive login asks foroverleaf_session2.3fortexpage,https://www.texpage.com. Chrome import uses theSESSIONIDcookie.4for a custom Overleaf Community Edition host.5for From Chrome on macOS. This checkscstcloud,overleaf, andtexpageand saves each valid session automatically.
If Chrome has valid sessions for all supported platforms, login finishes immediately.
If none can be imported, the CLI asks you to enter cookies manually and
returns to this menu. If only some are imported, it lists the missing platforms
and offers Enter cookies manually (return to this menu) or Finish.
macOS may ask for access to the Chrome Safe Storage Keychain item. See
Authentication for profile selection and troubleshooting.
Known-platform sessions are saved under ~/.texleaf/sessions/. Custom-host
sessions are saved to .texleaf/session.json in the current directory unless
--session-file is provided.
If you already know the target, --platform cstcloud, --platform overleaf, --platform texpage,
or --host http://localhost can skip the selection prompt.
3. Clone an Overleaf project
Open the project in Overleaf and copy the project URL:
https://latex.cstcloud.cn/project/67ab12cd34ef567890abcdef
Then clone it into a project-named local Git repository:
cd ~/papers
texleaf clone https://latex.cstcloud.cn/project/67ab12cd34ef567890abcdef
cd PROJECT_NAME_FROM_OVERLEAF
texleaf clone parses the URL host and project id. These official URLs are
recognized:
texleaf clone https://latex.cstcloud.cn/project/6a72a92ee92000863e4de8a1
texleaf clone https://www.overleaf.com/project/697aee96f59bdd00852659f7
texleaf clone https://cn.overleaf.com/project/697aee96f59bdd00852659f7
texleaf clone https://www.texpage.com/project/user/PROJECT_KEY/VERSION_NO
TexPage URLs include both the project key and selected version. The clone pins
that version in .texleaf/config.json; TexPage project lookup by a raw key uses
the selected version returned by the account's project list.
The raw project id form still works when you provide the target platform or host yourself:
texleaf clone --platform cstcloud 67ab12cd34ef567890abcdef
For a self-hosted Overleaf Community Edition deployment, pass the base URL with
--host:
cd ~/papers
texleaf clone --host http://localhost 67ab12cd34ef567890abcdef
cd PROJECT_NAME_FROM_OVERLEAF
If you saved the custom-host session somewhere else, pass the same
--session-file to both auth login and clone.
4. Edit, review, and push
texleaf pull
# if pull staged remote changes:
git diff --cached
git commit -m "overleaf: import latest remote snapshot"
$EDITOR main.tex
git diff
git add -A
git commit -m "revise paper"
texleaf push --dry-run
texleaf push
texleaf push --dry-run prints the local push plan without writing to
Overleaf. texleaf push performs a freshness pull first, refuses dirty
worktrees and unresolved conflicts, then verifies the remote snapshot after
writing.
What It Does
texleaf-sync is a TypeScript CLI for syncing an Overleaf Community Edition
project with a local Git repository.
The CLI command is texleaf, and project metadata lives under .texleaf/ so
it can coexist with other tools. Local Git remains the safety layer: Overleaf
is imported into a managed branch, normal Git review handles conflicts, and
writes back to Overleaf only happen from committed local changes.
Current Status
Current version: CLI 0.1.5.
Important commands:
texleaf auth loginsaves a reusable Overleaf session.texleaf auth statusvalidates the saved session.texleaf auth logoutdeletes a saved session.texleaf clonedownloads an Overleaf project into a new local Git repository.texleaf pullimports the latest Overleaf snapshot and merges it through Git.texleaf statusshows local sync state and pending push operations.texleaf status --jsonprints machine-readable status.texleaf verifycompares the latest Overleaf snapshot with the local tree.texleaf pushapplies committed local changes back to Overleaf and verifies the result.texleaf push --dry-runprints the write plan without changing Overleaf.
TexPage supports project snapshots, text updates, and file synchronization for new, replaced, moved, renamed, and deleted text or binary files. Parent folders are created as needed. This CLI synchronizes regular files and paths; it does not preserve empty directories, symlinks, or filesystem permissions. TexPage binary uploads use short-lived object-storage credentials; the TexPage session cookie is not sent to storage.
Do not edit the same TexPage project in the browser while a CLI push is running. Both clients use the same account operation sequence, so concurrent edits are not supported. The server must return a complete CRDT history for text writes; the CLI rejects partial history before sending operations. Moving or renaming the configured main file does not update TexPage project settings; select the main file again in the TexPage UI if compilation no longer uses the intended file. A failed remote operation can leave earlier operations from the same push applied; pull or clone a fresh snapshot before retrying. After a verified push, the remote snapshot history records the exact local commit that was uploaded, so later pushes do not treat those writes as new remote changes.
Authentication
Known platforms store global sessions under ~/.texleaf/sessions/:
--platform cstclouduseshttps://latex.cstcloud.cnand expectslatex-sessionplusoverleaf.sid.--platform overleafuseshttps://www.overleaf.comand expectsoverleaf_session2.--platform texpageuseshttps://www.texpage.comand expectsSESSIONID.
On macOS, --from-chrome imports saved cookies from Google Chrome without
copying their values into the terminal:
texleaf auth login --from-chrome
texleaf auth login --platform cstcloud --from-chrome
texleaf auth login --platform overleaf --from-chrome --chrome-profile "Profile 1"
texleaf auth login --platform texpage --from-chrome
Without --platform or --host, --from-chrome starts the same all-platform
check as the menu option. It saves a separate file for each platform under
~/.texleaf/sessions/, honoring --profile, and requests the Keychain password
at most once per scan. Use --session-file only with an explicit --platform
or --host for Chrome import. In a noninteractive terminal, an incomplete
all-platform import exits with an error after saving any successful sessions.
The CLI searches Default and Profile N in Chrome's standard user data
directory. If several profiles contain matching cookies, specify one using
--chrome-profile "Default", --chrome-profile "Profile 1", or an absolute
profile directory path. This is separate from --profile, which names the
saved texleaf session.
The importer reads the cookie database in read-only mode, filters by the target host, expiry, and application path, and excludes partitioned cookies. For known platforms it imports only the session cookie names listed above. It decrypts cookies using macOS Keychain and validates the session before saving it with owner-only permissions. Cookie values are never printed. The encryption format follows Chromium's macOS Keychain implementation.
Log in to the target site in Chrome first. Allow Chrome Safe Storage access
when macOS prompts. If cookies cannot be found or the database is locked, quit
Chrome and retry so its cookies are flushed to disk. The import is a snapshot;
before clone, pull, push, verify, and auth status, the CLI checks the saved
session. On macOS, a missing or rejected session triggers one automatic Chrome
import for the target host. Valid cookies are saved to the same session file and
the command continues. Sessions imported from Chrome remember the selected
profile directory for future refreshes. The CLI asks you to log in only if the
import fails; network and server errors are reported without importing cookies.
Chrome import uses the system sqlite3 and security commands. On other systems,
or if Keychain access is denied, use the interactive cookie login below.
For custom Overleaf Community Edition hosts, pass --host. Password login is
usually the simplest path for local Docker and self-hosted deployments; pass
--email and let the CLI prompt for the password.
If password login is blocked by SSO, captcha, or another local policy, run
cookie login interactively and paste the browser Cookie header when prompted.
Self-hosted Community Edition deployments commonly use sharelatex.sid, but
the exact cookie name can vary with local configuration, so use the browser's
actual Cookie header for that host.
Session cookies grant access to your account: never post them in issues, paste
them into logs, or commit .texleaf/session.json or files under
~/.texleaf/sessions/.
For https://latex.cstcloud.cn, TLS verification is disabled by default because
that deployment's certificate chain can fail in local CLI websocket clients.
Use --insecure for another host only when you understand the trust boundary.
End-to-End Workflow
Pull the latest remote snapshot
Run pull before editing when other people may have changed the online project:
texleaf pull
If remote changes are staged, review and commit them:
git diff --cached
git commit -m "overleaf: import latest remote snapshot"
Edit locally and commit
$EDITOR main.tex
git diff
git add -A
git commit -m "revise paper"
Push back to Overleaf
Preview first:
texleaf push --dry-run
Then write:
texleaf push
Before writing, texleaf push imports a freshness snapshot and checks it
against the merge base of the current branch and the managed remote branch.
Only when the remote actually has newer Overleaf content does it stage those
changes through Git and stop, so you can review and commit the merge before
trying again. Unpushed local commits alone never block the push.
Check status or verify
texleaf status
texleaf verify
Use texleaf verify --allow-diff when you want a zero exit code while still
printing differences.
Configuration
Example .texleaf/config.json:
{
"project": {
"host": "https://latex.cstcloud.cn",
"projectId": "67ab12cd34ef567890abcdef",
"projectName": "my-paper",
"platform": "cstcloud"
},
"backend": {
"timeoutMs": 16000,
"sslVerify": false
},
"git": {
"mainBranch": "main",
"remoteBranch": "texleaf-remote"
},
"auth": {
"profile": "default",
"sessionFile": "/Users/you/.texleaf/sessions/cstcloud.json"
},
"sync": {
"snapshotDir": ".texleaf/snapshots",
"lockFile": ".texleaf/lock",
"lastSyncedFile": ".texleaf/last_synced_commit",
"lastRemoteSnapshotFile": ".texleaf/last_remote_snapshot_commit"
},
"ignore": {
"patterns": [
".git/",
".gitignore",
".env",
".texleaf/"
]
}
}
.texleaf/config.json records the project/platform binding. The managed
texleaf-remote branch stores the latest imported Overleaf snapshot.
Never commit cookies or local sync metadata under .texleaf/.
Development
When working from a linked source checkout, rebuild after source changes so the
global texleaf command sees the latest compiled files.
npm install
npm run build
npm link
npm test
node dist/cli.js --help
Packaging The CLI
To build a distributable npm tarball:
npm pack
ls -lh texleaf-sync-*.tgz
The tarball contains dist/, the READMEs, and the license file. It can be
installed with npm install -g ./texleaf-sync-0.1.5.tgz.
Ähnliche Projekte entdecken
Wird geladen…