Files
final-wishes/OVERVIEW.md
2026-11-30 19:14:14 -05:00

15 KiB
Raw Blame History

Final Wishes — Overview

An encrypted, printable "in the event of my death or incapacity" guide that lives on a thumbdrive as a single self-contained HTML file, so a non-technical executor can open it on any PC or Mac with one passphrase and print it.

Purpose

The owner keeps accounts, documents, contacts, wind-down steps and similar life-admin information in one document that is encrypted at rest. It began as an 8-page 2022 PDF with plaintext secrets (abi-wishes.pdf, never committed). The executor double-clicks final-wishes.html, enters a passphrase, reads the guide in the browser and prints it. The owner edits the same file and saves it back to the drive. There is no server, no install and no network access.

Tech Stack

Layer Technology
Language / runtime Vanilla JavaScript (ES modules in source). Browser for the app, Node 20+ for build and tests.
UI Hand-written DOM code (h() helper, textContent only, no innerHTML), plain CSS with light/dark themes
Crypto WebCrypto: PBKDF2-SHA256 (600,000 iterations) into AES-256-GCM
Build build.js: concatenates src/*.js, no bundler, no dependencies
Tests node --test (built-in runner). Browser behavior was checked by hand with headless Chromium over CDP, which is not part of the repo.
Hosting / issues Gitea (gitea.ericthered.tech), gt CLI. Issues #1–#19 track the work.

There are no npm dependencies and no CDN or network calls at runtime.

Directory Structure

build.js                 builds dist/final-wishes.html (optionally encrypting a JSON file into it)
sanitize.js              `node sanitize.js --in real.html --out copy.html`: re-seals a copy with secrets erased under a new passphrase
bump-version.js          `npm run bump`, and the pre-commit hook's engine: advances src/version.js to today's date + next letter
.githooks/pre-commit     runs `bump-version.js --staged`; enable once per clone with `npm run hooks`
package.json             scripts: build, seal, test
src/
  capture.js             capture-bundle format and merge destinations (pure)
  capture-app.js         the UI of the separate capture.html tool
  crypto.js              encrypt / decrypt / passphrase rules (blob format below)
  model.js               document schema, validate(), section/record/field/sequence kinds
  ops.js                 pure edit helpers: add/move/remove, header, images, sequences, sub-tabs,
                         revert-to-saved (Cancel), delete-section message, clearSecrets
  print.js               pure print helpers: secret masking, header layout, frame rules, secret count
  images.js              image helpers (PNG/JPEG sniffing, sizing, data URLs) + browser import pipeline
  template.js            assemble(): the HTML skeleton shared by build.js and in-page Save
  version.js             APP_VERSION ("Ver YYMMDDX" in the top bar) and bump helpers
  app.js                 the whole UI (start/unlock, view, edit, print, save)
  style.css              screen styles, visual-sequence styles, @media print rules
test/                    one test file per src module, plus a build test
docs/
  thumbdrive/README.txt  executor's one-page instructions (copied to the drive)
PLAN.md                  original plan
HANDOFF.md               notes on open issue #20 (save writes a 0-byte file) and the pending decision on download-by-default
null.html, null.withWorkflow.html   committed sanitized sample copies (secrets erased via `sanitize.js`); null.withWorkflow.html includes a sample capture workflow

Git-ignored on purpose: *.pdf, data/ (plaintext working copies with real secrets), dist/, node_modules/.

Architecture

One file. build.js concatenates the modules (crypto, images, model, ops, print, template, version), strips ^import lines and ^export keywords, appends app.js, and drops the result into the skeleton from src/template.js. All modules therefore share one global scope in the built file, so names must not collide across modules. The skeleton holds <style id="fw-css">, <script id="payload" type="application/octet-stream"> (the encrypted blob), <script id="fw-js"> and an empty <div id="printdoc">. The </script> inside the template literal is written <\/script>.

Encrypted payload. Blob layout: "FW" 0x01 | iterations (u32 big-endian) | salt (16) | IV (12) | ciphertext + GCM tag, with the header bound as additional authenticated data. The plaintext is the JSON document. The passphrase minimum is 12 characters. The passphrase is kept in memory only; the app never uses localStorage.

Document model (src/model.js, schemaVersion 1): meta {owner, title, lastUpdated}; optional header {fields} for the running print header; sections. Section kinds:

  • text (a body, plus optional sequences)
  • records (records with labeled fields; a field is text or an image). It can optionally have sub-tabs: subsections: [{id, title}], a generalTitle for the catch-all first tab (default "General"), and a subsection id on each record or sequence. No subsection, or one that matches no tab, means General.
  • steps and checklist (ordered items)

A visual sequence (kind: 'sequence', numbered frames of image + text with a layout of right / under / none) is an entry in the same ordered list as a section's records or items, or in a text section's sequences array. It is not a record or an item: no step number and no tick box. Ids are unique across the whole document. secret flags exist on fields and frames. Validation is validate() / assertValid(); the save path refuses an invalid document.

UI (src/app.js, a single IIFE): state lives in one state object (including collapsed, the folded record ids). Edits mutate state.doc in place and then call markDirty() or changed(record) (which also stamps updated and meta.lastUpdated). render() rebuilds the page. changed clears state.status, so set the status afterwards.

  • Editing and Cancel: edit mode is global. Cancel reverts the section (or the print header) on screen to a deep-copy baseline taken at open and at each save, then leaves edit mode.

  • Collapsing records: in view mode each record card has a Collapse/Expand button, and records sections have "Collapse all" / "Expand all". Folded ids live in state.collapsed (a Set, view-only, never saved, cleared on reload). A collapsed card shows only its title and gets ↑/↓ buttons that reorder it via move() and changed(), so moving stamps updated and marks the document dirty.

  • Sub-tabs: ops.js holds the pure logic (tabsOf, entriesInTab, moveToTab, moveWithin, removeSubsection, printGroups). The records stay in one array, and the tab bar filters them. The shown tab is in state.tabs (not saved). Up/down moves a record past its nearest neighbour in the same tab. Deleting a tab sends its records to General. Print writes one sub-heading per non-empty tab.

  • Images: drag and drop, clipboard paste and file picker all feed importFiles(). Files are sniffed by their first bytes, downscaled to at most 1600 px and re-encoded, which strips metadata, and stored as data URLs with a limit of about 3 MB each.

  • Walkthroughs (issue #23): a sequence frame may carry ifStuck text and a stop flag, and a sequence a captured date. In Edit, "Capture from screen…" uses getDisplayMedia (startScreenCapture, grabScreenFrame, stopScreenCapture in images.js; the stream lives in a closure variable in app.js, ended when leaving edit mode) and adds frames via addCapture() in ops.js. In view mode state.walk ({id, k}, not saved) shows a sequence one step at a time (walkSequence).

  • Credential references (issue #24): a frame's uses: [{record, field}] points at record fields by id. A field gets an id the first time it is referenced (ensureFieldId, addUse, findFieldRef, allRecordsIn in ops.js). A dangling reference is shown as removed, never a validation error. viewUses and copyValue (30 s clipboard wipe) are in app.js; usesView in print.js does the masked/included print text.

  • Annotation (issue #25): a frame's marks are {type:'marker',x,y} or {type:'box',x,y,w,h} as fractions of the picture (isMark, normRect in images.js). markedImage() in app.js wraps a step's <img> in a .marked box and lays CSS overlays over it, so the same marks work in the list, player, lightbox and print. openAnnotator() is a canvas dialog; Blur out runs pixelateRegion() (pure, in images.js) on the pixels and Apply re-encodes the picture, so no unblurred copy is stored. Marks are dropped when the picture is replaced, removed or erased by clearSecrets.

  • Search (issue #27): src/search.js has the pure searchRanges() (case-insensitive, plain text) and stepSearchIndex(). In app.js a toolbar Search button sets state.searchOpen, which swaps the toolbar's buttons for the search controls (same row); Cancel swaps them back. The controls are a persistent element re-attached on every render() (so the typed text and focus survive). findAllHits() builds a hidden copy of every section with state.searchAll set (all sub-tabs, nothing folded) using the normal view functions, then counts matches per entry (data-eid on record/item/sequence elements). stepSearch() navigates (section, sub-tab, unfold, state.walk = null); highlightSearch() runs at the end of render() and wraps the matches in <mark class="hit">. Text under SEARCH_SKIP (buttons, inputs, .secret, .nosearch) is never searched, so secrets stay out. New view-mode furniture such as dates and badges needs the nosearch class or it will be counted.

  • Capture online, merge offline (issue #28): build.js also writes capture.html (modules crypto, images, capture, version + src/capture-app.js, no document, no payload, no storage). It captures walkthroughs and exports an encrypted bundle: src/capture.js (sealBundle, openBundle, validateBundle, destinations), the blob uses magic "FC" 0x01 via the magic argument of encrypt/decrypt, so bundles and documents can't be confused. The main app's Import captures… (importCaptures() in app.js) opens a bundle, lets the user choose a destination per walkthrough, and importWalkthrough() in ops.js adds each as a sequence. Nothing is written until Save; the bundle file is never modified. Annotation happens after import.

  • Reset (?reset=1): opening the file with ?reset=1 or #reset=1 shows a banner after unlock offering to erase every secret-flagged field value and secret frame (clearSecrets() in ops.js, count from countSecrets). Labels, structure and flags stay. It is read live (resetRequested()), with a hashchange listener to re-offer, and state.resetOffered dismisses it. Nothing is written until Save, so make a Backup copy first. It's meant for working on layout on a less safe machine.

Save. Uses the File System Access API (showSaveFilePicker, handle reused) where available, otherwise a Blob download. assemble() rebuilds the full HTML from the page's own CSS and JS plus a fresh encrypted payload. If the write throws NotAllowedError/SecurityError (Chrome creates an empty file, then refuses the write; seen on a COSMIC/Wayland desktop with portal dialogs, issue #20), save() drops the handle and downloads final-wishes.html instead, with an explanatory status. "Backup copy" downloads final-wishes-YYYYMMDD.html.

Upgrading app code, keeping data. A file runs the code it was saved with. On the start screen, "Open your existing Final Wishes file" extracts the #payload from an older .html, unlocks it with the passphrase, and Save then writes it out with the newer code.

Print. Built only when Print is chosen and cleared on afterprint, so secrets don't linger in the DOM. It is a <table> whose <thead> holds the running header, which the browser repeats at the top of every page. Each section starts a new page (a section with sub-tabs gets a sub-heading per non-empty tab), records and sequence steps avoid page breaks inside them, and checklist items have tick boxes. The print dialog offers "withhold secrets" (default) or "include secrets". Images are decoded before window.print().

Integrations

None at runtime. Development uses the Gitea remote and the gt CLI for issues; PLAN.md and README.md describe the process.

Database & Data Layer

No database. The document is a JSON object, encrypted and embedded in the HTML file. The plaintext working copy data/seed.json is git-ignored, was used only to seal the first build, and has been deleted.

Connectivity & Configuration

Item Purpose
FW_PASSPHRASE (env) Passphrase for build.js; otherwise it is prompted for hidden and entered twice. It is never accepted as a command-line argument.
node build.js --data FILE --out PATH Seal a JSON file into the built HTML. Without --data the app starts empty and can open an older file or a JSON file.
npm run build / seal / test / bump / hooks Build the app only / build with data/seed.json / run the tests / advance the app version by hand / enable the pre-commit hook that does it automatically

Key Entry Points

  • build.js: how the single file is assembled
  • src/template.js: the output skeleton
  • src/app.js: the start screen (renderStart), then render(), save(), buildPrintDoc()
  • src/model.js: the data contract; read this first before changing stored data
  • src/crypto.js: the encrypted format
  • README.md: how the owner uses and updates it

Notes & Gotchas

  • Bundle scope: all modules share one scope after the build. Don't add a top-level name that already exists elsewhere, and don't use import/export forms other than line-start import and export , because the stripper is regex-based.
  • h() children: it flattens with flat(Infinity), but replaceChildren needs an explicit .flat(). Use textContent, never innerHTML.
  • Dirty and status: markDirty() clears the status text, so set state.status after calling changed().
  • Older builds: files saved with images, visual sequences or sub-tabs can't be opened by builds that predate them. The upgrade path only goes forward.
  • Blob size: images are embedded in the encrypted payload and make the file bigger and saves slower.
  • Skipped test: one test in test/model.test.js is skipped unless the gitignored data/seed.json exists.
  • Browser coverage: features were verified in headless Chromium only; Firefox and Safari drop and paste are untested.
  • Open work: issue #20 (in-place save refused by Chrome on one machine; see HANDOFF.md) is open, with a pending choice to make download the default save. Issue #8 (security clean-up) remains open. It is the owner's own tasks: rotating exposed secrets, refreshing stale data and keeping a second encrypted copy.
  • Git history: commit 9fa6096 contains a PIN that matched a real one from the source material. It was removed from the code in 7a81637 but not from history, so treat it as exposed.