60 Commits

Author SHA1 Message Date
e3d089a71f Merge pull request 'v1.3.1' (#39) from dev into main
All checks were successful
CI / test (push) Successful in 14s
Release / release (push) Successful in 42s
CI / build-dev (push) Has been skipped
Reviewed-on: #39
2026-03-28 15:42:00 -04:00
668e7c34bb Merge pull request 'chore: release v1.3.1' (#38) from chore/bump-v1.3.1 into dev
All checks were successful
CI / test (push) Successful in 15s
CI / build-dev (push) Successful in 25s
CI / test (pull_request) Successful in 14s
CI / build-dev (pull_request) Has been skipped
Reviewed-on: #38
2026-03-28 15:40:46 -04:00
e796b4f400 chore: release v1.3.1
All checks were successful
CI / test (pull_request) Successful in 14s
CI / build-dev (pull_request) Has been skipped
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:40:16 -04:00
a4b5c20993 Merge pull request 'fix: clear instance history on delete and import' (#37) from fix/delete-clears-history into dev
All checks were successful
CI / test (push) Successful in 13s
CI / build-dev (push) Successful in 20s
Reviewed-on: #37
2026-03-28 15:38:15 -04:00
d17f364fc5 fix: clear instance history on delete and import
All checks were successful
CI / test (pull_request) Successful in 14s
CI / build-dev (pull_request) Has been skipped
deleteInstance now removes history rows for that vmid before removing
the instance. importInstances clears all history before replacing
instances. Prevents stale history appearing when a vmid is reused.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:37:45 -04:00
5f79eec3dd Merge pull request 'fix: categorize release notes into New Features / Bug Fixes, drop chores' (#36) from fix/release-notes-format into dev
All checks were successful
CI / test (push) Successful in 12s
CI / build-dev (push) Successful in 20s
Reviewed-on: #36
2026-03-28 15:36:27 -04:00
ed98bb57c0 fix: categorize release notes into New Features / Bug Fixes, drop chores
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:35:53 -04:00
120b61a423 Merge pull request 'v1.3.0' (#35) from dev into main
All checks were successful
CI / test (push) Successful in 14s
Release / release (push) Successful in 40s
CI / build-dev (push) Has been skipped
Reviewed-on: #35
2026-03-28 15:31:57 -04:00
074f0600af Merge pull request 'chore: release v1.3.0' (#34) from chore/bump-v1.3.0 into dev
All checks were successful
CI / test (push) Successful in 14s
CI / build-dev (push) Successful in 21s
CI / test (pull_request) Successful in 14s
CI / build-dev (pull_request) Has been skipped
Reviewed-on: #34
2026-03-28 15:30:02 -04:00
e4f9407827 Merge branch 'dev' into chore/bump-v1.3.0
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
2026-03-28 15:29:09 -04:00
fde5ce7dc1 Merge pull request 'chore: release v1.3.0' (#33) from chore/bump-v1.3.0 into dev
All checks were successful
CI / test (push) Successful in 13s
CI / build-dev (push) Successful in 28s
Reviewed-on: #33
2026-03-28 15:28:44 -04:00
20df10b333 chore: release v1.3.0
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:28:39 -04:00
c906511bfc chore: release v1.3.0
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:27:30 -04:00
745e5920ad Merge pull request 'fix: set html zoom 1.1 so default scale matches browser 110%' (#32) from fix/base-zoom into dev
All checks were successful
CI / test (push) Successful in 12s
CI / build-dev (push) Successful in 20s
Reviewed-on: #32
2026-03-28 15:25:32 -04:00
90e0a98914 fix: set html zoom 1.1 so default scale matches browser 110%
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:24:58 -04:00
cba4b73798 Merge pull request 'fix: use badge for stack on detail overview, consistent across all views' (#31) from fix/detail-stack-badge into dev
All checks were successful
CI / test (push) Successful in 14s
CI / build-dev (push) Successful in 21s
Reviewed-on: #31
2026-03-28 15:22:13 -04:00
0d567472a9 fix: use badge for stack on detail overview, consistent across all views
All checks were successful
CI / test (pull_request) Successful in 12s
CI / build-dev (pull_request) Has been skipped
stack was plain highlighted text on the detail page but a coloured badge
on the home cards and in the history timeline. Now all three use the same
badge component.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:21:25 -04:00
9f6b2ece52 Merge pull request 'fix: parse SQLite timestamps as UTC, not local time' (#30) from fix/sqlite-utc-timestamps into dev
All checks were successful
CI / test (push) Successful in 12s
CI / build-dev (push) Successful in 20s
Reviewed-on: #30
2026-03-28 15:20:15 -04:00
e3911157e9 fix: parse SQLite timestamps as UTC, not local time
All checks were successful
CI / test (pull_request) Successful in 14s
CI / build-dev (pull_request) Has been skipped
SQLite datetime('now') returns 'YYYY-MM-DD HH:MM:SS' with no timezone
marker. JS was treating this as local time, so timestamps showed the
correct UTC digits but with the local TZ abbreviation attached (e.g.
'7:15 PM EDT' when the real local time was '3:15 PM EDT').

Add parseUtc() which appends 'Z' before parsing any string that has no
existing timezone marker, ensuring JS always treats them as UTC before
the display-timezone conversion is applied.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:19:35 -04:00
0589288dfe Merge pull request 'fix: populate nav instance count on direct detail page load/refresh' (#29) from fix/detail-nav-count into dev
All checks were successful
CI / test (push) Successful in 13s
CI / build-dev (push) Successful in 21s
Reviewed-on: #29
2026-03-28 15:16:32 -04:00
8ead7687e5 fix: populate nav instance count on direct detail page load/refresh
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
nav-count was only set in renderDashboard, so loading /instance/:vmid
directly left it showing "—". Add getInstances() to the parallel fetch
in renderDetailPage and set the count there too.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:15:55 -04:00
0e1e9b6699 Merge pull request 'fix: show stack badge in history timeline, matching state treatment' (#28) from fix/history-stack-badge into dev
All checks were successful
CI / test (push) Successful in 13s
CI / build-dev (push) Successful in 22s
Reviewed-on: #28
2026-03-28 15:14:02 -04:00
3c008c5bce fix: show stack badge in history timeline, matching state treatment
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:13:27 -04:00
1582c28b28 Merge pull request 'fix: clean up instance detail subtitle — dividers, readable values' (#27) from feat/timezone-settings into dev
All checks were successful
CI / test (push) Successful in 12s
CI / build-dev (push) Successful in 21s
Reviewed-on: #27
2026-03-28 15:10:54 -04:00
bcd934f5b1 Merge branch 'dev' into feat/timezone-settings
All checks were successful
CI / test (pull_request) Successful in 12s
CI / build-dev (pull_request) Has been skipped
2026-03-28 15:10:26 -04:00
4c9acd20c7 fix: clean up instance detail subtitle — dividers, readable values
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
Separate vmid / id / created with a subtle vertical border so they
don't run together. Bump font to 13px. Labels drop to 11px muted,
values use full --text colour so the actual data stands out clearly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:10:05 -04:00
520fb98d96 Merge pull request 'feat: redesign history timeline — single-line, timestamp right-aligned' (#26) from feat/timezone-settings into dev
All checks were successful
CI / test (push) Successful in 12s
CI / build-dev (push) Successful in 19s
Reviewed-on: #26
2026-03-28 15:07:01 -04:00
800184d2be Merge branch 'dev' into feat/timezone-settings
All checks were successful
CI / test (pull_request) Successful in 12s
CI / build-dev (pull_request) Has been skipped
2026-03-28 15:06:34 -04:00
82c314f85c feat: redesign history timeline — single-line, timestamp right-aligned
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
Each event is now one row: label · old → new on the left, timestamp
right-aligned. Nothing is far from anything else. State changes use the
existing badge component for immediate visual recognition. The created
event reads 'instance created' in accent. Middle-dot separator keeps
field label and change value clearly associated without forced spacing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:06:09 -04:00
2fba532ec7 Merge pull request 'feat: rework history timeline for clarity' (#25) from feat/timezone-settings into dev
All checks were successful
CI / test (push) Successful in 13s
CI / build-dev (push) Successful in 20s
Reviewed-on: #25
2026-03-28 15:01:39 -04:00
9177578aaf Merge branch 'dev' into feat/timezone-settings
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
2026-03-28 15:01:12 -04:00
94c4a0af51 feat: rework history timeline for clarity
All checks were successful
CI / test (pull_request) Successful in 12s
CI / build-dev (pull_request) Has been skipped
Timestamp now sits on its own line above each event so it's visually
separate from the change description. Field names use a friendly label
map (hardware_acceleration → hw acceleration, tailscale_ip → tailscale ip,
etc.). The created event reads "instance created" in accent colour instead
of a raw "created / —". Padding between rows increased.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 15:00:22 -04:00
ec60d53767 Merge pull request 'feat: timezone setting — display timestamps in selected local timezone' (#24) from feat/timezone-settings into dev
All checks were successful
CI / test (push) Successful in 12s
CI / build-dev (push) Successful in 19s
Reviewed-on: #24
2026-03-28 14:56:01 -04:00
ad81d7ace7 Merge branch 'dev' into feat/timezone-settings
All checks were successful
CI / test (pull_request) Successful in 12s
CI / build-dev (pull_request) Has been skipped
2026-03-28 14:55:35 -04:00
badd542bd7 feat: timezone setting — display timestamps in selected local timezone
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
Add a Display section to the settings modal with a timezone dropdown.
Selection is persisted to localStorage and applied to all timestamps via
fmtDate (date-only) and fmtDateFull (date + time + TZ abbreviation, e.g.
"Mar 28, 2026, 2:48 PM EDT"). Changing the timezone live-re-renders the
current page. Defaults to UTC.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 14:53:20 -04:00
7c31ee3327 Merge pull request 'chore: maintenance — test coverage, route cleanup, README rewrite' (#23) from chore/maintenance into dev
All checks were successful
CI / test (push) Successful in 13s
CI / build-dev (push) Successful in 23s
Reviewed-on: #23
2026-03-28 14:47:27 -04:00
0ecfa7dbc9 chore: maintenance — test coverage, route cleanup, README rewrite
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
- Add fmtHistVal and stateClass helper tests (7 new, 106 total)
- Add import regression test: missing name field returns 400 not 500
- Fix normalise() crash on missing name: body.name.trim() → (body.name ?? '').trim()
- Extract duplicate DB error handler into handleDbError() helper
- Rewrite README from scratch with audit log, export/import, full API docs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 14:46:48 -04:00
f16fb3e088 Merge pull request 'feat: audit log / history timeline on instance detail page' (#22) from feat/history-timeline into dev
All checks were successful
CI / test (push) Successful in 17s
CI / build-dev (push) Successful in 22s
Reviewed-on: #22
2026-03-28 14:36:22 -04:00
cb01573cdf feat: audit log / history timeline on instance detail page
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
Adds an instance_history table that records every field change:
- createInstance logs a 'created' event
- updateInstance diffs old vs new and logs one row per changed field
  (name, state, stack, vmid, tailscale_ip, all service flags)
- History is stored under the new vmid when vmid changes

New endpoint: GET /api/instances/:vmid/history

The 'timestamps' section on the detail page is replaced with a
grid timeline showing timestamp | field | old → new for each event.
State changes are colour-coded (deployed=green, testing=amber,
degraded=red). Boolean service flags display as on/off.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 14:35:35 -04:00
b48d5fb836 Merge pull request 'fix: remove stacks count from stats bar' (#21) from fix/remove-stacks-stat into dev
All checks were successful
CI / test (push) Successful in 13s
CI / build-dev (push) Successful in 20s
Reviewed-on: #21
2026-03-28 14:28:19 -04:00
6e124576cb fix: remove stacks count from stats bar
All checks were successful
CI / test (pull_request) Successful in 12s
CI / build-dev (pull_request) Has been skipped
Stacks are always just production/development — counting them adds
no useful information to the dashboard summary.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 14:27:43 -04:00
1f328e026d Merge pull request 'fix: uniform 16px spacing above all settings sections' (#20) from fix/settings-section-spacing into dev
All checks were successful
CI / test (push) Successful in 14s
CI / build-dev (push) Successful in 22s
Reviewed-on: #20
2026-03-28 14:24:09 -04:00
71c2c68fbc fix: uniform 16px spacing above all settings sections
All checks were successful
CI / test (pull_request) Successful in 12s
CI / build-dev (pull_request) Has been skipped
Removing the :first-child { padding-top: 0 } override lets every
section use the same padding: 16px 0, so the gap above Export matches
the gap above Import (and any future sections).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 14:23:14 -04:00
8bcf8229db Merge pull request 'fix: remove top padding from settings modal body' (#19) from fix/settings-modal-body-padding into dev
All checks were successful
CI / test (push) Successful in 17s
CI / build-dev (push) Successful in 21s
Reviewed-on: #19
2026-03-28 14:20:20 -04:00
6e1e9f7153 fix: remove top padding from settings modal body
All checks were successful
CI / test (pull_request) Successful in 14s
CI / build-dev (pull_request) Has been skipped
The modal-body's 22px padding-top created a visible gap between the
header divider and the Export section title.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 14:19:39 -04:00
1fbb74d1ef Merge pull request 'fix: remove top gap above first settings section' (#18) from feat/settings-modal into dev
All checks were successful
CI / test (push) Successful in 13s
CI / build-dev (push) Successful in 23s
Reviewed-on: #18
2026-03-28 14:16:22 -04:00
617a5b5800 Merge branch 'dev' into feat/settings-modal
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
2026-03-28 14:15:57 -04:00
0985d9d481 fix: remove top gap above first settings section
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
padding-top on the first .settings-section created a visible gap
above the Export title. Fixed with :first-child { padding-top: 0 }.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 14:15:25 -04:00
2af6c56558 Merge pull request 'feat: settings modal with database export and import' (#17) from feat/settings-modal into dev
All checks were successful
CI / test (push) Successful in 13s
CI / build-dev (push) Successful in 21s
Reviewed-on: #17
2026-03-28 14:12:08 -04:00
af207339a4 feat: settings modal with database export and import
All checks were successful
CI / test (pull_request) Successful in 12s
CI / build-dev (pull_request) Has been skipped
Adds a gear button to the nav that opens a settings modal with:
- Export: GET /api/export returns all instances as a JSON backup file
  with a Content-Disposition attachment header
- Import: POST /api/import validates and bulk-replaces all instances;
  client uses FileReader to POST the parsed JSON, with a confirm dialog
  before destructive replace

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 14:10:59 -04:00
cd16b7ea28 Merge pull request 'v1.2.2' (#16) from dev into main
All checks were successful
CI / test (push) Successful in 13s
Release / release (push) Successful in 34s
CI / build-dev (push) Has been skipped
Reviewed-on: #16
2026-03-28 14:01:33 -04:00
20d8a13375 Merge pull request 'chore: bump version to 1.2.2' (#15) from chore/bump-v1.2.2 into dev
All checks were successful
CI / test (push) Successful in 14s
CI / build-dev (push) Successful in 24s
CI / test (pull_request) Successful in 14s
CI / build-dev (pull_request) Has been skipped
Reviewed-on: #15
2026-03-28 13:59:53 -04:00
f72aaa52f8 chore: bump version to 1.2.2
All checks were successful
CI / test (pull_request) Successful in 12s
CI / build-dev (pull_request) Has been skipped
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 13:59:23 -04:00
dd47d5006e Merge pull request 'fix: collapse python3 one-liner to fix YAML indentation error' (#14) from fix/release-yaml-indent into dev
All checks were successful
CI / test (push) Successful in 12s
CI / build-dev (push) Successful in 21s
Reviewed-on: #14
2026-03-28 13:58:26 -04:00
10e25e1803 fix: collapse python3 one-liner to fix YAML indentation error
All checks were successful
CI / test (pull_request) Successful in 13s
CI / build-dev (pull_request) Has been skipped
Multi-line python3 -c "..." had unindented code outside the run: | block,
causing 'yaml: line 83: could not find expected :'. Collapsed to a single
indented line so the YAML parser sees it correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 13:57:48 -04:00
afbdefa549 Merge pull request 'v1.2.1' (#13) from dev into main
All checks were successful
CI / test (push) Successful in 14s
CI / build-dev (push) Has been skipped
Reviewed-on: #13
2026-03-28 13:55:34 -04:00
1a62e2fdd9 Merge pull request 'chore: bump version to 1.2.1' (#12) from chore/bump-v1.2.1 into dev
All checks were successful
CI / test (push) Successful in 15s
CI / build-dev (push) Successful in 28s
CI / test (pull_request) Successful in 12s
CI / build-dev (pull_request) Has been skipped
Reviewed-on: #12
2026-03-28 13:54:12 -04:00
1271c061fd chore: bump version to 1.2.1
All checks were successful
CI / test (pull_request) Successful in 16s
CI / build-dev (pull_request) Has been skipped
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 13:52:40 -04:00
7b2a996c21 Merge pull request 'fix: remove npm cache and fix release notes shell injection' (#11) from fix/release-workflow into dev
All checks were successful
CI / test (push) Successful in 13s
CI / build-dev (push) Successful in 20s
Reviewed-on: #11
2026-03-28 13:51:49 -04:00
3233d65db0 fix: remove npm cache and fix release notes shell injection
All checks were successful
CI / test (pull_request) Successful in 14s
CI / build-dev (pull_request) Has been skipped
cache: npm caused ~4min ETIMEDOUT on every run (cache service unreachable).

Commit messages containing backticks were shell-expanded inside the
curl -d "..." string, causing 'sha: No such file or directory'. Fixed by
writing release notes to a temp file and using python3 to build the JSON
payload, then passing it to curl with --data @file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 13:49:38 -04:00
14 changed files with 772 additions and 125 deletions

View File

@@ -20,7 +20,6 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: npm
- run: npm ci
- run: npm test
@@ -48,12 +47,10 @@ jobs:
run: |
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
NOTES=$(git log "${LAST_TAG}..HEAD" --pretty=format:"- %s" --no-merges)
git log "${LAST_TAG}..HEAD" --pretty=format:"- %s" --no-merges > /tmp/release_notes.txt
else
NOTES=$(git log --pretty=format:"- %s" --no-merges)
git log --pretty=format:"- %s" --no-merges > /tmp/release_notes.txt
fi
NOTES_JSON=$(printf '%s' "$NOTES" | python3 -c "import sys,json; print(json.dumps(sys.stdin.read()))")
echo "NOTES=${NOTES_JSON}" >> $GITEA_ENV
- name: Docker metadata
id: meta
@@ -82,14 +79,31 @@ jobs:
- name: Create Gitea release
run: |
cat > /tmp/make_release.py << 'PYEOF'
import json, os
v = os.environ['VERSION']
img = os.environ['IMAGE']
raw = open('/tmp/release_notes.txt').read().strip()
feats, fixes = [], []
for line in raw.splitlines():
msg = line.lstrip('- ').strip()
if msg.startswith('feat:'):
feats.append('- ' + msg[5:].strip())
elif msg.startswith('fix:'):
fixes.append('- ' + msg[4:].strip())
sections = []
if feats:
sections.append('### New Features\n\n' + '\n'.join(feats))
if fixes:
sections.append('### Bug Fixes\n\n' + '\n'.join(fixes))
notes = '\n\n'.join(sections) or '_No changes_'
body = notes + '\n\n### Image\n\n' + img + ':' + v
payload = {'tag_name': 'v'+v, 'name': 'Catalyst v'+v, 'body': body, 'draft': False, 'prerelease': False}
open('/tmp/release_body.json', 'w').write(json.dumps(payload))
PYEOF
python3 /tmp/make_release.py
curl -sf -X POST \
-H "Authorization: token ${{ secrets.TOKEN }}" \
-H "Content-Type: application/json" \
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases" \
-d "{
\"tag_name\": \"v${{ env.VERSION }}\",
\"name\": \"Catalyst v${{ env.VERSION }}\",
\"body\": \"### Changes\n\n${{ env.NOTES }}\n\n### Image\n\n\`${{ env.IMAGE }}:${{ env.VERSION }}\`\",
\"draft\": false,
\"prerelease\": false
}"
--data @/tmp/release_body.json

1
.gitignore vendored
View File

@@ -1,5 +1,4 @@
node_modules/
js/version.js
data/*.db
data/*.db-shm
data/*.db-wal

155
README.md
View File

@@ -1,39 +1,38 @@
# Catalyst
A self-hosted infrastructure registry. Track every VM, container, and service across your homelab — their state, stack, and which internal services are running on them.
A self-hosted infrastructure registry for homelab Proxmox environments. Track virtual machines across stacks, monitor service health, and maintain a full audit log of every configuration change.
---
## Features
- **Dashboard** — filterable, searchable instance list with state and stack badges
- **Detail pages** — per-instance view with service flags, Tailscale IP, and timestamps
- **Detail pages** — per-instance view with service flags, Tailscale IP, and a full change timeline
- **Audit log** — every field change is recorded with before/after values and a timestamp
- **Full CRUD** — add, edit, and delete instances via a clean modal interface
- **Production safeguard** — only development instances can be deleted; production instances must be demoted first
- **REST API** — every operation is a plain HTTP call; no magic, no framework lock-in
- **Persistent storage** — SQLite database on a Docker named volume; survives restarts and upgrades
- **Zero native dependencies** — SQLite via Node's built-in `node:sqlite`. No compilation, no binaries.
- **Export / import** — JSON backup and restore via the settings modal
- **REST API** — every operation is a plain HTTP call
- **Persistent storage** — SQLite on a Docker named volume; survives restarts and upgrades
- **Zero native dependencies** — SQLite via Node's built-in `node:sqlite`; no compilation, no binaries
---
## Quick start
```bash
docker run -d \
--name catalyst \
-p 3000:3000 \
-v catalyst-data:/app/data \
gitea.thewrightserver.net/josh/catalyst:latest
```
Or with the included Compose file:
```bash
docker compose up -d
```
Open [http://localhost:3000](http://localhost:3000).
### Environment variables
| Variable | Default | Description |
|---|---|---|
| `PORT` | `3000` | HTTP port the server binds to |
| `DB_PATH` | `data/catalyst.db` | Path to the SQLite database file |
---
## REST API
@@ -44,11 +43,11 @@ All endpoints are under `/api`. Request and response bodies are JSON.
#### `GET /api/instances`
Returns all instances, sorted by name. All query parameters are optional.
Returns all instances sorted by name. All query parameters are optional.
| Parameter | Type | Description |
|-----------|--------|-----------------------------------------|
| `search` | string | Partial match on `name` or `vmid` |
|---|---|---|
| `search` | string | Partial match on `name`, `vmid`, or `stack` |
| `state` | string | Exact match: `deployed`, `testing`, `degraded` |
| `stack` | string | Exact match: `production`, `development` |
@@ -64,11 +63,11 @@ GET /api/instances?search=plex&state=deployed
"state": "deployed",
"stack": "production",
"tailscale_ip": "100.64.0.1",
"atlas": 1, "argus": 0, "semaphore": 0,
"atlas": 1, "argus": 1, "semaphore": 0,
"patchmon": 1, "tailscale": 1, "andromeda": 0,
"hardware_acceleration": 1,
"created_at": "2024-01-15T10:30:00.000Z",
"updated_at": "2024-03-10T14:22:00.000Z"
"created_at": "2024-01-15T10:30:00",
"updated_at": "2024-03-10T14:22:00"
}
]
```
@@ -91,10 +90,43 @@ GET /api/instances/stacks
Returns a single instance by VMID.
| Status | Condition |
|--------|-----------|
|---|---|
| `200` | Instance found |
| `404` | No instance with that VMID |
| `400` | VMID is not a valid integer |
| `404` | No instance with that VMID |
---
#### `GET /api/instances/:vmid/history`
Returns the audit log for an instance — newest events first.
| Status | Condition |
|---|---|
| `200` | History returned (may be empty array) |
| `400` | VMID is not a valid integer |
| `404` | No instance with that VMID |
```json
[
{
"id": 3,
"vmid": 117,
"field": "state",
"old_value": "testing",
"new_value": "deployed",
"changed_at": "2024-03-10T14:22:00"
},
{
"id": 1,
"vmid": 117,
"field": "created",
"old_value": null,
"new_value": null,
"changed_at": "2024-01-15T10:30:00"
}
]
```
---
@@ -103,21 +135,21 @@ Returns a single instance by VMID.
Creates a new instance. Returns the created record.
| Status | Condition |
|--------|-----------|
|---|---|
| `201` | Created successfully |
| `400` | Validation error (see `errors` array in response) |
| `400` | Validation error see `errors` array in response |
| `409` | VMID already exists |
**Request body:**
| Field | Type | Required | Notes |
|-------|------|----------|-------|
|---|---|---|---|
| `name` | string | yes | |
| `vmid` | integer | yes | Must be > 0, unique |
| `vmid` | integer | yes | Must be > 0 and unique |
| `state` | string | yes | `deployed`, `testing`, or `degraded` |
| `stack` | string | yes | `production` or `development` |
| `tailscale_ip` | string | no | Defaults to `""` |
| `atlas` | 0\|1 | no | Defaults to `0` |
| `tailscale_ip` | string | no | Valid IPv4 or empty string |
| `atlas` | 0\|1 | no | |
| `argus` | 0\|1 | no | |
| `semaphore` | 0\|1 | no | |
| `patchmon` | 0\|1 | no | |
@@ -132,7 +164,7 @@ Creates a new instance. Returns the created record.
Replaces all fields on an existing instance. Accepts the same body shape as `POST`. The `vmid` in the body may differ from the URL — this is how you change a VMID.
| Status | Condition |
|--------|-----------|
|---|---|
| `200` | Updated successfully |
| `400` | Validation error |
| `404` | No instance with that VMID |
@@ -145,11 +177,36 @@ Replaces all fields on an existing instance. Accepts the same body shape as `POS
Deletes an instance. Only instances on the `development` stack may be deleted.
| Status | Condition |
|--------|-----------|
|---|---|
| `204` | Deleted successfully |
| `400` | VMID is not a valid integer |
| `404` | No instance with that VMID |
| `422` | Instance is on the `production` stack |
| `400` | VMID is not a valid integer |
---
### Backup
#### `GET /api/export`
Downloads a JSON backup of all instances as a file attachment.
```json
{
"version": 1,
"exported_at": "2024-03-10T14:22:00.000Z",
"instances": [ ... ]
}
```
#### `POST /api/import`
Replaces all instances from a JSON backup. Validates every row before committing — if any row is invalid the entire import is rejected.
| Status | Condition |
|---|---|
| `200` | Import successful — returns `{ "imported": N }` |
| `400` | Body missing `instances` array, or validation errors |
---
@@ -165,34 +222,22 @@ npm start # start the server on :3000
Tests are split across three files:
| File | What it covers |
|------|----------------|
| `tests/db.test.js` | SQLite data layer — all CRUD operations, constraints, filters |
|---|---|
| `tests/db.test.js` | SQLite data layer — CRUD, constraints, filters, history logging |
| `tests/api.test.js` | HTTP API — all endpoints, status codes, error cases |
| `tests/helpers.test.js` | UI helper functions — `esc()` XSS contract, `fmtDate()` |
| `tests/helpers.test.js` | UI helpers — `esc()` XSS contract, date formatting, history formatters |
---
## Versioning
Catalyst uses [semantic versioning](https://semver.org). `package.json` is the single source of truth for the version number.
Catalyst uses [semantic versioning](https://semver.org). `package.json` is the single source of truth.
| Change | Bump | Example |
|--------|------|---------|
| Bug fix | patch | `1.0.0``1.0.1` |
| New feature, backward compatible | minor | `1.0.0``1.1.0` |
| Breaking change | major | `1.0.0``2.0.0` |
| Change | Bump |
|---|---|
| Bug fix | patch |
| New feature, backward compatible | minor |
| Breaking change | major |
### Cutting a release
```bash
# 1. Bump version in package.json, then:
git add package.json
git commit -m "chore: release v1.1.0"
git tag v1.1.0
git push && git push --tags
```
Pushing a tag triggers the full CI pipeline: **test → build → release**.
- Docker image tagged `:1.1.0`, `:1.1`, and `:latest` in the Gitea registry
- A Gitea release is created at `v1.1.0`
Pushing a tag triggers the CI pipeline: **test → build → release**.
Docker images are tagged `:x.y.z`, `:x.y`, and `:latest`.

View File

@@ -25,6 +25,10 @@
--mono: 'JetBrains Mono', 'IBM Plex Mono', monospace;
}
html {
zoom: 1.1;
}
html, body {
height: 100%;
background: var(--bg);
@@ -70,6 +74,19 @@ nav {
.nav-sep { flex: 1; }
.nav-btn {
background: none;
border: 1px solid var(--border2);
color: var(--text2);
border-radius: 6px;
padding: 4px 8px;
font-size: 14px;
cursor: pointer;
margin-left: 10px;
line-height: 1;
}
.nav-btn:hover { border-color: var(--accent); color: var(--accent); }
.nav-divider { color: var(--border2); }
.nav-status {
@@ -361,16 +378,25 @@ select:focus { border-color: var(--accent); }
}
.detail-sub {
font-size: 12px;
color: var(--text3);
margin-top: 6px;
font-size: 13px;
margin-top: 8px;
display: flex;
gap: 16px;
align-items: center;
gap: 0;
}
.detail-sub span { display: flex; gap: 4px; }
.detail-sub .lbl { color: var(--text3); }
.detail-sub .val { color: var(--text2); }
.detail-sub > span {
display: flex;
align-items: center;
gap: 6px;
}
.detail-sub > span + span {
margin-left: 12px;
padding-left: 12px;
border-left: 1px solid var(--border);
}
.detail-sub .lbl { color: var(--text3); font-size: 11px; }
.detail-sub .val { color: var(--text); }
.detail-actions { display: flex; gap: 8px; }
@@ -615,6 +641,58 @@ select:focus { border-color: var(--accent); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
/* ── HISTORY TIMELINE ── */
.tl-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 9px 0;
border-bottom: 1px solid var(--border);
}
.tl-item:last-child { border-bottom: none; }
.tl-event { display: flex; align-items: center; gap: 7px; font-size: 13px; min-width: 0; }
.tl-label { color: var(--text2); }
.tl-sep { color: var(--text3); user-select: none; }
.tl-old { color: var(--text3); text-decoration: line-through; font-size: 12px; }
.tl-arrow { color: var(--text3); font-size: 11px; }
.tl-new { color: var(--text); font-weight: 500; }
.tl-time { color: var(--text3); font-size: 11px; white-space: nowrap; flex-shrink: 0; }
.tl-deployed { color: var(--accent); }
.tl-testing { color: var(--amber); }
.tl-degraded { color: var(--red); }
.tl-created .tl-event { color: var(--accent); font-weight: 500; }
.tl-empty { color: var(--text3); font-size: 12px; padding: 8px 0; }
/* ── SETTINGS MODAL ── */
#settings-modal .modal-body { padding-top: 0; }
.settings-section { padding: 16px 0; border-bottom: 1px solid var(--border); }
.settings-section:last-child { border-bottom: none; padding-bottom: 0; }
.settings-section-title {
font-size: 10px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.1em;
color: var(--text3);
margin-bottom: 8px;
}
.settings-desc { font-size: 12px; color: var(--text2); margin: 0 0 14px; line-height: 1.6; }
.settings-row { display: flex; align-items: center; gap: 12px; }
.settings-label { font-size: 13px; color: var(--text2); white-space: nowrap; min-width: 80px; }
.settings-select { flex: 1; }
.import-row { display: flex; gap: 10px; align-items: center; }
.import-file-input { flex: 1; }
.btn-secondary {
background: var(--bg3);
border-color: var(--border2);
color: var(--text);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--red2); border-color: var(--red); color: var(--text); }
.btn-danger:hover { background: var(--red); }
/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }

View File

@@ -22,6 +22,7 @@
<span class="nav-divider">·</span>
<span id="nav-version"></span>
</div>
<button class="nav-btn" onclick="openSettingsModal()" title="Settings">&#9881;</button>
</nav>
<main>
@@ -91,7 +92,7 @@
<div class="services-grid" id="detail-services"></div>
</div>
<div class="detail-section full">
<div class="section-title">timestamps</div>
<div class="section-title">history</div>
<div id="detail-timestamps"></div>
</div>
</div>
@@ -171,6 +172,38 @@
</div>
</div>
<!-- SETTINGS MODAL -->
<div id="settings-modal" class="modal-overlay">
<div class="modal">
<div class="modal-header">
<span class="modal-title">Settings</span>
<button class="modal-close" onclick="closeSettingsModal()">&#x2715;</button>
</div>
<div class="modal-body">
<div class="settings-section">
<div class="settings-section-title">Display</div>
<div class="settings-row">
<label class="settings-label" for="tz-select">Timezone</label>
<select id="tz-select" class="form-input settings-select"></select>
</div>
</div>
<div class="settings-section">
<div class="settings-section-title">Export</div>
<p class="settings-desc">Download all instance data as a JSON backup file.</p>
<button class="btn btn-secondary" onclick="exportDB()">Export Database</button>
</div>
<div class="settings-section">
<div class="settings-section-title">Import</div>
<p class="settings-desc">Restore from a backup file. This replaces all current instances.</p>
<div class="import-row">
<input type="file" id="import-file" accept=".json" class="form-input import-file-input">
<button class="btn btn-danger" onclick="importDB()">Import</button>
</div>
</div>
</div>
</div>
</div>
<!-- TOAST -->
<div class="toast" id="toast">
<div class="toast-dot"></div>

View File

@@ -55,3 +55,8 @@ async function updateInstance(vmid, data) {
async function deleteInstance(vmid) {
await api(`/instances/${vmid}`, { method: 'DELETE' });
}
async function getInstanceHistory(vmid) {
const res = await fetch(`${BASE}/instances/${vmid}/history`);
return res.json();
}

172
js/ui.js
View File

@@ -3,6 +3,34 @@ let editingVmid = null;
let currentVmid = null;
let toastTimer = null;
// ── Timezone ──────────────────────────────────────────────────────────────────
const TIMEZONES = [
{ label: 'UTC', tz: 'UTC' },
{ label: 'Hawaii (HST)', tz: 'Pacific/Honolulu' },
{ label: 'Alaska (AKT)', tz: 'America/Anchorage' },
{ label: 'Pacific (PT)', tz: 'America/Los_Angeles' },
{ label: 'Mountain (MT)', tz: 'America/Denver' },
{ label: 'Central (CT)', tz: 'America/Chicago' },
{ label: 'Eastern (ET)', tz: 'America/New_York' },
{ label: 'Atlantic (AT)', tz: 'America/Halifax' },
{ label: 'London (GMT/BST)', tz: 'Europe/London' },
{ label: 'Paris / Berlin (CET)', tz: 'Europe/Paris' },
{ label: 'Helsinki (EET)', tz: 'Europe/Helsinki' },
{ label: 'Istanbul (TRT)', tz: 'Europe/Istanbul' },
{ label: 'Dubai (GST)', tz: 'Asia/Dubai' },
{ label: 'India (IST)', tz: 'Asia/Kolkata' },
{ label: 'Singapore (SGT)', tz: 'Asia/Singapore' },
{ label: 'China (CST)', tz: 'Asia/Shanghai' },
{ label: 'Japan / Korea (JST/KST)', tz: 'Asia/Tokyo' },
{ label: 'Sydney (AEST)', tz: 'Australia/Sydney' },
{ label: 'Auckland (NZST)', tz: 'Pacific/Auckland' },
];
function getTimezone() {
return localStorage.getItem('catalyst_tz') || 'UTC';
}
// ── Helpers ───────────────────────────────────────────────────────────────────
function esc(str) {
@@ -11,17 +39,25 @@ function esc(str) {
return d.innerHTML;
}
// SQLite datetime('now') → 'YYYY-MM-DD HH:MM:SS' (UTC, no timezone marker).
// Appending 'Z' tells JS to parse it as UTC rather than local time.
function parseUtc(d) {
if (typeof d !== 'string') return new Date(d);
const hasZone = d.endsWith('Z') || /[+-]\d{2}:\d{2}$/.test(d);
return new Date(hasZone ? d : d.replace(' ', 'T') + 'Z');
}
function fmtDate(d) {
if (!d) return '—';
try {
return new Date(d).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
return parseUtc(d).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', timeZone: getTimezone() });
} catch (e) { return d; }
}
function fmtDateFull(d) {
if (!d) return '—';
try {
return new Date(d).toLocaleString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
return parseUtc(d).toLocaleString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', timeZone: getTimezone(), timeZoneName: 'short' });
} catch (e) { return d; }
}
@@ -39,7 +75,6 @@ async function renderDashboard() {
<div class="stat-cell"><div class="stat-label">deployed</div><div class="stat-value">${states['deployed'] || 0}</div></div>
<div class="stat-cell"><div class="stat-label">testing</div><div class="stat-value amber">${states['testing'] || 0}</div></div>
<div class="stat-cell"><div class="stat-label">degraded</div><div class="stat-value red">${states['degraded'] || 0}</div></div>
<div class="stat-cell"><div class="stat-label">stacks</div><div class="stat-value">${(await getDistinctStacks()).length}</div></div>
`;
await populateStackFilter();
@@ -100,10 +135,39 @@ async function filterInstances() {
// ── Detail Page ───────────────────────────────────────────────────────────────
const BOOL_FIELDS = ['atlas','argus','semaphore','patchmon','tailscale','andromeda','hardware_acceleration'];
const FIELD_LABELS = {
name: 'name',
state: 'state',
stack: 'stack',
vmid: 'vmid',
tailscale_ip: 'tailscale ip',
atlas: 'atlas',
argus: 'argus',
semaphore: 'semaphore',
patchmon: 'patchmon',
tailscale: 'tailscale',
andromeda: 'andromeda',
hardware_acceleration: 'hw acceleration',
};
function stateClass(field, val) {
if (field !== 'state') return '';
return { deployed: 'tl-deployed', testing: 'tl-testing', degraded: 'tl-degraded' }[val] ?? '';
}
function fmtHistVal(field, val) {
if (val == null || val === '') return '—';
if (BOOL_FIELDS.includes(field)) return val === '1' ? 'on' : 'off';
return esc(val);
}
async function renderDetailPage(vmid) {
const inst = await getInstance(vmid);
const [inst, history, all] = await Promise.all([getInstance(vmid), getInstanceHistory(vmid), getInstances()]);
if (!inst) { navigate('dashboard'); return; }
currentVmid = vmid;
document.getElementById('nav-count').textContent = `${all.length} instance${all.length !== 1 ? 's' : ''}`;
document.getElementById('detail-vmid-crumb').textContent = vmid;
document.getElementById('detail-name').textContent = inst.name;
@@ -114,7 +178,7 @@ async function renderDetailPage(vmid) {
document.getElementById('detail-identity').innerHTML = `
<div class="kv-row"><span class="kv-key">name</span><span class="kv-val highlight">${esc(inst.name)}</span></div>
<div class="kv-row"><span class="kv-key">state</span><span class="kv-val"><span class="badge ${esc(inst.state)}">${esc(inst.state)}</span></span></div>
<div class="kv-row"><span class="kv-key">stack</span><span class="kv-val highlight">${esc(inst.stack) || '—'}</span></div>
<div class="kv-row"><span class="kv-key">stack</span><span class="kv-val"><span class="badge ${esc(inst.stack)}">${esc(inst.stack) || '—'}</span></span></div>
<div class="kv-row"><span class="kv-key">vmid</span><span class="kv-val highlight">${inst.vmid}</span></div>
<div class="kv-row"><span class="kv-key">internal id</span><span class="kv-val">${inst.id}</span></div>
`;
@@ -134,10 +198,30 @@ async function renderDetailPage(vmid) {
</div>
`).join('');
document.getElementById('detail-timestamps').innerHTML = `
<div class="kv-row"><span class="kv-key">created</span><span class="kv-val">${fmtDateFull(inst.created_at)}</span></div>
<div class="kv-row"><span class="kv-key">updated</span><span class="kv-val">${fmtDateFull(inst.updated_at)}</span></div>
`;
document.getElementById('detail-timestamps').innerHTML = history.length
? history.map(e => {
if (e.field === 'created') return `
<div class="tl-item tl-created">
<span class="tl-event">instance created</span>
<span class="tl-time">${fmtDateFull(e.changed_at)}</span>
</div>`;
const label = FIELD_LABELS[e.field] ?? esc(e.field);
const newCls = (e.field === 'state' || e.field === 'stack')
? `badge ${esc(e.new_value)}`
: `tl-new ${stateClass(e.field, e.new_value)}`;
return `
<div class="tl-item">
<div class="tl-event">
<span class="tl-label">${label}</span>
<span class="tl-sep">·</span>
<span class="tl-old">${fmtHistVal(e.field, e.old_value)}</span>
<span class="tl-arrow">→</span>
<span class="${newCls}">${fmtHistVal(e.field, e.new_value)}</span>
</div>
<span class="tl-time">${fmtDateFull(e.changed_at)}</span>
</div>`;
}).join('')
: '<div class="tl-empty">no history yet</div>';
document.getElementById('detail-edit-btn').onclick = () => openEditModal(inst.vmid);
document.getElementById('detail-delete-btn').onclick = () => confirmDeleteDialog(inst);
@@ -258,12 +342,72 @@ function showToast(msg, type = 'success') {
toastTimer = setTimeout(() => t.classList.remove('show'), 3000);
}
// ── Settings Modal ────────────────────────────────────────────────────────────
function openSettingsModal() {
const sel = document.getElementById('tz-select');
if (!sel.options.length) {
for (const { label, tz } of TIMEZONES) {
const opt = document.createElement('option');
opt.value = tz;
opt.textContent = label;
sel.appendChild(opt);
}
}
sel.value = getTimezone();
document.getElementById('settings-modal').classList.add('open');
}
function closeSettingsModal() {
document.getElementById('settings-modal').classList.remove('open');
document.getElementById('import-file').value = '';
}
async function exportDB() {
const res = await fetch('/api/export');
const blob = await res.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `catalyst-backup-${new Date().toISOString().slice(0, 10)}.json`;
a.click();
URL.revokeObjectURL(url);
}
async function importDB() {
const file = document.getElementById('import-file').files[0];
if (!file) { showToast('Select a backup file first', 'error'); return; }
document.getElementById('confirm-title').textContent = 'Replace all instances?';
document.getElementById('confirm-msg').textContent =
`This will delete all current instances and replace them with the contents of "${file.name}". This cannot be undone.`;
document.getElementById('confirm-overlay').classList.add('open');
document.getElementById('confirm-ok').onclick = async () => {
closeConfirm();
try {
const { instances } = JSON.parse(await file.text());
const res = await fetch('/api/import', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ instances }),
});
const data = await res.json();
if (!res.ok) { showToast(data.error ?? 'Import failed', 'error'); return; }
showToast(`Imported ${data.imported} instance${data.imported !== 1 ? 's' : ''}`, 'success');
closeSettingsModal();
renderDashboard();
} catch {
showToast('Invalid backup file', 'error');
}
};
}
// ── Keyboard / backdrop ───────────────────────────────────────────────────────
document.addEventListener('keydown', e => {
if (e.key !== 'Escape') return;
if (document.getElementById('instance-modal').classList.contains('open')) { closeModal(); return; }
if (document.getElementById('confirm-overlay').classList.contains('open')) { closeConfirm(); return; }
if (document.getElementById('settings-modal').classList.contains('open')) { closeSettingsModal(); return; }
});
document.getElementById('instance-modal').addEventListener('click', e => {
@@ -272,3 +416,13 @@ document.getElementById('instance-modal').addEventListener('click', e => {
document.getElementById('confirm-overlay').addEventListener('click', e => {
if (e.target === document.getElementById('confirm-overlay')) closeConfirm();
});
document.getElementById('settings-modal').addEventListener('click', e => {
if (e.target === document.getElementById('settings-modal')) closeSettingsModal();
});
document.getElementById('tz-select').addEventListener('change', e => {
localStorage.setItem('catalyst_tz', e.target.value);
const m = window.location.pathname.match(/^\/instance\/(\d+)/);
if (m) renderDetailPage(parseInt(m[1], 10));
else renderDashboard();
});

1
js/version.js Normal file
View File

@@ -0,0 +1 @@
const VERSION = "1.3.1";

View File

@@ -1,6 +1,6 @@
{
"name": "catalyst",
"version": "1.2.0",
"version": "1.3.1",
"type": "module",
"scripts": {
"start": "node server/server.js",

View File

@@ -43,6 +43,16 @@ function createSchema() {
);
CREATE INDEX IF NOT EXISTS idx_instances_state ON instances(state);
CREATE INDEX IF NOT EXISTS idx_instances_stack ON instances(stack);
CREATE TABLE IF NOT EXISTS instance_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
vmid INTEGER NOT NULL,
field TEXT NOT NULL,
old_value TEXT,
new_value TEXT,
changed_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_history_vmid ON instance_history(vmid);
`);
}
@@ -99,8 +109,14 @@ export function getDistinctStacks() {
// ── Mutations ─────────────────────────────────────────────────────────────────
const HISTORY_FIELDS = [
'name', 'state', 'stack', 'vmid', 'tailscale_ip',
'atlas', 'argus', 'semaphore', 'patchmon', 'tailscale', 'andromeda',
'hardware_acceleration',
];
export function createInstance(data) {
return db.prepare(`
db.prepare(`
INSERT INTO instances
(name, state, stack, vmid, atlas, argus, semaphore, patchmon,
tailscale, andromeda, tailscale_ip, hardware_acceleration)
@@ -108,10 +124,14 @@ export function createInstance(data) {
(@name, @state, @stack, @vmid, @atlas, @argus, @semaphore, @patchmon,
@tailscale, @andromeda, @tailscale_ip, @hardware_acceleration)
`).run(data);
db.prepare(
`INSERT INTO instance_history (vmid, field, old_value, new_value) VALUES (?, 'created', NULL, NULL)`
).run(data.vmid);
}
export function updateInstance(vmid, data) {
return db.prepare(`
const old = getInstance(vmid);
db.prepare(`
UPDATE instances SET
name=@name, state=@state, stack=@stack, vmid=@newVmid,
atlas=@atlas, argus=@argus, semaphore=@semaphore, patchmon=@patchmon,
@@ -119,10 +139,42 @@ export function updateInstance(vmid, data) {
hardware_acceleration=@hardware_acceleration, updated_at=datetime('now')
WHERE vmid=@vmid
`).run({ ...data, newVmid: data.vmid, vmid });
const newVmid = data.vmid;
const insertEvt = db.prepare(
`INSERT INTO instance_history (vmid, field, old_value, new_value) VALUES (?, ?, ?, ?)`
);
for (const field of HISTORY_FIELDS) {
const oldVal = String(old[field] ?? '');
const newVal = String(field === 'vmid' ? newVmid : (data[field] ?? ''));
if (oldVal !== newVal) insertEvt.run(newVmid, field, oldVal, newVal);
}
}
export function deleteInstance(vmid) {
return db.prepare('DELETE FROM instances WHERE vmid = ?').run(vmid);
db.prepare('DELETE FROM instance_history WHERE vmid = ?').run(vmid);
db.prepare('DELETE FROM instances WHERE vmid = ?').run(vmid);
}
export function importInstances(rows) {
db.exec('BEGIN');
db.exec('DELETE FROM instance_history');
db.exec('DELETE FROM instances');
const insert = db.prepare(`
INSERT INTO instances
(name, state, stack, vmid, atlas, argus, semaphore, patchmon,
tailscale, andromeda, tailscale_ip, hardware_acceleration)
VALUES
(@name, @state, @stack, @vmid, @atlas, @argus, @semaphore, @patchmon,
@tailscale, @andromeda, @tailscale_ip, @hardware_acceleration)
`);
for (const row of rows) insert.run(row);
db.exec('COMMIT');
}
export function getInstanceHistory(vmid) {
return db.prepare(
'SELECT * FROM instance_history WHERE vmid = ? ORDER BY changed_at DESC'
).all(vmid);
}
// ── Test helpers ──────────────────────────────────────────────────────────────

View File

@@ -1,7 +1,7 @@
import { Router } from 'express';
import {
getInstances, getInstance, getDistinctStacks,
createInstance, updateInstance, deleteInstance,
createInstance, updateInstance, deleteInstance, importInstances, getInstanceHistory,
} from './db.js';
export const router = Router();
@@ -28,9 +28,16 @@ function validate(body) {
return errors;
}
function handleDbError(context, e, res) {
if (e.message.includes('UNIQUE')) return res.status(409).json({ error: 'vmid already exists' });
if (e.message.includes('CHECK')) return res.status(400).json({ error: 'invalid field value' });
console.error(context, e);
res.status(500).json({ error: 'internal server error' });
}
function normalise(body) {
const row = {
name: body.name.trim(),
name: (body.name ?? '').trim(),
state: body.state,
stack: body.stack,
vmid: body.vmid,
@@ -54,6 +61,14 @@ router.get('/instances', (req, res) => {
res.json(getInstances({ search, state, stack }));
});
// GET /api/instances/:vmid/history
router.get('/instances/:vmid/history', (req, res) => {
const vmid = parseInt(req.params.vmid, 10);
if (!vmid) return res.status(400).json({ error: 'invalid vmid' });
if (!getInstance(vmid)) return res.status(404).json({ error: 'instance not found' });
res.json(getInstanceHistory(vmid));
});
// GET /api/instances/:vmid
router.get('/instances/:vmid', (req, res) => {
const vmid = parseInt(req.params.vmid, 10);
@@ -76,10 +91,7 @@ router.post('/instances', (req, res) => {
const created = getInstance(data.vmid);
res.status(201).json(created);
} catch (e) {
if (e.message.includes('UNIQUE')) return res.status(409).json({ error: 'vmid already exists' });
if (e.message.includes('CHECK')) return res.status(400).json({ error: 'invalid field value' });
console.error('POST /api/instances', e);
res.status(500).json({ error: 'internal server error' });
handleDbError('POST /api/instances', e, res);
}
});
@@ -97,9 +109,35 @@ router.put('/instances/:vmid', (req, res) => {
updateInstance(vmid, data);
res.json(getInstance(data.vmid));
} catch (e) {
if (e.message.includes('UNIQUE')) return res.status(409).json({ error: 'vmid already exists' });
if (e.message.includes('CHECK')) return res.status(400).json({ error: 'invalid field value' });
console.error('PUT /api/instances/:vmid', e);
handleDbError('PUT /api/instances/:vmid', e, res);
}
});
// GET /api/export
router.get('/export', (_req, res) => {
const instances = getInstances();
const date = new Date().toISOString().slice(0, 10);
res.setHeader('Content-Disposition', `attachment; filename="catalyst-backup-${date}.json"`);
res.json({ version: 1, exported_at: new Date().toISOString(), instances });
});
// POST /api/import
router.post('/import', (req, res) => {
const { instances } = req.body ?? {};
if (!Array.isArray(instances)) {
return res.status(400).json({ error: 'body must contain an instances array' });
}
const errors = [];
for (const [i, row] of instances.entries()) {
const errs = validate(normalise(row));
if (errs.length) errors.push({ index: i, errors: errs });
}
if (errors.length) return res.status(400).json({ errors });
try {
importInstances(instances.map(normalise));
res.json({ imported: instances.length });
} catch (e) {
console.error('POST /api/import', e);
res.status(500).json({ error: 'internal server error' });
}
});
@@ -118,7 +156,6 @@ router.delete('/instances/:vmid', (req, res) => {
deleteInstance(vmid);
res.status(204).end();
} catch (e) {
console.error('DELETE /api/instances/:vmid', e);
res.status(500).json({ error: 'internal server error' });
handleDbError('DELETE /api/instances/:vmid', e, res);
}
});

View File

@@ -239,6 +239,78 @@ describe('DELETE /api/instances/:vmid', () => {
})
})
// ── GET /api/instances/:vmid/history ─────────────────────────────────────────
describe('GET /api/instances/:vmid/history', () => {
it('returns history events for a known vmid', async () => {
await request(app).post('/api/instances').send(base)
const res = await request(app).get('/api/instances/100/history')
expect(res.status).toBe(200)
expect(res.body).toBeInstanceOf(Array)
expect(res.body[0].field).toBe('created')
})
it('returns 404 for unknown vmid', async () => {
expect((await request(app).get('/api/instances/999/history')).status).toBe(404)
})
it('returns 400 for non-numeric vmid', async () => {
expect((await request(app).get('/api/instances/abc/history')).status).toBe(400)
})
})
// ── GET /api/export ───────────────────────────────────────────────────────────
describe('GET /api/export', () => {
it('returns 200 with instances array and attachment header', async () => {
await request(app).post('/api/instances').send(base)
const res = await request(app).get('/api/export')
expect(res.status).toBe(200)
expect(res.headers['content-disposition']).toMatch(/attachment/)
expect(res.body.instances).toHaveLength(1)
expect(res.body.instances[0].name).toBe('traefik')
})
it('returns empty instances array when no data', async () => {
const res = await request(app).get('/api/export')
expect(res.body.instances).toEqual([])
})
})
// ── POST /api/import ──────────────────────────────────────────────────────────
describe('POST /api/import', () => {
it('replaces all instances and returns imported count', async () => {
await request(app).post('/api/instances').send(base)
const res = await request(app).post('/api/import')
.send({ instances: [{ ...base, vmid: 999, name: 'imported' }] })
expect(res.status).toBe(200)
expect(res.body.imported).toBe(1)
expect((await request(app).get('/api/instances')).body[0].name).toBe('imported')
})
it('returns 400 if instances is not an array', async () => {
expect((await request(app).post('/api/import').send({ instances: 'bad' })).status).toBe(400)
})
it('returns 400 with per-row errors for invalid rows', async () => {
const res = await request(app).post('/api/import')
.send({ instances: [{ ...base, name: '', vmid: 1 }] })
expect(res.status).toBe(400)
expect(res.body.errors[0].index).toBe(0)
})
it('returns 400 if body has no instances key', async () => {
expect((await request(app).post('/api/import').send({})).status).toBe(400)
})
it('returns 400 (not 500) when a row is missing name', async () => {
const res = await request(app).post('/api/import')
.send({ instances: [{ ...base, name: undefined, vmid: 1 }] })
expect(res.status).toBe(400)
})
})
// ── Static assets & SPA routing ───────────────────────────────────────────────
describe('static assets and SPA routing', () => {

View File

@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from 'vitest'
import {
_resetForTest,
getInstances, getInstance, getDistinctStacks,
createInstance, updateInstance, deleteInstance,
createInstance, updateInstance, deleteInstance, importInstances, getInstanceHistory,
} from '../server/db.js'
beforeEach(() => _resetForTest());
@@ -164,6 +164,81 @@ describe('deleteInstance', () => {
expect(getInstance(1)).toBeNull();
expect(getInstance(2)).not.toBeNull();
});
it('clears history for the deleted instance', () => {
createInstance({ ...base, name: 'a', vmid: 1 });
deleteInstance(1);
expect(getInstanceHistory(1)).toHaveLength(0);
});
it('does not clear history for other instances', () => {
createInstance({ ...base, name: 'a', vmid: 1 });
createInstance({ ...base, name: 'b', vmid: 2 });
deleteInstance(1);
expect(getInstanceHistory(2).length).toBeGreaterThan(0);
});
});
// ── importInstances ───────────────────────────────────────────────────────────
describe('importInstances', () => {
const base = { state: 'deployed', stack: 'production', atlas: 0, argus: 0, semaphore: 0, patchmon: 0, tailscale: 0, andromeda: 0, tailscale_ip: '', hardware_acceleration: 0 };
it('replaces all existing instances with the imported set', () => {
createInstance({ ...base, name: 'old', vmid: 1 });
importInstances([{ ...base, name: 'new', vmid: 2 }]);
expect(getInstance(1)).toBeNull();
expect(getInstance(2)).not.toBeNull();
});
it('clears all instances when passed an empty array', () => {
createInstance({ ...base, name: 'a', vmid: 1 });
importInstances([]);
expect(getInstances()).toEqual([]);
});
it('clears history for all replaced instances', () => {
createInstance({ ...base, name: 'old', vmid: 1 });
importInstances([{ ...base, name: 'new', vmid: 2 }]);
expect(getInstanceHistory(1)).toHaveLength(0);
});
});
// ── instance history ─────────────────────────────────────────────────────────
describe('instance history', () => {
const base = { state: 'deployed', stack: 'production', atlas: 0, argus: 0, semaphore: 0, patchmon: 0, tailscale: 0, andromeda: 0, tailscale_ip: '', hardware_acceleration: 0 };
it('logs a created event when an instance is created', () => {
createInstance({ ...base, name: 'a', vmid: 1 });
const h = getInstanceHistory(1);
expect(h).toHaveLength(1);
expect(h[0].field).toBe('created');
});
it('logs changed fields when an instance is updated', () => {
createInstance({ ...base, name: 'a', vmid: 1 });
updateInstance(1, { ...base, name: 'a', vmid: 1, state: 'degraded' });
const h = getInstanceHistory(1);
const stateEvt = h.find(e => e.field === 'state');
expect(stateEvt).toBeDefined();
expect(stateEvt.old_value).toBe('deployed');
expect(stateEvt.new_value).toBe('degraded');
});
it('logs no events when nothing changes on update', () => {
createInstance({ ...base, name: 'a', vmid: 1 });
updateInstance(1, { ...base, name: 'a', vmid: 1 });
const h = getInstanceHistory(1).filter(e => e.field !== 'created');
expect(h).toHaveLength(0);
});
it('records history under the new vmid when vmid changes', () => {
createInstance({ ...base, name: 'a', vmid: 1 });
updateInstance(1, { ...base, name: 'a', vmid: 2 });
expect(getInstanceHistory(2).some(e => e.field === 'vmid')).toBe(true);
expect(getInstanceHistory(1).filter(e => e.field !== 'created')).toHaveLength(0);
});
});
// ── Test environment boot isolation ───────────────────────────────────────────

View File

@@ -58,16 +58,22 @@ describe('esc', () => {
// ── fmtDate() ─────────────────────────────────────────────────────────────────
function fmtDate(d) {
function parseUtc(d) {
if (typeof d !== 'string') return new Date(d)
const hasZone = d.endsWith('Z') || /[+-]\d{2}:\d{2}$/.test(d)
return new Date(hasZone ? d : d.replace(' ', 'T') + 'Z')
}
function fmtDate(d, tz = 'UTC') {
if (!d) return '—'
try {
return new Date(d).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' })
return parseUtc(d).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', timeZone: tz })
} catch (e) { return d }
}
describe('fmtDate', () => {
it('formats a valid ISO date string', () => {
const result = fmtDate('2024-03-15T00:00:00')
const result = fmtDate('2024-03-15T12:00:00Z')
expect(result).toMatch(/Mar/)
expect(result).toMatch(/15/)
expect(result).toMatch(/2024/)
@@ -88,24 +94,42 @@ describe('fmtDate', () => {
// ── fmtDateFull() ─────────────────────────────────────────────────────────────
function fmtDateFull(d) {
function fmtDateFull(d, tz = 'UTC') {
if (!d) return '—'
try {
return new Date(d).toLocaleString('en-US', {
return parseUtc(d).toLocaleString('en-US', {
year: 'numeric', month: 'short', day: 'numeric',
hour: '2-digit', minute: '2-digit',
timeZone: tz, timeZoneName: 'short',
})
} catch (e) { return d }
}
describe('fmtDateFull', () => {
it('includes date and time components', () => {
const result = fmtDateFull('2024-03-15T14:30:00')
const result = fmtDateFull('2024-03-15T14:30:00Z')
expect(result).toMatch(/Mar/)
expect(result).toMatch(/2024/)
expect(result).toMatch(/\d{1,2}:\d{2}/)
})
it('includes the timezone abbreviation', () => {
expect(fmtDateFull('2024-03-15T14:30:00Z', 'UTC')).toMatch(/UTC/)
})
it('converts to the given timezone', () => {
// 2024-03-15 18:30 UTC = 2024-03-15 14:30 EDT (UTC-4 in March)
const result = fmtDateFull('2024-03-15T18:30:00Z', 'America/New_York')
expect(result).toMatch(/2:30/)
expect(result).toMatch(/EDT/)
})
it('treats SQLite-format timestamps (space, no Z) as UTC', () => {
// SQLite datetime('now') → 'YYYY-MM-DD HH:MM:SS', no timezone marker.
// Must parse identically to the same moment expressed as ISO UTC.
expect(fmtDateFull('2024-03-15 18:30:00', 'UTC')).toBe(fmtDateFull('2024-03-15T18:30:00Z', 'UTC'))
})
it('returns — for null', () => {
expect(fmtDateFull(null)).toBe('—')
})
@@ -133,6 +157,64 @@ describe('version label formatting', () => {
})
})
// ── fmtHistVal() ─────────────────────────────────────────────────────────────
// Mirrors the logic in ui.js — formats history field values for display.
const BOOL_FIELDS = ['atlas','argus','semaphore','patchmon','tailscale','andromeda','hardware_acceleration']
function fmtHistVal(field, val) {
if (val == null || val === '') return '—'
if (BOOL_FIELDS.includes(field)) return val === '1' ? 'on' : 'off'
return val
}
describe('fmtHistVal', () => {
it('returns — for null', () => {
expect(fmtHistVal('state', null)).toBe('—')
})
it('returns — for empty string', () => {
expect(fmtHistVal('state', '')).toBe('—')
})
it('returns on/off for boolean service fields', () => {
expect(fmtHistVal('atlas', '1')).toBe('on')
expect(fmtHistVal('atlas', '0')).toBe('off')
expect(fmtHistVal('hardware_acceleration', '1')).toBe('on')
})
it('returns the value as-is for non-boolean fields', () => {
expect(fmtHistVal('state', 'deployed')).toBe('deployed')
expect(fmtHistVal('name', 'plex')).toBe('plex')
expect(fmtHistVal('tailscale_ip', '100.64.0.1')).toBe('100.64.0.1')
})
})
// ── stateClass() ─────────────────────────────────────────────────────────────
// Mirrors the logic in ui.js — maps state values to timeline CSS classes.
function stateClass(field, val) {
if (field !== 'state') return ''
return { deployed: 'tl-deployed', testing: 'tl-testing', degraded: 'tl-degraded' }[val] ?? ''
}
describe('stateClass', () => {
it('returns empty string for non-state fields', () => {
expect(stateClass('name', 'plex')).toBe('')
expect(stateClass('stack', 'production')).toBe('')
})
it('returns the correct colour class for each state value', () => {
expect(stateClass('state', 'deployed')).toBe('tl-deployed')
expect(stateClass('state', 'testing')).toBe('tl-testing')
expect(stateClass('state', 'degraded')).toBe('tl-degraded')
})
it('returns empty string for unknown state values', () => {
expect(stateClass('state', 'unknown')).toBe('')
})
})
// ── CSS regressions ───────────────────────────────────────────────────────────
const css = readFileSync(join(__dirname, '../css/app.css'), 'utf8')