Imported from cafferychen777/overleaf-cli (
skills/overleaf-cli/SKILL.md). Install upstream withnpx skills add cafferychen777/overleaf-cli --skill overleaf-cli. Copyright stays with the author.
Overleaf CLI
Establish Context
- Locate the executable with
command -v overleaf-cli. In the source repository, runnpm run buildand usenode out/index.jswhen the installed executable is unavailable. - Run
<cli> --helpand the relevant<cli> <command> --helpbefore relying on remembered flags. Treat current CLI output as authoritative. - Find the project root by walking upward for
.overleaf-cli.json. Keep all project-relative paths within that root. - Read references/command-and-safety.md before running a mutating command, resolving conflicts, diagnosing protocol behavior, or editing this CLI.
Never print, return, commit, or inspect the contents of saved cookies, passwords, or ~/.overleaf-cli/config.json. Report only whether credentials exist for the selected normalized server.
Choose the Least-Mutating Workflow
- Inspect state with
list,diff,history list,history diff,history export, orshare listbefore changing remote data. - Use
pullto create or refresh a local replica. Preserve its default conflict archive behavior. Add--forceonly when the user explicitly accepts overwriting unarchived local conflicts. - Run
diffbeforepushwhenever practical and inspect every deletion. Ordinarypushmay delete paths previously tracked by this replica, but preserves remote-only paths. Add--prune-remoteonly when the user explicitly wants local files to mirror-delete remote-only paths. - Use
watchonly for an explicitly requested continuous session. Keep the process observable, report connection or conflict events, and stop it cleanly on request. - Treat
init,push,watch,history restore, and share mutations as remote writes. Resolve the exact project and target before execution; stop when identity or scope remains ambiguous. - Treat
compileas a remote build plus a localoutput.pdforoutput.logwrite. Preserve any unrelated output the user needs.
Do not broaden authorization merely because the command supports a flag. Preserve unrelated local files and remote collaborators.
Handle Conflicts Conservatively
- Stop automatic remote writes when the CLI reports a merge conflict.
- Preserve the visible local file and every snapshot under
.overleaf-cli-conflicts/. - Compare the local file, conflict snapshot, and available merge base; produce one resolved local file.
- Run
diff, thenpushonly after the resolution matches user intent. - Leave conflict archives intact unless the user explicitly asks to remove verified obsolete snapshots.
Do not hand-edit .overleaf-cli-hashes.json, .overleaf-cli-tracked.json, or .overleaf-cli-cache/ during normal operation. Diagnose their invariant first when recovery work truly requires an edit.
Troubleshoot Systematically
- Reproduce with
--verbosewhile redacting secrets from all output. - Separate failures into configuration, HTTP, Socket.IO/OT, local filesystem, merge, compile, history, or sharing layers.
- Verify normalized server and project identity, project-root containment, ignored-path behavior, and whether the file is text or binary.
- Increase
OVERLEAF_CLI_HTTP_TIMEOUT_MSorOVERLEAF_CLI_SOCKET_TIMEOUT_MSonly for demonstrated timeout failures. - Prefer a minimal local test or fake protocol response over mutating a real Overleaf project during diagnosis.
Maintain the Source
- Preserve the architecture boundaries described in the reference file: commands orchestrate, APIs transport, sync modules reconcile, and state stores persist invariants.
- Keep code and comments in English.
- Reuse
ProjectContext, path helpers, local snapshot classification, state storage, and centralized colors instead of rebuilding parallel logic. - Reject traversal, symlink escapes, invalid OT positions, ambiguous compile artifacts, and unsafe remote names at boundaries.
- Make writes atomic when persisting credentials, project binding, hashes, tracked paths, or cached merge bases.
- Add regression tests for each bug. Run
npm test,git diff --check,npm audit --json, CLI help/version smoke tests, and an isolatednpm packinstall for dependency or packaging changes. - Preserve the patched Overleaf Socket.IO client and bundled compatible
wsversion unless replacing the legacy protocol stack with a verified end-to-end alternative.
Report what changed, which checks passed, and any unverified live-server behavior. Never claim that private Overleaf endpoints are stable without an integration test against the intended server.