Skip to content

Commit b2baf23

Browse files
authored
Merge pull request #113 from DenisValeev/codex/add-project-documentation-in-md-format
2 parents 660add8 + 9212c5e commit b2baf23

9 files changed

Lines changed: 798 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ This project is a static toolbox site. The landing page (`index.html`) lists sma
2929
- If you skip scripted coverage, at least open the affected HTML files in a browser (or start `python -m http.server`) to confirm layout, theme switching, and keyboard interactions still work.
3030
- If you adjust the asset observatory, regenerate its dataset snapshot with `node tools/generate-asset-report.js` so `apps/asset-observatory/asset-data.js` stays in sync.
3131
- A new regression spec enforces Home buttons across apps—after tweaking navigation chrome, run `npx playwright test tests/home-navigation.spec.js`.
32+
33+
## Documentation
34+
- The `ai_docs/` directory hosts the Markdown knowledge base. Update the relevant guides whenever you change workflows, scripts, or datasets so the docs remain authoritative.
35+
- When you add, remove, or rename a guide, update the `guides` array in `ai_docs/index.html` so the navigation stays in sync.
36+
- After editing documentation, open `ai_docs/index.html` in a browser (or via `npx serve .`) to confirm the Markdown renders through Marked and the hash navigation works.

ai_docs/AGENTS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# AI documentation workspace
2+
3+
- Keep documentation in Markdown under `ai_docs/docs/`. Use descriptive headings and prefer tables for directory overviews.
4+
- Whenever you add a new guide, update `ai_docs/index.html` so the navigation lists the page. Each entry in the `guides` array should include an `id`, `title`, `file`, and concise `summary`.
5+
- Render tweaks should preserve the two-space indentation used throughout the HTML and CSS. Stick with the existing palette and typography to keep the docs visually aligned with the landing page.
6+
- After editing docs, load `ai_docs/index.html` in a browser (or via `npx serve .`) to confirm the Markdown renders and navigation links update the hash correctly.
7+
- Keep cross-references current: when workflows, scripts, or tests change, update the relevant Markdown sections and summaries so the knowledge base stays authoritative.

ai_docs/docs/apps.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# App catalog
2+
3+
Each mini app lives under `apps/<name>/` with inline styles, a focused script, and any supporting datasets it needs. The landing page links directly to every `index.html`, and many collections ship an additional `all-*.html` archive that renders the full dataset in a searchable table. This catalog summarises the responsibilities, data dependencies, and regression coverage for each tool.
4+
5+
## Dad Jokes (`apps/jokes`)
6+
7+
- **Purpose.** Shuffle a curated deck of developer-friendly jokes, reveal punchlines on demand, and explore the full archive when you need deeper context.
8+
- **Key files.**
9+
- `index.html` – Deck UI with shuffle/prev/next controls, keyboard shortcuts, and a punchline toggle.
10+
- `app.js` – Guards missing DOM nodes, shuffles the dataset, renders the current joke, and wires keyboard shortcuts (`ArrowLeft`, `ArrowRight`, `Space`).
11+
- `jokes.js` – Dataset that assigns an array of `{ joke, punchline }` objects to `window.jokes`.
12+
- `all-jokes.html` & `render-all.js` – Table view with search/filter controls and a badge that reflects the dataset count via `data-count`.
13+
- **Data maintenance.** Update jokes with `tools/update-content-metadata.js`, regenerate embeddings with `tools/review-content-similarity.js`, and use the commands in `apps/jokes/AGENTS.md` to validate syntax and spot duplicates.
14+
- **Regression coverage.** `tests/jokes.spec.js` covers deck navigation; `tests/jokes-dataset.spec.js` verifies dataset invariants; `tests/home-navigation.spec.js` confirms the Home shortcut.
15+
16+
## Quotes (`apps/quotes`)
17+
18+
- **Purpose.** Surface themed quote decks with shuffle controls, reveal the full backlog, and maintain deterministic metadata for dedupe analysis.
19+
- **Key files.**
20+
- `index.html` – Shuffle UI mirroring the jokes experience.
21+
- `app.js` – Maintains the active deck, handles keyboard shortcuts, and toggles the quote attribution display.
22+
- `quotes-data.js` – Dataset assigned to `window.quotesData` with `{ text, author, tags }` entries.
23+
- `all-quotes.html` & `render-all.js` – Archive table with search and filter affordances plus the dataset count badge.
24+
- **Data maintenance.** Refresh the dataset metadata with `tools/update-content-metadata.js --dataset=quotes`, rerun embeddings for duplicate detection, and keep `data/quotes-embeddings*.json` in sync. Similarity overrides live in `data/similarity-overrides.json`.
25+
- **Regression coverage.** `tests/quotes.spec.js` exercises the deck UI, `tests/quotes-all.spec.js` covers the archive table, and `tests/quotes-data.spec.js` checks dataset integrity.
26+
27+
## Slang (`apps/slang`)
28+
29+
- **Purpose.** Educate visitors on trending internet slang with reveal-on-demand definitions and a searchable archive.
30+
- **Key files.**
31+
- `index.html` and `app.js` – Shuffle UI, reveal toggle, and keyboard shortcuts identical to the jokes/quotes decks but targeting `window.slangEntries`.
32+
- `slang.js` – Dataset assigned to `window.slangEntries`.
33+
- `all-slang.html` & `render-all.js` – Archive listing with search, filters, and the dataset count badge.
34+
- **Data maintenance.** Follow `apps/slang/AGENTS.md`: run the syntax checks, regenerate metadata (`tools/update-content-metadata.js --dataset=slang`), and refresh embeddings via `tools/review-content-similarity.js` for the synthetic, Hugging Face, and 128-dimension stores.
35+
- **Regression coverage.** `tests/slang-app.spec.js`, `tests/slang-all.spec.js`, and `tests/slang-dataset.spec.js` validate the UI, archive view, and dataset respectively.
36+
37+
## Cosine Similarity Lab (`apps/similarity-report`)
38+
39+
- **Purpose.** Visualise cosine-similar joke/quote/slang pairs, toggle datasets and providers, and inspect per-entry vector statistics.
40+
- **Key files.**
41+
- `index.html` – Standalone HTML+JS document that fetches the similarity reports under `data/`, renders dataset toggles, and presents side-by-side comparisons.
42+
- Consumes `data/similarity-report-*.json` plus overrides declared in `data/similarity-overrides.json`.
43+
- **Data maintenance.** Regenerate similarity reports with `tools/review-content-similarity.js` whenever embeddings change. The tool reads cross-deck reports (`data/similarity-report-cross-deck*.json`) alongside per-dataset outputs.
44+
- **Regression coverage.** `tests/similarity-report.spec.js` exercises dataset filtering, score thresholds, and keyboard shortcuts.
45+
46+
## Asset Observatory (`apps/asset-observatory`)
47+
48+
- **Purpose.** Provide a high-level dashboard for dataset counts, embedding stores, similarity reports, and upstream sources powering the toolbox.
49+
- **Key files.**
50+
- `index.html` – Layout and visualisations for the dataset cards, provider summaries, cross-deck rollups, and ledger table.
51+
- `app.js` – Loads `asset-data.js`, renders the dashboard, and wires filtering controls.
52+
- `asset-data.js` – Machine-generated snapshot produced by `tools/generate-asset-report.js`.
53+
- **Data maintenance.** Run `node tools/generate-asset-report.js` whenever datasets, embeddings, or similarity reports change. The `apps/asset-observatory/AGENTS.md` file captures the workflow and regression command.
54+
- **Regression coverage.** `tests/asset-observatory.spec.js` ensures cards, charts, and counts stay aligned with the snapshot.
55+
56+
## Embedding Explorer (`apps/embedding-explorer`)
57+
58+
- **Purpose.** Inspect embedding vectors, compare dataset records, and visualise high-impact dimensions.
59+
- **Key files.**
60+
- `index.html` – Dashboard layout with dataset selector, record filter, neighbor list, and dual canvas plots.
61+
- `app.js` – Parses sample embeddings, decodes base64 vectors, computes statistics, renders histograms, and highlights the strongest positive/negative dimensions.
62+
- `sample-embeddings.js` – Bundled dataset and metadata sources exposed as `window.embeddingExplorerSamples` and `window.embeddingSources`.
63+
- **Data maintenance.** Update `sample-embeddings.js` when adding new demo vectors. The explorer reads live datasets by decoding the base64 payloads from the embeddings stores in `data/` when available.
64+
- **Regression coverage.** `tests/embedding-explorer.spec.js` verifies dataset switching, record filtering, neighbor insights, and chart rendering.
65+
66+
## Value Formatter (`apps/value-formatter`)
67+
68+
- **Purpose.** Transform newline-separated values into templated output for quick copy/paste workflows.
69+
- **Key files.**
70+
- `index.html` – Single-page interface with preset transforms, custom transform inputs, and textareas for input/output. Stores the latest input in `localStorage` so the session persists.
71+
- All logic lives inline inside `<script>` tags; the app does not depend on external datasets.
72+
- **Data maintenance.** None required beyond keeping the presets up to date. The tool stores user input locally and has no background data dependencies.
73+
- **Regression coverage.** `tests/value-formatter.spec.js` validates presets, persistence, and manual transformations.
74+
75+
## Landing page integration
76+
77+
- Every app exposes a “Home” navigation link that returns to `../../`, satisfying `tests/home-navigation.spec.js` and `tests/home.spec.js`.
78+
- The landing page’s `tests/index.spec.js` ensures new tools register their cards and developer shortcuts.
79+
- When adding an app, update `index.html` with the new card and extend the offline manifest so the service worker caches the new assets.

ai_docs/docs/architecture.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Site architecture
2+
3+
The toolbox intentionally avoids a build pipeline. Each page is authored as standalone HTML with inline CSS and a small script bundle. The repository’s shared behaviours live in the landing page, the offline bootstrap flow, and the service worker. This section documents how those pieces interact.
4+
5+
## Landing page (`index.html`)
6+
7+
- **Layout and theming.** The page renders the Toolbox banner plus grouped rows for deck-based apps (jokes, quotes, slang) and utilities (formatters, explorers, reports). CSS custom properties define the light and dark palettes, and the document honours `prefers-color-scheme` so browsers automatically switch palettes.
8+
- **App rows.** Each `<li class="app-row">` contains labelled buttons that deep-link into the relevant app or its archival pages (such as `apps/jokes/all-jokes.html`). Buttons rely on inline SVG chevrons copied across the project to keep the iconography consistent.
9+
- **Offline call-to-action.** The card with `data-offline-card` summarises the cached bundle, renders progress while assets stream in, and exposes a “Refresh offline bundle” button that triggers a manual cache reset. A progress bar pinned to the top edge communicates status for screen reader users via `aria-live` updates.
10+
- **Client bootstrap.** A script near the bottom of the document orchestrates service worker registration, fetches `offline-manifest.json`, displays bundle metadata, and pipes progress updates into the visual meter. It also exposes a `data-offline-reset` button that calls into the worker to rebuild caches on demand.
11+
12+
## Offline manifest (`offline-manifest.json`)
13+
14+
- Generated by `node tools/generate-offline-manifest.js` (surfaced via `npm run build:offline`).
15+
- Lists every HTML, JavaScript, and JSON asset shipped with the site, together with byte sizes and a combined SHA-256 digest.
16+
- Includes the Git commit metadata embedded by the generator so the landing page can show which revision produced the bundle.
17+
- Stored under versioned keys such as `"version": "2024-04-02T20-19-04"`, which doubles as the cache suffix used by the service worker.
18+
19+
## Service worker (`service-worker.js`)
20+
21+
- **Cache naming.** Uses a `toolbox-offline-v*` prefix, where `*` matches the manifest’s version. The worker persists the active version in `toolbox-offline-metadata` so it can recover after reloads.
22+
- **Lifecycle.** On install it calls `skipWaiting()` so the newest worker activates immediately. Activation reads the stored manifest, deletes stale caches, and claims open clients.
23+
- **Fetch handling.**
24+
- Navigation requests fall back to the cached landing page when offline.
25+
- Requests for `offline-manifest.json` are intercepted so the worker can serve a cached copy while streaming updates in the background.
26+
- Static asset requests are served from the active cache first, with a network fallback that backfills the cache.
27+
- **Messaging.** Listens for two message types:
28+
- `apply-manifest` enqueues a cache update using the provided manifest payload.
29+
- `reset-offline-cache` clears caches and re-runs the manifest application from scratch.
30+
- **Progress reporting.** Tracks how many assets and bytes have been cached and posts structured messages back to the landing page. The page renders this information inside the progress meter and the offline summary card.
31+
32+
## Data loading
33+
34+
- Deck-style apps (jokes, quotes, slang) expose datasets by assigning arrays to globals (`window.jokes`, `window.proverbsData`, etc.). Each app imports the dataset script via `<script src="..." defer>` and reads it synchronously during initialisation.
35+
- Heavy reports (asset observatory, similarity report) load JSON snapshots that live under `data/`. Generators in `tools/` keep those snapshots fresh.
36+
- The embedding explorer includes bundled samples (`apps/embedding-explorer/sample-embeddings.js`) so the interface can demonstrate statistics without requiring external APIs.
37+
38+
## Packaging and distribution
39+
40+
- `package.json` declares a `pretest` hook that ensures Playwright’s Chromium build is available before tests run. No bundler dependencies are required.
41+
- Opening any HTML file from disk is sufficient during development, but `npx serve .` (or any HTTP server) enables service worker registration and cross-document navigation.
42+
- The offline bundle allows end users to “install” the toolbox on mobile devices by caching the entire asset list and pinning the landing page to the home screen.

ai_docs/docs/data-maintenance.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Data maintenance
2+
3+
Content-heavy apps rely on shared datasets stored under `data/` plus machine-generated snapshots that live alongside each app. This guide documents the files that need to stay in sync and the scripts that regenerate them.
4+
5+
## Directory overview
6+
7+
| File | Description |
8+
| --- | --- |
9+
| `jokes-manifest.json`, `quotes-manifest.json`, `slang-manifest.json` | Deterministic manifests produced by `tools/update-content-metadata.js`. They record record hashes, canonical IDs, total counts, and metadata used by downstream scripts. |
10+
| `*-embeddings.json`, `*-embeddings-openai.json`, `*-embeddings-cohere.json`, `slang-embeddings-hfspace.json`, `slang-embeddings-synthetic128.json` | Embedding stores keyed by record IDs. These power the similarity reports, the embedding explorer, and duplicate detection workflows. |
11+
| `similarity-report-*.json` | Cosine similarity sweeps grouped by dataset and provider (synthetic, OpenAI, Cohere, HF space, synthetic-128). Cross-deck variants highlight overlaps between jokes, quotes, and slang. |
12+
| `similarity-overrides.json` | Flags intentional near-duplicates so the cosine similarity lab can highlight protected pairs instead of suggesting removals. |
13+
| `test-runs/` | Archives Playwright trace data and logs captured by `tools/record-playwright-log.js` to help diagnose failures. |
14+
15+
## Updating deck datasets
16+
17+
1. Edit the dataset files under `apps/jokes/jokes.js`, `apps/quotes/quotes-data.js`, or `apps/slang/slang.js`.
18+
2. Run the syntax and shape checks documented in each app’s `AGENTS.md` file (`node --check ...` and the `node -e` globals check).
19+
3. Regenerate metadata and manifests:
20+
```bash
21+
node tools/update-content-metadata.js --dataset=jokes
22+
node tools/update-content-metadata.js --dataset=quotes
23+
node tools/update-content-metadata.js --dataset=slang
24+
```
25+
Pass `--dataset=<name>` to target a single collection when needed.
26+
4. Refresh embeddings for duplicate detection. Typical commands:
27+
```bash
28+
node tools/review-content-similarity.js --dataset=jokes --provider=synthetic --write --update-manifest
29+
node tools/review-content-similarity.js --dataset=jokes --provider=hfspace --model=bienkieu/sentence-embedding --batch-size=8 --report=data/similarity-report-jokes.json
30+
node tools/review-content-similarity.js --dataset=quotes --provider=openai --write --update-manifest
31+
node tools/review-content-similarity.js --dataset=slang --provider=synthetic --threshold-slang=0.8 --write --update-manifest
32+
```
33+
Adjust providers and options according to your API access and the thresholds documented in `apps/slang/AGENTS.md` and the repository README.
34+
5. Review high-similarity pairs and move intentional overlaps into `data/similarity-overrides.json` so the similarity lab highlights them as protected.
35+
6. Commit refreshed datasets, manifests, embeddings, and similarity reports together to keep the bundle consistent.
36+
37+
## Regenerating similarity reports
38+
39+
- `tools/review-content-similarity.js` emits JSON files such as `data/similarity-report-jokes.json`, `data/similarity-report-quotes-openai.json`, and `data/similarity-report-cross-deck.json`.
40+
- Pass `--provider=<source>` plus `--write` and `--report=...` to persist new embeddings and the matching report. Providers include:
41+
- `synthetic` for deterministic vectors embedded locally.
42+
- `hfspace` for the BienKieu Hugging Face Space (`sentence-transformers/all-MiniLM-L6-v2`).
43+
- `openai` and `cohere` for API-based embeddings when credentials are available.
44+
- Use `--threshold-<dataset>` flags to enforce dataset-specific duplication caps (for example, `--threshold-slang=0.8`).
45+
- After generating reports, rerun `node tools/generate-asset-report.js` so the asset observatory reflects the new counts and byte sizes.
46+
47+
## Maintaining the asset observatory snapshot
48+
49+
- The observatory reads `apps/asset-observatory/asset-data.js`, a machine-generated file containing dataset counts, provider rollups, cross-deck statistics, and ledger rows.
50+
- Regenerate it via:
51+
```bash
52+
node tools/generate-asset-report.js
53+
```
54+
- The script inspects dataset files, manifests, embedding stores, similarity reports, and upstream sources. It records totals for entries, bytes, and asset counts per provider, plus cross-deck similarity pairs.
55+
- Commit the updated snapshot along with the underlying dataset changes so the dashboard stays consistent.
56+
57+
## Offline manifest refreshes
58+
59+
- Any change to HTML, JavaScript, or JSON assets requires regenerating `offline-manifest.json`:
60+
```bash
61+
npm run build:offline
62+
```
63+
- The generator computes SHA-256 digests, total bytes, asset counts, and Git metadata. The manifest’s version feeds directly into the service worker’s cache key.
64+
- After updating the manifest, reload the landing page to confirm the offline card reflects the new bundle size.
65+
66+
## Diagnostics and audit logs
67+
68+
- Run `node tools/record-playwright-log.js` to capture Playwright traces for failing specs. Output lives under `data/test-runs/` with timestamps and spec names.
69+
- Use the JSON artifacts inside `test-runs/` to reproduce test paths or share failure context in pull requests.

0 commit comments

Comments
 (0)