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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Added
- **Tracked-change types in the package entry** - `TrackedChange`, `ProjectReview`, `ListTrackedChangesOptions`, the acceptance and rejection plan types, `TrackedChangeKind`, `TrackedChangeAuthor`, `ShareJsTextOp` and `RejectConflictError` are exported from `@aloth/olcli`, so code that uses `listReview`, `listTrackedChanges` or `rejectTrackedChanges` as a library can name what they return and catch the conflict error
- **Accept tracked changes of one doc with a single request** - `acceptTrackedChangesInDoc(projectId, docId, ids)` sends just the editor's accept request. `acceptTrackedChanges` reads the whole project before and after to resolve the ids and check the result, which is right for the CLI but costs two passes over every doc; an editor integration that already holds the changes and re-reads the project after every write can skip both. `acceptTrackedChanges` now uses it for each doc, so the request is built in one place
- **The text around a tracked change, on request** - `listTrackedChanges` and `listReview` take `surroundingChars`, and each change then carries `before` and `after`: up to that many characters of the visible text right before the change and right after it (after the inserted text for an insert). `position` only fits Overleaf's current copy of the doc; a tool that shows tracked changes in a local copy that was edited since, such as a git clone, needs some surrounding text to find each change again. Off by default, so the output of `olcli changes` does not change

## [0.16.2] - 2026-11-11

Expand Down
26 changes: 22 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export type CommentStatus = 'all' | 'open' | 'resolved';
export interface ListCommentsOptions {
status?: CommentStatus;
contextLines?: number;
/** For `listReview`: characters of text around each tracked change, as in `ListTrackedChangesOptions`. */
surroundingChars?: number;
/** Sockets used to join docs in parallel (1-8). Defaults to OLCLI_CONCURRENCY, else 4. */
concurrency?: number;
}
Expand Down Expand Up @@ -176,10 +178,20 @@ export interface TrackedChange {
author: TrackedChangeAuthor;
timestamp?: string;
context?: CommentContext;
/**
* Up to `surroundingChars` characters of the visible text right before and
* right after the change (after the inserted text for an insert). Only set
* when asked for; enough to find the change again in a copy of the doc that
* was edited since, where `position` no longer fits.
*/
before?: string;
after?: string;
}

export interface ListTrackedChangesOptions {
contextLines?: number;
/** Characters of text to return around each change as `before`/`after` (0, the default, returns none). */
surroundingChars?: number;
/** Sockets used to join docs in parallel (1-8). Defaults to OLCLI_CONCURRENCY, else 4. */
concurrency?: number;
}
Expand Down Expand Up @@ -2432,7 +2444,7 @@ export class OverleafClient {
const joinedDocs = await this.joinDocuments(projectId, docs, resolveCommentConcurrency(options.concurrency));
return {
comments: this.commentsFromDocs(docs, joinedDocs, threads, options.status || 'all', contextLines),
changes: await this.changesFromDocs(projectId, projectInfo, docs, joinedDocs, contextLines)
changes: await this.changesFromDocs(projectId, projectInfo, docs, joinedDocs, contextLines, options.surroundingChars)
};
}

Expand Down Expand Up @@ -2538,15 +2550,16 @@ export class OverleafClient {
const projectInfo = await this.getProjectInfo(projectId);
const docs = this.collectProjectDocs(projectInfo);
const joinedDocs = await this.joinDocuments(projectId, docs, resolveCommentConcurrency(options.concurrency));
return this.changesFromDocs(projectId, projectInfo, docs, joinedDocs, options.contextLines || 0);
return this.changesFromDocs(projectId, projectInfo, docs, joinedDocs, options.contextLines || 0, options.surroundingChars);
}

private async changesFromDocs(
projectId: string,
projectInfo: ProjectInfo,
docs: ProjectDoc[],
joinedDocs: JoinedDocument[],
contextLines: number
contextLines: number,
surroundingChars = 0
): Promise<TrackedChange[]> {
const perDoc = joinedDocs.map(doc => this.docTrackedChanges(doc));
const anyChanges = perDoc.some(doc => doc.changes.length > 0);
Expand All @@ -2557,6 +2570,7 @@ export class OverleafClient {
const { changes, visibleContent } = perDoc[index];
for (const change of changes) {
const location = this.positionToLineColumn(visibleContent, change.position);
const end = change.kind === 'insert' ? change.position + change.text.length : change.position;
result.push({
id: change.id,
docId: doc.id,
Expand All @@ -2568,7 +2582,11 @@ export class OverleafClient {
text: change.text,
author: describeAuthor(change.userId, users),
...(change.timestamp ? { timestamp: change.timestamp } : {}),
...(contextLines > 0 ? { context: this.buildCommentContext(visibleContent, location.line, contextLines) } : {})
...(contextLines > 0 ? { context: this.buildCommentContext(visibleContent, location.line, contextLines) } : {}),
...(surroundingChars > 0 ? {
before: visibleContent.slice(Math.max(0, change.position - surroundingChars), change.position),
after: visibleContent.slice(end, end + surroundingChars)
} : {})
});
}
}
Expand Down
23 changes: 23 additions & 0 deletions test/tracked-changes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ test('listReview returns comments and tracked changes from one pass with locatio
]);
});

test('surroundingChars returns the visible text around each change, and nothing by default', async () => {
const client: any = new OverleafClient({ cookies: { session: 's' }, csrf: 'c' });
client.getProjectInfo = async () => ({ rootFolder: [{ docs: [{ _id: 'd1', name: 'main.tex' }, { _id: 'd2', name: 'a.tex' }], folders: [] }] });
client.getCommentThreads = async () => ({});
client.getChangesUsers = async () => [];
client.openProjectSocket = async () => ({});
client.closeProjectSocket = async () => {};
client.joinDocument = async (_s: object, docId: string) => docId === 'd1'
? { docId, content: 'line one\nfoo quux baz', lines: [], version: 3, type: 'sharejs-text-ot',
ranges: { changes: [{ id: 'c1', op: { i: 'quux', p: 13 }, metadata: {} }, { id: 'c2', op: { d: 'gone', p: 4 }, metadata: {} }] } }
: { docId, content: 'x', lines: ['x'], version: 1, type: 'history-ot',
ranges: { content: 'xyz', trackedChanges: [{ range: { pos: 1, length: 1 }, tracking: { type: 'delete', userId: 'u9' } }] } };

const around = (await client.listReview('p', { surroundingChars: 5 })).changes.map((c: any) => [c.path, c.text, c.before, c.after]);
assert.deepEqual(around, [
['a.tex', 'y', 'x', 'z'],
['main.tex', 'gone', 'line', ' one\n'],
['main.tex', 'quux', '\nfoo ', ' baz']
]);
const plain = (await client.listTrackedChanges('p')).map((c: any) => [c.before, c.after]);
assert.deepEqual(plain, [[undefined, undefined], [undefined, undefined], [undefined, undefined]]);
});

test('normalizeJoinedDocument decodes UTF-8 in tracked change texts', () => {
const client: any = new OverleafClient({ cookies: {}, csrf: 'c' });
const enc = (s: string) => Buffer.from(s, 'utf-8').toString('binary');
Expand Down
Loading