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
34 changes: 27 additions & 7 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,29 @@ pending suggestions, since its break-and-restore would drop them. `submit` re-jo
the doc before every attempt unless `EditOptions.overwriteTrackedChanges` is set (the mirror
tracks text, not ranges, so earlier ranges may be stale) and throws `TrackedChangeConflictError`
(with `.changes`) before sending. Why: an edit inside a co-author's pending suggestion silently
rewrites or removes it, and Overleaf mails its author that the suggestion was rejected.
`listTrackedChanges` names authors from the project's owner/members. The MCP exposes
`overleaf_list_tracked_changes` but deliberately no override, so an agent asks a human instead;
the CLI has `changes` and `--overwrite-tracked-changes`.
rewrites or removes it, and Overleaf mails its author that the suggestion was rejected. Only
**other authors'** changes are protected (`foreignChanges`): the signed-in user's id is scraped
from the project page's `ol-user_id` (`RestClient.currentUserId`, alongside the CSRF token; it is
not in `joinProjectResponse`) and changes with that `user_id` pass. Verified live: a tracked
insert inside one's own tracked insertion extends it (same id), a tracked delete inside it just
shrinks it (no deletion change), an untracked insert splits it in two. A change without an
author, or every change when the user id is unknown, stays protected. `listTrackedChanges` names
authors from the project's owner/members. The MCP exposes `overleaf_list_tracked_changes` and an
`overwriteTrackedChanges` param on the seven text-writing tools, described as only for when the
user explicitly said to override a co-author's suggestion; the CLI has `changes` and
`--overwrite-tracked-changes`. Without a path, `listTrackedChanges` walks every doc (each
change carries its `path`).

**Accepting tracked changes** is HTTP, not realtime (verified live):
`POST /project/:id/doc/:docId/changes/accept {change_ids:[...]}` (cookie + CSRF) → 204. The text
and version do not change (an accepted insertion stays, an accepted deletion is already gone);
only the ranges drop the changes, and the server broadcasts `accept-changes [docId, ids]` to
the project, which the mirror can ignore. `acceptTrackedChanges(path, ids)` re-joins first and
accepts nothing if any id is not pending in that doc. MCP: `overleaf_accept_tracked_changes`
(destructive: an accepted suggestion can no longer be rejected; its description limits it to
changes the user explicitly said to accept). CLI: `accept <project> <path> <id>... | --all
[--before ISO-DATE]`. Rejecting is not implemented (the editor does it client-side by
applying the inverse op).

**Hash.** Overleaf's optional ShareJS hash is git-blob SHA-1 (`ot.gitBlobHash`). We **omit
it**: the server treats it as optional, and a mismatch is fatal (`otUpdateError "Invalid
Expand Down Expand Up @@ -261,8 +280,9 @@ state; instead:
also `idempotentHint: false`, since each call kicks off a fresh build. The writes set
`destructiveHint` explicitly (it would otherwise default to `true` whenever `readOnlyHint`
is `false`): `true` for overwrite/remove tools (`replace_text`, `replace_range`,
`delete_range`, `delete_lines`, `set_document`, `delete_document`, and `upload_file` — which
replaces a same-named file), `false` for the purely additive ones (`insert_text`,
`delete_range`, `delete_lines`, `set_document`, `delete_document`, `accept_tracked_changes`
— an accepted suggestion can no longer be rejected — and `upload_file`, which replaces a
same-named file), `false` for the purely additive ones (`insert_text`,
`append_text`, `create_document`, `add_comment` — which only annotates, leaving the text
unchanged — and `rename_document`, which changes a name, losing no content). The seven write
tools that change document text also take an optional `trackChanges` to submit as a
Expand All @@ -288,7 +308,7 @@ No configuration is required. Overrides (mainly for self-hosted / tuning):
`project(idOrName)` → `ProjectSession`. All document methods take a `project` (id or name) as
the first argument and are `async`: `projectInfo`, `listDocuments`, `readDocument`, `getLines`,
`documentVersion`, `search`, `insertAt`, `insert`, `append`, `deleteRange`, `replaceRange`,
`replaceText`, `setText`, `deleteLines`, `setCursor`, `getConnectedUsers`, `listTrackedChanges`, `createDocument`,
`replaceText`, `setText`, `deleteLines`, `setCursor`, `getConnectedUsers`, `listTrackedChanges`, `acceptTrackedChanges`, `createDocument`,
`uploadFile`, `createFolder`, `deleteDocument`, `renameDocument`, `resync`, `compile`. `ProjectSession`
exposes the same methods without the leading `project` argument. Every edit method takes an
optional trailing `EditOptions` (`{trackChanges?}`) — set `trackChanges` to submit the edit as
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Bring Claude (and any agent) into Overleaf. Claudeleaf is a reliable TypeScript
- **Full document control** — list documents, read text, insert at a position or line/column, replace ranges or literal text, delete ranges or lines, replace a whole document, create/delete/rename files, and **upload images** (e.g. a local W&B plot PNG) for `\includegraphics`: `claudeleaf upload <project> plot.png --folder figures` or the `overleaf_upload_file` MCP tool.
- **Review mode (track changes).** Submit any edit as a tracked change (a suggestion) with `trackChanges` instead of a direct edit, so a human accepts or rejects it in Overleaf. Requires track changes on the project (a premium feature).
- **Comments.** Anchor a comment to a span of text (like selecting text and commenting in the editor) and list a document's comments with their threads.
- **Collaborators' suggestions are protected.** List a document's pending tracked changes with their authors (`claudeleaf changes <project> <path>`, `overleaf_list_tracked_changes`). Any edit that would change text inside someone's pending suggestion is refused before it is sent, instead of silently rewriting it (which Overleaf reports to the author as a rejected suggestion). Override in the SDK/CLI with `overwriteTrackedChanges` / `--overwrite-tracked-changes`; the MCP server has no override, so an agent asks a human.
- **Collaborators' suggestions are protected.** List a document's pending tracked changes with their authors (`claudeleaf changes <project> <path>`, `overleaf_list_tracked_changes`). Any edit that would change text inside a co-author's pending suggestion is refused before it is sent, instead of silently rewriting it (which Overleaf reports to the author as a rejected suggestion). Your own suggestions stay editable: editing inside one extends or shrinks it, as in the Overleaf editor. Override with `overwriteTrackedChanges` (SDK, MCP) / `--overwrite-tracked-changes` (CLI); the MCP tools tell an agent to use it only when the user explicitly asked to override a co-author's suggestion.
- **Accept suggestions.** Accept pending tracked changes by id, like the review panel's Accept (`claudeleaf accept <project> <path> <id>...`, `--all`, `--before 2026-10-15`; MCP `overleaf_accept_tracked_changes`). `changes` without a path lists the whole project.
- **Compile & error logs** — trigger a LaTeX recompile and get back the status plus the parsed errors and warnings (with file and line), or the full raw log.
- **Reliable by design** — automatic reconnect with document re-join, per-document edit serialization, and server-confirmed edits (no silent loss).
- **Zero config, easy sign-in.** No credentials stored and nothing to configure: run `claudeleaf login` once, sign in by hand in the browser that opens (handles reCAPTCHA / SSO / 2FA), and the session is cached.
Expand Down
37 changes: 32 additions & 5 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { OverleafClient } from "./client.js";
import { Config } from "./config.js";
import { ClaudeleafError } from "./errors.js";

const VALUE_FLAGS = new Set(["count", "folder", "name"]);
const VALUE_FLAGS = new Set(["count", "folder", "name", "before"]);

function parseArgs(args: string[]): { positionals: string[]; flags: Record<string, string | boolean> } {
const positionals: string[] = [];
Expand Down Expand Up @@ -80,7 +80,9 @@ Usage: claudeleaf <command> [args]
comment <project> <path> <start> <end> [message|-]
comment on the [start,end) span
comments <project> <path> list a document's comments
changes <project> <path> list a document's pending tracked changes
changes <project> [path] list pending tracked changes (whole project if no path)
accept <project> <path> <id>... | --all [--before ISO-DATE]
accept tracked changes (by id, or all / all before a date)
upload <project> <localFile> [--folder DIR] [--name NAME]
upload an image/PDF for \includegraphics
compile <project> [--draft] [--stop-on-first-error] [--log] [--warnings]
Expand All @@ -91,8 +93,8 @@ project is an id or name. line/column are 0-based; start/end are character offse
The editing commands (append, insert, replace, set) accept --track-changes to
submit the edit as a review-mode suggestion instead of a direct edit (requires
track changes on the project, a premium feature). They refuse, sending nothing,
an edit that would touch a pending tracked change; --overwrite-tracked-changes
skips that check.`;
an edit that would touch another author's pending tracked change (your own
suggestions stay editable); --overwrite-tracked-changes skips that check.`;

async function run(argv: string[]): Promise<number> {
const command = argv[0];
Expand Down Expand Up @@ -246,10 +248,35 @@ async function run(argv: string[]): Promise<number> {
for (const c of changes) {
const who = c.author ?? c.email ?? c.userId ?? "?";
const when = c.timestamp ? ` ${c.timestamp}` : "";
console.log(`${c.line}:${c.column} ${c.kind.padEnd(6)} ${who}${when} ${JSON.stringify(c.text)}`);
const where = positionals[1] === undefined ? `${c.path} ` : "";
console.log(`${c.id} ${where}${c.line}:${c.column} ${c.kind.padEnd(6)} ${who}${when} ${JSON.stringify(c.text)}`);
}
return 0;
}
case "accept": {
const path = positionals[1];
if (!path) {
console.error("error: 'accept' needs a document path");
return 1;
}
let ids = positionals.slice(2);
const before = typeof flags.before === "string" ? Date.parse(flags.before) : undefined;
if (before !== undefined && Number.isNaN(before)) {
console.error(`error: --before is not a date: ${flags.before}`);
return 1;
}
if (ids.length === 0 && (boolFlag(flags.all) || before !== undefined)) {
ids = (await client.listTrackedChanges(project, path))
.filter((c) => before === undefined || (c.timestamp !== undefined && Date.parse(c.timestamp) < before))
.map((c) => c.id);
} else if (ids.length === 0) {
console.error("error: 'accept' needs change ids, --all or --before");
return 1;
}
const accepted = await client.acceptTrackedChanges(project, path, ids);
console.log(`Accepted ${accepted.length} tracked change(s) in ${path}.`);
return 0;
}
case "upload": {
const file = positionals[1];
if (!file) {
Expand Down
7 changes: 6 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,15 @@ export class OverleafClient {
}

// -- tracked changes --------------------------------------------------
async listTrackedChanges(project: string, path: string): Promise<TrackedChange[]> {
/** A document's pending tracked changes, or the whole project's when `path` is omitted. */
async listTrackedChanges(project: string, path?: string): Promise<TrackedChange[]> {
return (await this.project(project)).listTrackedChanges(path);
}

async acceptTrackedChanges(project: string, path: string, changeIds: string[]): Promise<TrackedChange[]> {
return (await this.project(project)).acceptTrackedChanges(path, changeIds);
}

// -- presence & structure ---------------------------------------------
async setCursor(project: string, path: string, line: number, column: number): Promise<void> {
await (await this.project(project)).setCursor(path, line, column);
Expand Down
Loading
Loading