Sync notes from dragonroll to foundry #98

Closed
opened 2026-10-15 22:49:15 +00:00 by Syndria98 · 15 comments
Owner

Make that each dragonroll is a page in foundry of the same journal called Dragonroll. Make it also sync

Make that each dragonroll is a page in foundry of the same journal called Dragonroll. Make it also sync
Syndria98 added the ai-ready label 2026-10-15 22:49:15 +00:00
Agent added the working label 2026-10-15 22:53:05 +00:00
Collaborator

Now let me read the backend sync route:

Now let me read the backend sync route:
Collaborator

Now let me look at the Note model, the note routes, and the existing tests:

Now let me look at the Note model, the note routes, and the existing tests:
Collaborator

Now let me look at the backend index.js, note.js rest, and check the docs for foundry content:

Now let me look at the backend index.js, note.js rest, and check the docs for foundry content:
Collaborator

I have the full picture now. Let me implement. Starting with the backend model and sync routes:

I have the full picture now. Let me implement. Starting with the backend model and sync routes:
Collaborator

Now add the two note endpoints to foundry-link.js:

Now add the two note endpoints to `foundry-link.js`:
Collaborator

Now the Foundry module. I'll add the notes sync section between the character sync and the bridge publishing:

Now the Foundry module. I'll add the notes sync section between the character sync and the bridge publishing:
Collaborator

Now update the existing test harnesses that load foundry-link.js so they stub the new Note model require:

Now update the existing test harnesses that load `foundry-link.js` so they stub the new `Note` model require:
Collaborator

Now the new test file:

Now the new test file:
Collaborator

Let me fix a shared-state hazard in the test fixtures (the map-note fetch stub mutates note objects, so shared constants would leak state between tests):

Let me fix a shared-state hazard in the test fixtures (the map-note fetch stub mutates note objects, so shared constants would leak state between tests):
Collaborator

Now let's run the full test suite:

Now let's run the full test suite:
Collaborator

Two fixes needed. Let me look at the force-import harness and fix both:

Two fixes needed. Let me look at the force-import harness and fix both:
Collaborator

The repo is squashed, but a version bump for a new module feature follows Foundry convention. Now the documentation updates — module README, user docs, and AGENTS.md:

The repo is squashed, but a version bump for a new module feature follows Foundry convention. Now the documentation updates — module README, user docs, and AGENTS.md:
Collaborator

All tests pass. Let me do a final review of the complete diff:

All tests pass. Let me do a final review of the complete diff:
Collaborator

Implemented issue #98: every Dragonroll note now stands as a page of one Foundry journal called Dragonroll, kept in sync. All 361 tests pass (12 of them new).

How it works — it follows the existing character/item sync patterns end to end:

  • Backend (backend/src/routes/foundry-link.js, backend/src/models/Note.js)

    • GET /api/foundry/sync/notes answers with every note of the campaign — title, markdown content, and the foundryPageId it already stands as.
    • POST /api/foundry/sync/map-note records the page the module created for a note (world-checked, campaign-scoped, refuses a page already mapped to another note, like map-item).
    • Note gained foundryPageId with the same campaign-scoped partial unique index foundryItemId/foundryFolderId use.
  • Foundry module (dragonroll-foundry/scripts/api.js, v0.5.0)

    • A reconcileDragonrollNotes() loop reads the campaign's notes every 5 s (same rhythm as the characters/items reconcile, gated by the sync token and the Auto-sync setting) and writes each note as a page of one JournalEntry named Dragonroll — creating the journal, or adopting and flagging one the GM already made under that name.
    • Note markdown becomes page HTML through Foundry's own renderer (TextEditor._getMarkdown), with escaped paragraphs as a fallback.
    • Pages carry the note's id in a dragonroll-foundry.noteId flag: editing a note rewrites its page, deleting one drops the page, and the GM's own pages in that journal are never touched. A page mapped by foundryPageId but whose flag was lost is claimed instead of doubled. Pages already in step are not rewritten. The copy runs one way — notes are written in Dragonroll — so nothing in the journal travels back.
  • Tests (tests/foundry-note-journal.test.js): the backend pairing routes, and the module side in the usual node:vm stubbed-Foundry harness — journal creation/adoption, rendering, edit/delete propagation, no-rewrite churn, orphan-page claiming, fallback renderer, and autosync-off. The three existing harnesses that load foundry-link.js gained the one-line Note model stub.

  • Docs: the Foundry docs page's "What syncs" table plus a one-way-sync paragraph, the module README's routes table and a "Notes" section, and the AGENTS.md sync rules.

Implemented issue #98: **every Dragonroll note now stands as a page of one Foundry journal called Dragonroll, kept in sync**. All 361 tests pass (12 of them new). **How it works** — it follows the existing character/item sync patterns end to end: - **Backend** (`backend/src/routes/foundry-link.js`, `backend/src/models/Note.js`) - `GET /api/foundry/sync/notes` answers with every note of the campaign — title, markdown content, and the `foundryPageId` it already stands as. - `POST /api/foundry/sync/map-note` records the page the module created for a note (world-checked, campaign-scoped, refuses a page already mapped to another note, like `map-item`). - `Note` gained `foundryPageId` with the same campaign-scoped partial unique index `foundryItemId`/`foundryFolderId` use. - **Foundry module** (`dragonroll-foundry/scripts/api.js`, v0.5.0) - A `reconcileDragonrollNotes()` loop reads the campaign's notes every 5 s (same rhythm as the characters/items reconcile, gated by the sync token and the Auto-sync setting) and writes each note as a page of one `JournalEntry` named **Dragonroll** — creating the journal, or adopting and flagging one the GM already made under that name. - Note markdown becomes page HTML through Foundry's own renderer (`TextEditor._getMarkdown`), with escaped paragraphs as a fallback. - Pages carry the note's id in a `dragonroll-foundry.noteId` flag: editing a note rewrites its page, deleting one drops the page, and the GM's own pages in that journal are never touched. A page mapped by `foundryPageId` but whose flag was lost is claimed instead of doubled. Pages already in step are not rewritten. The copy runs one way — notes are written in Dragonroll — so nothing in the journal travels back. - **Tests** (`tests/foundry-note-journal.test.js`): the backend pairing routes, and the module side in the usual `node:vm` stubbed-Foundry harness — journal creation/adoption, rendering, edit/delete propagation, no-rewrite churn, orphan-page claiming, fallback renderer, and autosync-off. The three existing harnesses that load `foundry-link.js` gained the one-line `Note` model stub. - **Docs**: the Foundry docs page's "What syncs" table plus a one-way-sync paragraph, the module README's routes table and a "Notes" section, and the AGENTS.md sync rules.
Collaborator

Implementation is ready for review: #103

Implementation is ready for review: https://git.aranroig.com/Syndria98/dragonroll/pulls/103
Agent added help wanted and removed working labels 2026-10-15 23:19:43 +00:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Syndria98/dragonroll#98