Download tasks/contract-version-restore-comments/environment/app/docs/development.md from VettoAI/terminal-tasks-open: direct link, hf CLI and curl.
- Browser
- Download file 5.95 kB
-
https://huggingface.co/datasets/VettoAI/terminal-tasks-open/resolve/main/tasks/contract-version-restore-comments/environment/app/docs/development.md
- Command line
-
hf download hf://datasets/VettoAI/terminal-tasks-open/tasks/contract-version-restore-comments/environment/app/docs/development.md
-
curl -L -o development.md https://huggingface.co/datasets/VettoAI/terminal-tasks-open/resolve/main/tasks/contract-version-restore-comments/environment/app/docs/development.md
Collaboration development
Ewan Bell, collaboration maintainer
Run npm run db:start from the project root to start the local Postgres 16 cluster, then npm start in packages/collab-server. The server listens on port 1234; PORT selects another port. DATABASE_URL defaults to postgres://contracts:contracts-local@127.0.0.1:5432/contracts. The contracts role owns this application's database. npm run db:shell opens it with psql.
The contract room opens at http://127.0.0.1:5173 through npm run dev. Enter a contract ID and use Open to switch rooms. The version panel chooses a historical row; ordinary editor selections can be reviewed with Comment on selection. These controls use the same restore and comment integrations as the Node clients. Its history panel calls the promise-returning restoreVersion(provider, versionId) in packages/editor/src/versions/restoreVersion.ts. Providers use the contract ID as their document name. The HTTP integration uses CONTRACT_HTTP_URL, independently of a provider's WebSocket address; its default is http://127.0.0.1:1234. The browser can set globalThis.CONTRACT_HTTP_URL.
GET /contracts/:contractId/versions lists versions, and GET /contracts/:contractId/versions/:versionId returns either {kind: 'snapshot', snapshot: '<base64>'} or {kind: 'json', json: <Tiptap document>}. The comments collection at /contracts/:contractId/comments supports GET and POST. The editor package exposes createComment for both the UI and Node integrations. It sends the quote and two encoded Yjs relative positions: the start uses assoc 0 and the end boundary uses assoc -1. Its context payload carries base64 ydoc, start_pos and end_pos values. The update is Y.encodeStateAsUpdate of the selecting client's local document; the endpoints are the original Y.encodeRelativePosition values from that selection. The POST route stores this review revision in comment_contexts, keyed by comment ID, alongside the comment. These legal-review records are retained intact. The live comment row holds display anchors, which can change as a review progresses.
resolveCommentRange(ydoc, comment) takes an actual Postgres comment row, including its byte buffers, and returns finite zero-based half-open character offsets inside the clause text, without node wrappers. Equal endpoints mean detached. The comment UI uses forward association at the start (assoc: 0) and backward association at the end (assoc: -1). These live half-open ranges track insertions and deletions, including in text returned by a version choice. Deleting endpoint characters leaves a nonempty remaining selection attached; deleting the whole span detaches it. The archived original selection is a review record, separate from the current highlight.
The history integration calls restoreVersion with a connected HocuspocusProvider, retains its promise while held traffic is released, and then waits for completion and synchronization. Local state at the instant of that call is the view the user is acting on.
The provider connection and its local Y.Doc have separate lifecycles. An editor keeps its document when its transport disconnects, including unsent local edits. Reconnecting the provider synchronizes that retained document with the server; it does not replace the editor's local document. A receiving editor can lag behind while its own outgoing edits reach colleagues. Backspace and amount corrections entered in that local view are ordinary edits to the writer's note, including when colleagues have already brought it into a chosen version. Closing a room ends that provider's lifecycle. Reopening the contract creates a fresh provider and loads the persisted text and live review positions, including edits to text returned by a version choice. Posting a comment on that edited text archives the selecting browser's actual document and endpoints. Provider document names remain the contract IDs across reconnects and fresh room openings.
npm run test:browser runs the Playwright room tests. The smoke in tests/browser/contract-room.spec.ts covers opening, typing and commenting on selected text. The payment-review regression in tests/browser/version-review.spec.ts chooses the C-1001 snapshot, edits the returned phrase and comments on the edited selection. In tests/browser/reconnecting-reviewer.spec.ts, a browser reviewer chooses that snapshot while a colleague's retained Node provider is disconnected. The colleague reconnects through the development relay and corrects a finance note before receiving the chosen document, then reconnects again from the refreshed view. Start Postgres first. playwright.config.ts starts the collaboration server and editor dev server when needed. Chromium is installed with Playwright in the development image; CHROMIUM_EXECUTABLE_PATH selects its executable. Separate browser contexts provide independent reviewer sessions.
The shared fragment is named default. Clauses have a clauseId attribute and one paragraph of unmarked text; clause order and count are fixed. Active Yjs documents use gc: false so history remains available. The restore and comment modules also run in Node without a DOM. npm test runs the editor's Vitest tests. npm run relay:example demonstrates holding and releasing provider traffic with the WebSocket relay in tools/relay during local development. Use a relay instance per provider connection; releaseOne(direction, index) forwards a single queued message. holdDocumentUpdates(direction) queues sync-step-2 and document-update frames while state vectors, awareness and connection control continue through. A receiving editor can stay behind while its outgoing typing reaches colleagues. release(direction) drains either kind of hold. The relay's events record received and delivered traffic with a documentUpdate flag, and pending(direction) reports a direction's queued messages.