Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
ccccea0
Static sheet: HTML renderer with tag-level self-check (4.8)
firegiant9000 Nov 18, 2026
b2a8848
Static sheet: quote-aware tag and attribute scan in Validate (4.8)
firegiant9000 Nov 18, 2026
62975f2
Static sheet: hand-written HTML tokenizer for Validate (4.8)
firegiant9000 Nov 18, 2026
f0e4e2a
Static sheet: html-sheet export target and Save filter (4.8)
firegiant9000 Nov 18, 2026
1230855
Static sheet: scan the raw text of session notes too (4.8)
firegiant9000 Nov 18, 2026
2d1985e
Test: encoded-path note refusal no longer matches through the profile…
firegiant9000 Nov 18, 2026
35eab52
Static sheet: export panel offers the phone or tablet sheet (4.8)
firegiant9000 Nov 18, 2026
f94594d
Static sheet: axe runs on the generated page in light and dark (4.8)
firegiant9000 Nov 18, 2026
308913c
Static sheet: feature page, D105, changelog (4.8)
firegiant9000 Nov 18, 2026
6ffd034
Static sheet docs: credit the Save filter test to HostServicesTests
firegiant9000 Nov 18, 2026
03aa1fc
Export panel: drop a preview reply that no longer matches the selection
firegiant9000 Nov 18, 2026
653fd24
HTML sheet: show negative spent as zero; encode every string in the e…
firegiant9000 Nov 18, 2026
c5661ba
Export preview: read the character once
firegiant9000 Nov 18, 2026
425fa94
Docs: D105 history entry, sheet has no links; rename export test title
firegiant9000 Nov 18, 2026
1e6b723
a11y: static sheet test checks the page is real and the colour scheme…
firegiant9000 Nov 18, 2026
a8fa57f
Merge remote-tracking branch 'origin/main' into w4-static-sheet
firegiant9000 Nov 19, 2026
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 docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

### Added
- **Sheet for a phone or tablet (D105, Wave 4 item 4.8):** More, Export, "Export to another tool or device" now offers "Sheet for a phone or tablet (HTML page, no internet needed)". It writes one `.tomestack-sheet.html` file that opens in any browser, with no script and no network: the core numbers, abilities, skills, attacks, spells (with slots as checkboxes), resources, features, notices and, in a personal copy only, your session notes. Ticks on the phone are not saved: reopening the file starts from the export. A share copy goes through the same preview and licence filter as the other exports. The sheet export model v1 is unchanged. [features/static-session-sheet.md](features/static-session-sheet.md).
- **Development only, test load caps and a gate script:** local test runs no longer use every core. Vitest runs at most 8 workers (override with `TOMESTACK_TEST_WORKERS`), and xUnit runs at most 8 threads per test project on machines with more than 8 cores; CI keeps its defaults. `scripts/gate.ps1` runs gate steps 1–8 in order, with per-step logs, a summary, a watchdog for a hung e2e or a11y run, DevHost cleanup, an optional lower priority and a CPU check. No app change.
- **Accessibility check in CI, two contrast fixes:** `npm run test:a11y` runs axe, colour contrast included, in the installed Edge against the DevHost, in light and dark, over home, each builder step and each sheet tab, plus home in each named theme. Serious and critical violations fail it, and it now runs in CI. It found two low-contrast spots, both fixed without changing any colour: the "Offline" tag in the header now sits on the page colour, and in the dark theme the sheet's status-bar buttons (Hit points, Armor Class, Initiative, Speed) now sit on the page colour instead of the browser's grey button face.
- **Tests only:** the UI flow tests in `src/Ui/e2e/` are split by feature (the 69 tests of `flow.e2e.tsx` into eight files, the 13 of `forms.e2e.tsx` into two, shared helpers in `helpers.tsx`); no test changed and no file is over 800 lines. The e2e files now run one after another against the shared DevHost. No app change.
Expand Down
2 changes: 2 additions & 0 deletions docs/LIVING_SPECS.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ Create `CHANGELOG.md` with `## Unreleased` and subsections `Added`, `Changed`, `
| D102 | Wave 4 row 4.4: first paint budget in the smoke run? | **Decided (owner ruling, 2026-11-12):** the smoke ready time (process start to the end of the in-app smoke script, the report's `processStartToReadyMs`; an upper bound on first paint) over 15 s locally or 45 s in CI (`CI=true`; raised from 30 s by owner ruling 2026-11-14 after a 36,010 ms hosted run) fails the smoke (`scripts/ready-budget.ps1`, called by `scripts/smoke.ps1`; `-MaxReadyMs` overrides, a negative value skips). Older builds without the field are not checked, but a plain smoke run passes `-Require`, so a current build that omits it fails. [performance.md](performance.md#smoke-ready-time-budget) | Decided; built (4.4b) |
| D103 | Save for an older TomeStack: previous minor only (row 4.5)? | **Decided (owner ruling R4, 2026-11-11; 2026-11-13 rulings):** "Save for an older TomeStack" offers only the previous minor, 0.8.0 from 0.9.0. A build never lists its own minor, so a 0.8.1 build lists none until the 0.9.0 row is added. The 0.7.0, 0.6.0 and 0.5.0 rows stay in the release ladder for re-pin and "opens in", and their lowering steps stay in `RulesCore`; their goldens and outcomes are deleted. The picker says "Only the version before this one is listed. To open the file in an older TomeStack, update that TomeStack first." The real-build proof is the previous minor's: `for-0.8.0/` opened by the real v0.8.0 build (`outcomes/0.8.0.json`, 5 pass), run by the weekly job. [package-format.md](features/package-format.md#save-for-an-older-tomestack-d85) | Decided; built (4.5) |
| D104 | Content revisions insert-only in the database? | **Decided (owner rulings, 2026-11-17, Wave 4 item 4.7):** database migration 13 makes `content_revisions` insert-only in the database. A BEFORE UPDATE and a BEFORE DELETE trigger on every row (drafts too) abort with "content revisions are insert-only". There is no runtime exception: the ADR-003 v2 rewrite, the one sanctioned rewrite of published revisions, always runs at migration 2, before 13. A future rewrite migration must drop and re-create the triggers inside its own migration. **Pre-upgrade copies** are named `tomestack.db.v<version>-<yyyyMMddTHHmmssZ>.bak` (UTC), for example `tomestack.db.v12-20261117T090503Z.bak`. The newest 3 are kept across versions; older `tomestack.db.v<N>.bak` copies count and are removed first. App-version copies `tomestack.db.app-*.bak` are unchanged. The migration is forward-only: older builds (0.8.x and earlier) refuse a database-13 folder, and restoring the copy is the way back. | Decided; built (Wave 4 4.7) |
| D105 | A static session sheet for a phone or tablet? | **Decided (owner rulings, 2026-11-18, Wave 4 item 4.8):** a new export target `html-sheet` writes one HTML file (`<name>.tomestack-sheet.html`, adapter 1.0.0) with no script and no external resource. A tag-level self-check (`HtmlSheet.Validate`) refuses scripts, event attributes, `src`, links that are not `#`, `style` attributes, embedding tags, `@import` and `url(`; a Content-Security-Policy meta tag is only a backstop, because many phone viewers ignore it. Every text is HTML-encoded, and the local-path and user-name scan covers the HTML, the sheet JSON and the raw note text. Pools, spell slots, death saves and hit dice are native checkboxes: ticks are not saved, and reopening the file starts from the export. Death saves are pre-ticked from play state. Session notes are included only in a personal copy; a share copy leaves them out and is preflighted as for the other targets. The trigger is the export panel only (More, Export). The sheet export model v1 is unchanged. | Decided; built (Wave 4 4.8) |

## Change history

- **2026-11-18 · Static session sheet (D105, Wave 4 row 4.8):** a new export target, `html-sheet`, writes one script-free HTML page of the sheet for a phone or tablet: no network, no links, a Content-Security-Policy that allows only its one hashed style, and plain tick boxes that are not saved. A personal copy may include session notes; a share copy never does. It only reads the sheet export model v1. Details in `docs/features/static-session-sheet.md`. No character, package format, database or dependency change.
- **2026-11-17 · Wave 4 item 4.7: database migration v13 (D104):** `content_revisions` is insert-only in the database (BEFORE UPDATE and BEFORE DELETE triggers on every row, drafts too). The pre-upgrade copies are named `tomestack.db.v<N>-<UTC time>.bak` and the newest 3 are kept. Older builds refuse the database-13 folder. No character, content or package format change.
- **2026-11-14 · Smoke ready-time budget in CI 45 s (D102):** the CI budget goes from 30 s to 45 s (owner ruling 2026-11-14); main 43600fc5 failed only on a 36,010 ms ready time and the next run passed. The local budget stays 15 s. `scripts/ready-budget.ps1`. No character, package format, database or dependency change.
- **2026-11-13 · Save for an older TomeStack: previous minor only (D103, Wave 4 row 4.5):** the save offers only the previous minor, 0.8.0 from 0.9.0 (owner ruling R4). The 0.7.0, 0.6.0 and 0.5.0 rows stay in the ladder for re-pin and "opens in"; their lowering steps stay in `RulesCore`, and their goldens and outcomes are deleted. The real-build proof is v0.8.0 (`outcomes/0.8.0.json`, 5 pass). No character, package format, database or dependency change.
Expand Down
1 change: 1 addition & 0 deletions docs/features/export-adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ BACKLOG B20 · ROADMAP M6 slice 4 · [ADR-012](../decisions/ADR-012-export-adapt
| --- | --- | --- | --- |
| Foundry VTT, dnd5e system (`foundry-dnd5e`) | `<name>.foundry-dnd5e.json`: one Actor document for "Import Data" on an actor | 1.0.0 | **Foundry core 14.367 with dnd5e 6.0.6** (the pinned pair; dnd5e 6.0.6, released 2026-10-06, declares compatibility minimum 14.367, verified 14) |
| TomeStack sheet (`sheet-json`) | `<name>.tomestack-sheet.json`: the sheet export model v1 itself | 1.0.0 | `docs/schemas/sheet-export.v1.schema.json` |
| Static session sheet (`html-sheet`) | `<name>.tomestack-sheet.html`: one script-free HTML page for a phone or tablet ([static-session-sheet.md](static-session-sheet.md)) | 1.0.0 | Its own tag-level check and golden file |
| Roll20 | none | none | **Deferred** (owner decision D14): no documented, supported import file for its official 5e sheets. The neutral JSON is what any tool can read |

**How the pin was verified (2026-09-29; moved to 6.0.6 on 2026-11-11).** The dnd5e data models at tag `release-6.0.6` of `github.com/foundryvtt/dnd5e`: `module/data/actor/character.mjs`, `templates/common.mjs`, `creature.mjs` and `attributes.mjs`; the item models `class.mjs`, `subclass.mjs`, `feat.mjs`, `spell.mjs` and `weapon.mjs`; `templates/item-description.mjs` and `activities.mjs`; `shared/damage-field.mjs` and `uses-field.mjs`; and `system.json` for the compatibility pair. They were read in full on 2026-09-29 for the previous pin; for `release-6.0.6` the two tags were diffed instead, and the only change in these files is a private migration path for skill and tool check bonuses in `templates/common.mjs`, which the adapter never writes. Each data model has a `_migrateData` step that Foundry runs when it builds a document from its source, and `system.json` names 6.0.0 as `needsMigrationVersion`: a document stamped with an older system version is migrated on load, so one pin stays importable while the system keeps those migrations. The file is stamped `_stats.systemVersion` 6.0.6 and `coreVersion` 14.367. The weekly workflow (`.github/workflows/weekly.yml`, `scripts/foundry-pin.mjs`) compares these files and the compatibility block with the latest dnd5e release and opens or updates one "Foundry dnd5e pin drift" issue when they differ; `FoundryPinDocTests` keeps this page's versions equal to the constants in `FoundryDnd5e.cs`.
Expand Down
46 changes: 46 additions & 0 deletions docs/features/static-session-sheet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Static session sheet (D105)

Wave 4 item 4.8 · decision [D105](../LIVING_SPECS.md) · status: **built; the owner's check on a real phone is not recorded yet.**

A sheet for the table when you would rather not carry a laptop. It is one HTML file you send to a phone or tablet and open in the browser. It needs no internet, no app and no TomeStack. It is a second target of the export adapters ([export-adapters.md](export-adapters.md)); the printable sheet (Print… on the character sheet) stays the full backup.

## Making one

1. Open a character, then **More**, **Export**.
2. Under "Export to another tool or device", choose **Sheet for a phone or tablet (HTML page, no internet needed)**.
3. Choose the purpose, as for the other formats:
- **Share** keeps only totals from content that may not be shared, and leaves out your session notes.
- **Personal copy** includes your own homebrew and your session notes, and is labelled "Do not share it".
4. Read the preview and save. The Save dialog offers "HTML page". The file is named `<name>.tomestack-sheet.html`.

A share copy goes through the same preflight as the other exports. The preview adds two warnings: "Includes N session notes." (personal copy) and "Ticks on the phone are not saved: reopening the file starts from this export."

## What is in the file

A header (name, classes, level, rules family, export date and the purpose label); Armor Class, initiative and proficiency bonus; hit points printed, with two empty write-in fields; abilities and saves; skills; conditions and exhaustion; death saves (pre-ticked from the play state); weapon attacks; spellcasting, with slots as checkboxes and each spell in a collapsible block; resources (up to 20 uses as checkboxes, more as a write-in field, and "no fixed maximum" as text); hit dice; toggles as read-only text; class columns; features in collapsible blocks; session notes (personal copy only); and the sources, licence notices and what was left out.

It follows the phone's light or dark setting. Printing it shows summaries only.

## What it does not do

- **Ticks are not saved.** They are plain checkboxes. Close the page or reload it and everything goes back to the export. Nothing writes back to TomeStack.
- **No script, no network.** The page loads nothing from anywhere and has no links at all.
- It does not recalculate. Change the character in TomeStack and export again.
- The sheet export model v1 is unchanged; this target only reads it.

## Safety rules

1. **Every text is HTML-encoded**, including homebrew names and descriptions and your notes.
2. **A tag-level self-check** (`HtmlSheet.Validate`, a small hand-written tokenizer) runs on the finished page before anything is written. It refuses scripts, event attributes, `src`, any link that is not `#...`, `style` attributes, embedding tags (frames, objects and the like), `@import` and `url(`. A failure is `export.invalid-output`, as for the other adapters.
3. **A Content-Security-Policy meta tag** blocks everything except the page's own style block (matched by hash). It is a backstop only: many phone viewers ignore it, so the self-check is the real guard.
4. **The privacy scan** that every export gets (data folder, profile, linked PDFs, the Windows user name as a path segment) covers the HTML, the sheet JSON it came from and the raw note text.

## Tests

- `tests/AppService.Tests/HtmlSheetTests.cs`: the content of each section, encoding of hostile text, and the self-check refusing each forbidden construct.
- `tests/AppService.Tests/ExportAdapterTests.cs`: the golden file `Golden/multiclass-caster.tomestack-sheet.html` (open it in any browser to see the result), notes only in a personal copy, and a local path refused.
- `tests/AppService.Tests/HostServicesTests.cs`: the Save dialog filter ("HTML page", `.html`).
- `src/Ui/src/components/VttExportPanel.test.tsx`: the choice in the export panel.
- `src/Ui/a11y/static-sheet.a11y.tsx`: axe in Edge, light and dark.

**Not verified:** opening the file on a real phone or tablet, and a Narrator or screen-reader pass.
4 changes: 3 additions & 1 deletion src/AppService/CommandDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,9 @@ private SaveOutcome SaveVttExportAs(ExtensionTokenPayload payload)
if (host is null)
throw new AppValidationException([new("host.unsupported", "This host has no native Save dialog.")], "unsupported");
var (fileName, bytes) = app.PeekVttExport(payload.Token);
var outcome = SaveBytes(fileName, bytes, "Export file", ".json");
var outcome = fileName.EndsWith(".html", StringComparison.OrdinalIgnoreCase)
? SaveBytes(fileName, bytes, "HTML page", ".html")
: SaveBytes(fileName, bytes, "Export file", ".json");
if (outcome.Saved)
app.CompleteVttExport(payload.Token);
return outcome;
Expand Down
27 changes: 24 additions & 3 deletions src/AppService/Exports/ExportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace TomeStack.AppService
/// </summary>
public sealed partial class TomeStackApp
{
public static IReadOnlyList<string> ExportTargets { get; } = [FoundryDnd5e.Target, SheetJson.Target];
public static IReadOnlyList<string> ExportTargets { get; } = [FoundryDnd5e.Target, SheetJson.Target, HtmlSheet.Target];

/// <summary>
/// Export files are indented, and readable: HTML in a description is written as it is, not as < escapes. The
Expand All @@ -88,13 +88,16 @@ public VttExportPreview PreviewVttExport(Guid characterId, string target, SheetP
{
if (!ExportTargets.Contains(target))
throw new AppValidationException([new("export.target-unknown", $"'{(target?.Length > 40 ? target[..40] : target)}' is not an export target this TomeStack has ({string.Join(", ", ExportTargets)}).")]);
var sheet = SheetExportFor(characterId, purpose);
var character = LoadCharacter(characterId);
var sheet = SheetExportFor(character, purpose);
string text;
string fileName;
string adapterVersion;
string? targetVersion;
IReadOnlyList<string> differences = [];
var baseName = SafeName(sheet.Character.Name);
var htmlNotes = 0;
string? rawNotes = null;
if (target == FoundryDnd5e.Target)
{
var actor = FoundryDnd5e.Map(sheet);
Expand All @@ -105,6 +108,17 @@ public VttExportPreview PreviewVttExport(Guid characterId, string target, SheetP
(adapterVersion, targetVersion) = (FoundryDnd5e.AdapterVersion, $"Foundry VTT {FoundryDnd5e.CoreVersion} with dnd5e {FoundryDnd5e.SystemVersion}");
differences = FoundryDifferences(sheet);
}
else if (target == HtmlSheet.Target)
{
htmlNotes = purpose == SheetPurpose.Personal ? character.Notes.Count : 0;
if (htmlNotes > 0)
rawNotes = string.Join("\n", character.Notes.Select(n => n.Text));
text = HtmlSheet.Render(sheet, new(purpose == SheetPurpose.Personal ? character.Notes : [], character.Play.DeathSaves));
if (HtmlSheet.Validate(text) is { Count: > 0 } problems)
throw new AppValidationException([new("export.invalid-output", $"The HTML sheet would not be safe to open ({problems[0]}), so nothing was written.")]);
fileName = baseName + HtmlSheet.FileSuffix;
(adapterVersion, targetVersion) = (HtmlSheet.AdapterVersion, "HTML page, no script");
}
else
{
var node = SheetJson.Map(sheet);
Expand All @@ -117,7 +131,10 @@ public VttExportPreview PreviewVttExport(Guid characterId, string target, SheetP
// The model is an allowlist with no path field; the scan is the second line (ADR-012 "Privacy"). The Foundry file
// holds HTML-encoded text (an accented or quoted name is written as an entity), so the sheet it came from, whose
// strings are the same but not encoded, is scanned too (review fix).
var scanned = target == FoundryDnd5e.Target ? [text, SheetJson.Map(sheet).ToJsonString(FileJson)] : new[] { text };
var scanned = target == FoundryDnd5e.Target || target == HtmlSheet.Target ? [text, SheetJson.Map(sheet).ToJsonString(FileJson)] : new[] { text };
// The HTML sheet also encodes its session notes, which the sheet model does not hold: scan their raw text too.
if (rawNotes is not null)
scanned = [.. scanned, rawNotes];
if (scanned.Any(t => OutputScan.Leaks(t, SensitivePaths(), [ScanIdentity().UserName])))
throw new AppValidationException([new("export.output-refused", "The file would contain a local path or your Windows user name, so nothing was written.")]);
var bytes = Encoding.UTF8.GetBytes(text);
Expand All @@ -129,6 +146,10 @@ public VttExportPreview PreviewVttExport(Guid characterId, string target, SheetP
warnings.Add(new("export.personal", "Personal copy: includes your own homebrew. Do not share it."));
if (target == FoundryDnd5e.Target)
warnings.Add(new("export.experimental", "Experimental: the Foundry file is checked against the dnd5e data model, but no import into a real Foundry world has been recorded yet."));
if (htmlNotes > 0)
warnings.Add(new("export.html-notes", htmlNotes == 1 ? "Includes 1 session note." : $"Includes {htmlNotes} session notes."));
if (target == HtmlSheet.Target)
warnings.Add(new("export.html-static", "Ticks on the phone are not saved: reopening the file starts from this export."));
return new(token, target, fileName, bytes.LongLength, adapterVersion, targetVersion, purpose, sheet.Dropped, sheet.Notices, differences, warnings);
}

Expand Down
Loading