Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ All notable changes to this project will be documented in this file.
## [Unreleased]

### Added
- **Turn pushed edits into tracked changes** ([#66](https://github.com/aloth/olcli/pull/66)) - `suggestChanges(projectId, path, edits)` makes edits that reached Overleaf as plain text, through git, `olcli push` or a sync, show up as tracked changes, as if they had been typed in Reviewing mode. Each edit is given as the old and new text with some text around it; olcli finds the new text, undoes the edit without tracking and redoes it with tracking (`meta.tc` on the update, as the editor sends it). The text ends up as it was, so a git clone that pushed the edit has nothing new to pull. An edit whose new text is not on Overleaf yet is reported as `not-pushed` and left alone. sharejs-text-ot docs only; history-ot docs are refused. Thanks to @fredericosantos
- **MCP tool `suggest_changes` (experimental)** - turns edits that are already on Overleaf as plain text into suggestions collaborators can accept or reject, for projects with track changes, by calling `suggestChanges`. Like the other write tools it asks the user first: the dialog lists each edit with its location and the suggested deletion and insertion, or why it is left alone. If no edit can become a suggestion it asks nothing and writes nothing, and it refuses to write when the document changed after the preview. Clients without elicitation get the preview only, since there is no olcli command for this yet. sharejs-text-ot documents only; returns one result per edit
- **Turn pushed edits into suggestions (experimental)** ([#66](https://github.com/aloth/olcli/pull/66), [#70](https://github.com/aloth/olcli/pull/70)) - `suggestChanges(projectId, path, edits)` makes edits that reached Overleaf as plain text, through git, `olcli push` or a sync, show up as tracked changes that collaborators can accept or reject, as if they had been typed in Reviewing mode. Each edit is given as the old and new text with some text around it; olcli finds the new text, undoes the edit without tracking and redoes it with tracking. The text ends up as it was, so a git clone that pushed the edit has nothing new to pull. Each edit gets a result: `done`, `not-pushed` (the new text is not on Overleaf yet), `not-found`, `already-tracked` (running it again sends nothing), `unchanged`, `invalid` or `not-tracked` (the document was read again and no tracked change was found). `planSuggestions` reports the results without writing, and `expectedVersion` refuses to write when the document changed since. Review-only access is refused with `SuggestionPermissionError` before anything is written. Limits: sharejs-text-ot documents only (history-ot documents are refused), and collaborators who have the document open see the old text for about 0.2 seconds. Documented in docs/LIBRARY.md. Thanks to @fredericosantos for the idea and the first implementation
- **MCP tool `suggest_changes` (experimental)** ([#70](https://github.com/aloth/olcli/pull/70)) - lets an agent turn edits that are already on Overleaf into suggestions, for projects with track changes. Like the other write tools it asks first: the dialog lists each edit with its location and the suggested deletion and insertion, or why it is left alone. If no edit can become a suggestion it asks nothing and writes nothing, and it refuses to write when the document changed after the preview. Clients without elicitation get the preview only. Returns one result per edit

### Fixed
- **`suggestChanges` no longer hangs on an edit with nothing to search for** - an edit whose `before`, `inserted` and `after` were all empty, such as a pure deletion given without surrounding text, made the search loop forever. Such an edit is now reported as `invalid` and nothing is sent
- **`suggestChanges` no longer tracks the same edit twice** - running it again for an edit that is already a tracked change added a second tracked change, and the tracked deletion held the old text twice. An edit whose new or old text is already tracked at that place is now reported as `already-tracked` and nothing is sent, also when the same edit appears twice in one call
- **`suggestChanges` checks its result** - after writing, the document is read again, and an edit without a tracked change at the expected place is reported as `not-tracked` instead of `done`
- **`suggestChanges` names the missing permission** - with review-only access the untracked undo is refused, and the call failed with "applyOtUpdate did not return an acknowledgement". It now throws `SuggestionPermissionError`, which says that the account needs edit access to the project, and nothing is written. When Overleaf reports the access level up front, the check happens before anything is sent
- **`suggestChanges` sends a tracked-change id seed in Overleaf's format** - the seed in `meta.tc` was 18 random hex digits; it now starts with the current time in seconds like the seeds the Overleaf editor generates, so the ids of the new tracked changes carry a meaningful timestamp
- **Password sign-in on overleaf.com says why it fails** - overleaf.com requires a captcha for password sign-in and answers a form post without one with HTTP 400, so `olcli auth --email`, and every command that signs in with `OVERLEAF_EMAIL` and `OVERLEAF_PASSWORD`, failed with only "Password login failed. HTTP 400". olcli now recognizes Overleaf's captcha rejection (`errorReason: "cannot_verify_user_not_robot"`), or, when the answer gives no reason, a login page with reCAPTCHA switched on for login, and stops with "<host> requires a captcha for password sign-in, which olcli cannot complete. Sign in with `olcli auth --browser`, or paste a session cookie with `olcli auth --cookie`." The CLI, the MCP server and the git remote helper print the same message; library code gets a `CaptchaRequiredError`. A wrong password keeps its old message, and the exit status is unchanged. On a terminal, `olcli auth --email` then asks "Sign in in the browser instead? [Y/n]" and runs the same flow as `olcli auth --browser` on yes; scripts, CI and the other commands never get a question
- **The progress spinner no longer hangs on a terminal without a width** - a terminal that reports a width of 0, such as a pseudo-terminal opened without a window size, made the spinner try to clear an endless number of lines on every frame, so a command printed control codes forever instead of finishing. Such a terminal now gets the plain output used for pipes and logs

### Changed
- **`suggestChanges` reports `unchanged`** for an edit whose `inserted` equals `deleted`, instead of `not-pushed`. `SuggestionResult` gains `already-tracked`, `unchanged`, `invalid` and `not-tracked`; existing values keep their meaning. `hint` is now optional
- **`suggestChanges` is marked experimental** - sharejs-text-ot documents only (history-ot documents are refused), and collaborators who have the document open see the old text for about 0.2 seconds while an edit is undone and redone. `planSuggestions` reports what it would do without writing, and an `expectedVersion` option refuses to write when the document changed since. Documented in docs/LIBRARY.md
- **Password sign-in is documented as self-hosted only** - `olcli --help`, `olcli auth --help`, the README, docs/CONFIGURATION.md, docs/MCP.md and SKILL.md say that `--email` and `OVERLEAF_EMAIL`/`OVERLEAF_PASSWORD` work only on self-hosted servers without reCAPTCHA and point to `olcli auth --browser` for overleaf.com. `olcli auth status` warns when password credentials would be used on overleaf.com, and its JSON output gains a `warnings` array

### Documentation
- **Contributing without an issue first** - CONTRIBUTING.md now welcomes pull requests at any time; for a larger change a draft pull request works as well as an issue. A pull request that does what it says is merged as it is, and remaining findings are fixed in a follow-up

## [0.17.0] - 2026-11-15

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ olcli auth status # instance, account, where the credential comes fr

**Get your session cookie:** sign in to Overleaf in a browser, open the developer tools (F12), then Application (Chrome, Edge) or Storage (Firefox), Cookies, and copy the value of `overleaf_session2` (`overleaf.sid` on most self-hosted instances). A value on the command line also works but lands in your shell history.

Self-hosted instances without reCAPTCHA also accept `olcli auth --email you@example.com`, which prompts for the password. Scripts can set `OVERLEAF_SESSION`, or `OVERLEAF_EMAIL` and `OVERLEAF_PASSWORD`, and skip `olcli auth` entirely.
Self-hosted instances without reCAPTCHA also accept `olcli auth --email you@example.com`, which prompts for the password. overleaf.com requires a captcha for password sign-in, which olcli cannot complete, so use `olcli auth --browser` or `olcli auth --cookie` there; on a terminal, a refused password sign-in offers the browser sign-in instead. Scripts can set `OVERLEAF_SESSION`, or on self-hosted instances without reCAPTCHA `OVERLEAF_EMAIL` and `OVERLEAF_PASSWORD`, and skip `olcli auth` entirely.

### Self-hosted Overleaf

Expand Down
8 changes: 5 additions & 3 deletions SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ reports each. Environment variables cannot be unset by a child process, so
`OVERLEAF_SESSION` and `OVERLEAF_EMAIL`/`OVERLEAF_PASSWORD` are reported rather
than silently ignored — they outrank anything on disk.

For unattended use, prefer `OVERLEAF_EMAIL`/`OVERLEAF_PASSWORD` over
`olcli auth --password`: every command reads them, and nothing is written to
disk or to shell history.
For unattended use on a self-hosted instance without reCAPTCHA, prefer
`OVERLEAF_EMAIL`/`OVERLEAF_PASSWORD` over `olcli auth --password`: every
command reads them, and nothing is written to disk or to shell history.
overleaf.com requires a captcha for password sign-in, which olcli cannot
complete; use `olcli auth --browser` or `OVERLEAF_SESSION` there.

### Self-hosted Overleaf

Expand Down
6 changes: 3 additions & 3 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ Everything is stored in plaintext, so it is worth knowing what is on disk:

### Password login

Self-hosted instances without reCAPTCHA accept a password login:
Self-hosted instances without reCAPTCHA accept a password login. overleaf.com does not: it requires a captcha for password sign-in, which olcli cannot complete, and olcli says so instead of a bare HTTP 400. Use `olcli auth --browser` or `olcli auth --cookie` there. On a terminal, `olcli auth --email` offers the browser sign-in when the captcha refuses the password; `olcli auth status` warns when password credentials would be used on overleaf.com.

```bash
olcli auth --email "you@example.com"
# prompts for the password, so it stays out of your shell history
```

The password is **not stored** unless you pass `--save-password`. A session cookie is saved either way and is what later commands use; the password only buys an automatic re-login once that cookie expires. For scripts, set `OVERLEAF_EMAIL` and `OVERLEAF_PASSWORD`: every command reads them, so a scripted run never needs `olcli auth` at all.
The password is **not stored** unless you pass `--save-password`. A session cookie is saved either way and is what later commands use; the password only buys an automatic re-login once that cookie expires. For scripts on such an instance, set `OVERLEAF_EMAIL` and `OVERLEAF_PASSWORD`: every command reads them, so a scripted run never needs `olcli auth` at all.

## Self-hosted Overleaf

Expand Down Expand Up @@ -62,7 +62,7 @@ olcli reads these. The MCP server and the git remote helper read the same sessio
| Variable | Purpose |
|---|---|
| `OVERLEAF_SESSION` | Session cookie value |
| `OVERLEAF_EMAIL`, `OVERLEAF_PASSWORD` | Password login, used when no session cookie is set or it is rejected |
| `OVERLEAF_EMAIL`, `OVERLEAF_PASSWORD` | Password login, used when no session cookie is set or it is rejected. Self-hosted instances without reCAPTCHA only; overleaf.com requires a captcha (use `olcli auth --browser`) |
| `OVERLEAF_BASE_URL` | Instance URL, like `--base-url` (default: `https://www.overleaf.com`) |
| `OVERLEAF_COOKIE_NAME` | Session cookie name, like `--cookie-name` (default: `overleaf_session2`; self-hosted instances often use `overleaf.sid`) |
| `OVERLEAF_TIMEOUT` | HTTP timeout in milliseconds, like `--timeout` |
Expand Down
2 changes: 1 addition & 1 deletion docs/MCP.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Every tool declares MCP tool annotations. Read-only tools set `readOnlyHint`. To
The MCP server reads credentials in this order:

1. **`OVERLEAF_SESSION` environment variable** — set in your MCP config (recommended)
2. **`OVERLEAF_EMAIL` + `OVERLEAF_PASSWORD` environment variables** — for password login (self-hosted)
2. **`OVERLEAF_EMAIL` + `OVERLEAF_PASSWORD` environment variables** - for password login on self-hosted instances without reCAPTCHA. overleaf.com requires a captcha for password sign-in, which olcli cannot complete; the tools then fail with a message that says so. Use `OVERLEAF_SESSION` or run `olcli auth --browser` once instead
3. **`.olauth` file in cwd** — written by `olcli auth --save-local`
4. **Stored config** — written by `olcli auth` (including saved password credentials)

Expand Down
81 changes: 81 additions & 0 deletions src/auth-fallback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* What `olcli auth` does when a password sign-in is refused because the
* instance requires a captcha: on a terminal, offer the browser sign-in
* instead; everywhere else, only report it.
*
* Kept apart from cli.ts so the decision can be tested without a terminal,
* a browser or the network.
*/

import { CaptchaRequiredError } from './errors.js';

export interface BrowserFallbackDeps {
/** True when a person is at the terminal (see `canOfferBrowserSignIn`). */
interactive: boolean;
/** Throws with a reason when `auth --browser` cannot run here (no browser, old Node). */
checkBrowser: () => void;
/** Asks the question; resolves to true for yes. */
ask: (question: string) => Promise<boolean>;
/** Runs the same flow as `olcli auth --browser`. */
runBrowser: () => Promise<void>;
}

/**
* - `browser`: the user said yes and the browser sign-in ran
* - `declined`: the user said no
* - `unavailable`: interactive, but `auth --browser` cannot run here; `reason` says why
* - `not-offered`: not a captcha error, or nobody to ask
*/
export type BrowserFallbackOutcome =
| { outcome: 'browser' }
| { outcome: 'declined' }
| { outcome: 'unavailable'; reason: string }
| { outcome: 'not-offered' };

export const BROWSER_FALLBACK_QUESTION = 'Sign in in the browser instead?';

/**
* True when stdin and stdout are both terminals and no CI system is driving
* the run. Only then can a question be answered by a person.
*/
export function canOfferBrowserSignIn(
streams: { stdin: { isTTY?: boolean }; stdout: { isTTY?: boolean } } = { stdin: process.stdin, stdout: process.stdout },
env: NodeJS.ProcessEnv = process.env,
): boolean {
const ci = env.CI !== undefined && env.CI !== '' && env.CI !== '0' && env.CI.toLowerCase() !== 'false';
return Boolean(streams.stdin.isTTY) && Boolean(streams.stdout.isTTY) && !ci;
}

export async function offerBrowserSignIn(error: unknown, deps: BrowserFallbackDeps): Promise<BrowserFallbackOutcome> {
if (!(error instanceof CaptchaRequiredError) || !deps.interactive) return { outcome: 'not-offered' };
try {
deps.checkBrowser();
} catch (reason) {
return { outcome: 'unavailable', reason: reason instanceof Error ? reason.message : String(reason) };
}
if (!(await deps.ask(BROWSER_FALLBACK_QUESTION))) return { outcome: 'declined' };
await deps.runBrowser();
return { outcome: 'browser' };
}

/** Hosts where password sign-in is known to need a captcha. */
const CAPTCHA_HOSTS = new Set(['www.overleaf.com', 'overleaf.com']);

/**
* Warnings for `auth status` about the credential that would be used.
* Password credentials on overleaf.com cannot sign in, because Overleaf
* requires a captcha for password sign-in there. Self-hosted instances are
* not judged: whether they have reCAPTCHA switched on is only known after a
* sign-in attempt.
*/
export function passwordSignInWarnings(usesPassword: boolean, baseUrl: string): string[] {
if (!usesPassword) return [];
let host: string;
try {
host = new URL(baseUrl).hostname.toLowerCase();
} catch {
return [];
}
if (!CAPTCHA_HOSTS.has(host)) return [];
return ['overleaf.com requires a captcha for password sign-in, which olcli cannot complete. Sign in with: olcli auth --browser'];
}
Loading
Loading