Skip to content

deploy: attribution, overwrite protection, and view metrics#10

Merged
sdelcore merged 2 commits into
mainfrom
deploy-attribution-and-metrics
Jul 15, 2026
Merged

deploy: attribution, overwrite protection, and view metrics#10
sdelcore merged 2 commits into
mainfrom
deploy-attribution-and-metrics

Conversation

@sdelcore

Copy link
Copy Markdown
Owner

Why

Deploys were anonymous and last-write-wins: nothing recorded who deployed a site, and deploying from a stale checkout silently clobbered someone else's (or your own other machine's) newer deploy. There was also no usage signal at all — no way to tell if a site is ever visited or how often it changes.

This borrows the pattern used by Wrangler / Theme Kit / git push --force-with-lease: record identity+source per deploy, do a compare-and-swap on "which version do you think you're replacing", and name the conflicting deployer in the warning.

What

Attribution — the CLI sends X-Shared-Deployer: user@hostname; every deploy and rollback is recorded (seq, time, deployer, source) in a new per-site meta/<site>.json (history capped at 50). Shown in shared list, shared versions (as current), and GET /api/sites.

Overwrite protection — the CLI remembers the last deployed version in .shared/state.json (dotfiles are never uploaded) and sends X-Shared-Prev-Version. On mismatch the server answers 409 with the conflicting deployer's identity and the CLI prompts:

hello was deployed by alice@dayman at 2026-07-14T23:40:23Z since your last deploy — overwrite? [y/N]

With no local state the CLI asks the server who deployed last and warns if it wasn't you. --force / X-Shared-Force: 1 skips the check; requests without a prev-version header (curl, older CLIs) are accepted unchecked, so nothing existing breaks.

View metricshandleStatic counts GETs of HTML documents (not assets/API) per site, batched in memory and flushed to meta every 30s with 30-day daily buckets. Totals appear in shared list, /api/sites, and the homepage cards.

Rate limiting is untouched (stays global via SHARED_AI_RATE), per earlier discussion.

Verified

Exercised end-to-end against a local server: attributed deploy, legacy curl deploy (unchecked, bumps seq), stale-state deploy → 409 → decline cancels / accept overwrites, fresh-checkout warning for a different user, rollback recorded with source: rollback, view counts visible immediately and persisted after the 30s flush with daily buckets. go vet, go test, cross-compile (linux/windows/darwin), and nix build all pass.

sdelcore added 2 commits July 14, 2026 19:42
Record who deployed (user@hostname via X-Shared-Deployer) and when in a
per-site meta/<site>.json, guard deploys with a force-with-lease style
version check (409 + interactive overwrite prompt, --force to skip), and
count per-site HTML page views with periodic flush. Views and last
deployer surface in shared list, shared versions, /api/sites, and the
homepage.
@sdelcore
sdelcore merged commit cd7de9f into main Jul 15, 2026
2 checks passed
@sdelcore
sdelcore deleted the deploy-attribution-and-metrics branch July 15, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant