Skip to content
Open
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
66 changes: 66 additions & 0 deletions collaborative-editor-governance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Collaborative Editor Governance

Self-contained collaborative research editor governance milestone for [SCIBASE.AI issue #12](https://github.com/SCIBASE-AI/SCIBASE.AI/issues/12).

The issue asks for a real-time collaborative research editor. This module focuses on a reviewable core for deterministic operation replay and editorial governance: typed scientific blocks, locks, comments, suggestions, tasks, snapshots, collaborator presence, and publication outline export.

## What It Adds

- Scientific document blocks with Markdown, LaTeX, code metadata, references, and section headings.
- Deterministic operation handling for block inserts, updates, deletes, comments, suggestions, and tasks.
- Section-lock enforcement that rejects edits from non-owners.
- Inline comment and suggestion state for peer review.
- Autosave/version snapshot with content hash and open review counts.
- Open-task dashboard and collaborator presence summary.
- Scientific formatting summary covering LaTeX, code highlighting, notebook blocks, reference-provider metadata, citation resolution, and publication templates.
- Offline collaboration conflict report for queued client operations, stale block versions, section-lock conflicts, missing review targets, safe suggestion conversion, restore snapshots, and audit hashes.
- Publication outline export with section block types, word counts, and export hash.
- Sample document fixture, tests, requirement map, CLI demo, and short demo GIF.

## Run

```bash
cd collaborative-editor-governance
npm run check
npm test
npm run demo
```

Expected demo shape:

```json
{
"title": "Longitudinal microbiome shifts after coastal flooding",
"acceptedOperations": 3,
"rejectedOperations": 1,
"readyForSubmission": false,
"formatting": {
"supportsLatex": true,
"referenceManager": {
"providers": ["zotero"],
"unresolvedCitations": []
}
},
"offlineConflicts": {
"queueCount": 1,
"conflictCodes": ["REVIEW_TARGET_MISSING", "SECTION_LOCK_CONFLICT", "STALE_BLOCK_VERSION"]
},
"outlineHash": "..."
}
```

## Demo Artifact

See [docs/demo.gif](docs/demo.gif) for a short visual walkthrough. The SVG source is included at [docs/demo.svg](docs/demo.svg).

## Files

- `src/editor-governance.js` - operation replay, locks, snapshots, dashboard, offline conflict resolution, and outline export.
- `data/sample-document.json` - reviewable scientific document fixture.
- `test/editor-governance.test.js` - dependency-free Node tests.
- `scripts/demo.js` - CLI demo.
- `docs/issue-12-requirement-map.md` - maps the implementation to bounty requirements.

## AI-Assisted Disclosure

This contribution was produced with AI assistance and manually verified with the local commands above.
159 changes: 159 additions & 0 deletions collaborative-editor-governance/data/sample-document.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"document": {
"id": "doc-flooding-microbiome",
"title": "Longitudinal microbiome shifts after coastal flooding",
"collaborators": [
{ "id": "u-1", "name": "Principal investigator", "role": "owner" },
{ "id": "u-2", "name": "Methods reviewer", "role": "reviewer" },
{ "id": "u-3", "name": "Data analyst", "role": "editor" }
],
"blocks": [
{
"id": "block-abstract",
"sectionId": "abstract",
"type": "markdown",
"content": "We report longitudinal microbiome shifts after coastal flooding.",
"metadata": { "heading": "Abstract" }
},
{
"id": "block-methods",
"sectionId": "methods",
"type": "markdown",
"content": "Samples were collected monthly and sequenced with a documented protocol @smith2026.",
"metadata": { "heading": "Methods" }
},
{
"id": "block-equation",
"sectionId": "methods",
"type": "latex",
"content": "$H = -\\sum_i p_i \\log(p_i)$",
"metadata": { "label": "eq:diversity" }
},
{
"id": "block-code",
"sectionId": "methods",
"type": "code",
"content": "normalize_counts(samples)",
"metadata": { "language": "python" }
}
],
"comments": [],
"suggestions": [],
"locks": [
{ "sectionId": "methods", "ownerId": "u-2", "status": "active" }
],
"tasks": [
{ "id": "task-1", "title": "Attach data dictionary", "assigneeId": "u-3", "status": "open" }
],
"presence": [
{
"userId": "u-1",
"name": "Principal investigator",
"sectionId": "abstract",
"cursorBlockId": "block-abstract",
"lastSeenAt": "2026-05-14T07:00:00Z"
},
{
"userId": "u-2",
"name": "Methods reviewer",
"sectionId": "methods",
"cursorBlockId": "block-methods",
"lastSeenAt": "2026-05-14T07:00:00Z"
}
],
"references": [
{
"key": "smith2026",
"provider": "zotero",
"title": "Flooding exposure sequencing protocol",
"doi": "10.5555/example"
}
],
"publicationTemplates": [
{
"id": "nature-methods",
"name": "Nature Methods",
"style": "nature",
"requiredSections": ["abstract", "methods", "results", "references"]
}
],
"versions": [],
"offlineQueues": [
{
"clientId": "offline-u-3",
"baseVersionId": "snapshot-draft-1",
"baseContentHash": "draft-base-hash",
"operations": [
{
"type": "update-block",
"actorId": "u-3",
"blockId": "block-abstract",
"baseBlockHash": "stale-abstract-hash",
"content": "We report flood-linked microbiome shifts with a larger validation cohort.",
"rebasedSuggestionId": "suggestion-offline-abstract"
},
{
"type": "update-block",
"actorId": "u-3",
"blockId": "block-methods",
"baseBlockHash": "stale-methods-hash",
"content": "Offline edit should wait because the methods section is locked."
},
{
"type": "comment",
"id": "comment-missing-block",
"actorId": "u-3",
"blockId": "block-removed",
"body": "This comment targets a block that disappeared while offline."
},
{
"type": "insert-block",
"actorId": "u-3",
"index": 4,
"block": {
"id": "block-offline-note",
"sectionId": "discussion",
"type": "markdown",
"content": "Offline reviewer note preserved after reconnect.",
"metadata": { "heading": "Discussion" }
}
}
]
}
]
},
"operations": [
{
"type": "comment",
"id": "comment-1",
"actorId": "u-2",
"blockId": "block-methods",
"body": "Please cite the sequencing protocol and include reagent version."
},
{
"type": "suggestion",
"id": "suggestion-1",
"actorId": "u-2",
"blockId": "block-methods",
"proposedContent": "Samples were collected monthly and sequenced with protocol v2.1."
},
{
"type": "update-block",
"actorId": "u-3",
"blockId": "block-methods",
"content": "This edit should be rejected while the methods section is locked."
},
{
"type": "insert-block",
"actorId": "u-1",
"index": 3,
"block": {
"id": "block-results",
"sectionId": "results",
"type": "markdown",
"content": "Observed diversity increased after flooding and moved toward baseline after remediation.",
"metadata": { "heading": "Results" }
}
}
]
}
Binary file added collaborative-editor-governance/docs/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added collaborative-editor-governance/docs/demo.mp4
Binary file not shown.
34 changes: 34 additions & 0 deletions collaborative-editor-governance/docs/demo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions collaborative-editor-governance/docs/issue-12-requirement-map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Issue #12 Requirement Map

This module is a deterministic milestone for SCIBASE issue #12, Real-time collaborative research editor & interface. It focuses on review governance, operation replay, and offline conflict handling for scientific documents.

| Issue requirement | Implementation |
| --- | --- |
| Scientific document blocks | Blocks include `markdown`, `latex`, `code`, section IDs, headings, language metadata, and publication outline export. |
| Markdown and LaTeX formatting | `buildScientificFormattingSummary()` reports Markdown blocks and LaTeX/equation support from typed blocks and inline equation syntax. |
| Reference manager integration | Document references preserve provider metadata such as Zotero/BibTeX source, cited keys, and unresolved citations. |
| Publication templates | Publication template metadata captures style names and required sections for common journal formats. |
| Code snippet highlighting | Code blocks carry language metadata and are reported in the scientific formatting summary. |
| Real-time operation application | `applyOperation()` and `applyOperationBatch()` deterministically apply insert, update, delete, comment, suggestion, and task operations. |
| Comments and suggestions | Comment and suggestion operations are stored with block links, actor IDs, and open/pending status. |
| Section locks | `isSectionLocked()` rejects edits from non-owners while allowing the lock owner to edit. |
| Offline/local caching conflict recovery | `rebaseOfflineQueue()` and `buildOfflineConflictReport()` process queued offline edits, detect stale block versions, preserve safe edits as suggestions, flag missing review targets, and create restore-ready snapshots. |
| Version history and autosave | `createVersionSnapshot()` records block count, open review items, content hash, and timestamp. |
| Task workflow | Task operations and dashboard open-task reporting support editorial handoff. |
| Collaborator presence | `buildPresenceSummary()` turns presence data into reviewer-ready cursor and staleness state. |
| Publication outline export | `exportPublicationOutline()` summarizes sections, block types, word counts, and export hash. |
| Reviewer demo | `npm run demo` prints accepted/rejected operation counts, snapshot, offline conflict codes, dashboard sections, and outline hash. |

## Verification

```bash
npm run check
npm test
npm run demo
```

The module is dependency-free and isolated under `collaborative-editor-governance/`.
12 changes: 12 additions & 0 deletions collaborative-editor-governance/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "scibase-collaborative-editor-governance",
"version": "0.1.0",
"private": true,
"description": "Deterministic collaborative research editor governance milestone for SCIBASE issue #12.",
"type": "commonjs",
"scripts": {
"check": "node --check src/editor-governance.js && node --check scripts/demo.js && node --check test/editor-governance.test.js",
"demo": "node scripts/demo.js",
"test": "node test/editor-governance.test.js"
}
}
29 changes: 29 additions & 0 deletions collaborative-editor-governance/scripts/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";

const sample = require("../data/sample-document.json");
const { buildCollaborativeEditorPacket } = require("../src/editor-governance");

const packet = buildCollaborativeEditorPacket(sample.document, sample.operations);

console.log(
JSON.stringify(
{
title: packet.document.title,
acceptedOperations: packet.operationResults.filter((result) => result.accepted).length,
rejectedOperations: packet.operationResults.filter((result) => !result.accepted).length,
snapshot: packet.snapshot,
readyForSubmission: packet.dashboard.readyForSubmission,
formatting: packet.formatting,
offlineConflicts: {
queueCount: packet.offlineConflicts.queueCount,
appliedCount: packet.offlineConflicts.appliedCount,
conflictCount: packet.offlineConflicts.conflictCount,
conflictCodes: packet.offlineConflicts.conflictCodes,
},
sections: packet.dashboard.sections,
outlineHash: packet.outline.exportHash,
},
null,
2,
),
);
Loading