feat: hostdoc insight <code> — CloudFront visit stats (#43, cloudfront slice) - #53
Open
jkas2016 wants to merge 13 commits into
Open
feat: hostdoc insight <code> — CloudFront visit stats (#43, cloudfront slice)#53jkas2016 wants to merge 13 commits into
jkas2016 wants to merge 13 commits into
Conversation
Design for the first vertical slice of `hostdoc insight <code>`: cloudfront mode end-to-end (v2 delivery-pipeline logging → dedicated log bucket with 30-day expiry → CLI-side gzip/W3C parse → per-code hits + approx unique visitors). Records the v1-vs-v2 decision (v2 chosen: ACL-free bucket-policy delivery fits hostdoc's hardened private OAC buckets) and the metric scope. Refs #43
TDD, bite-sized 8-task plan for the cloudfront insight slice: pure W3C parser (T1) + aggregation/log-key selection (T2), getObjectBytes (T3), config.logBucket + init import (T4), runInsight command (T5), CLI registration (T6), v2 logging Terraform (T7), README privacy/usage (T8). Refs #43
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
hostdoc insight <code>— per-document page-view hits + approximate unique visitors for cloudfront-mode sites, read from CloudFront standard-logging (v2) access logs provisioned in the user's own AWS. This is the cloudfront vertical slice of #43; s3-website and self-hosted are deferred to their own future slices.No HTML is modified (no JS beacon), no standing server/endpoint — logs live in the user's S3 and are parsed CLI-side.
Design
Spec:
docs/superpowers/specs/2026-07-11-cloudfront-insight-design.md· Plan:docs/superpowers/plans/2026-07-11-cloudfront-insight.mddelivery.logs.amazonaws.combucket policy. Partitioned{DistributionId}/{yyyy}/{MM}/{dd}/{HH}.#Fieldsmapping) → filter to/<code>/page views (.html//, assets excluded) → aggregate hits + unique client IPs (bots + non-2xx/3xx filtered).Changes
src/lib/cflog.ts(W3C parser),src/lib/insight.ts(aggregation + log-key date selection).src/lib/aws.ts:getObjectBytes(raw bytes for gzip).src/lib/config.ts+src/commands/init.ts: optional cloudfrontlogBucket, threaded through both cloudfrontresolveConfigbranches and imported from thelog_bucket_nameTerraform output (back-compat: legacy configs → clear re-provision hint).src/commands/insight.ts+src/index.ts:runInsight+insight <code>command (--days/--since).infra/: v2 delivery pipeline + private log bucket + lifecycle + output +log_retention_daysvar.README.md: usage + privacy notice (IPs stored only in the user's bucket, used only for unique approximation, minimal fields, 30-day expiry).Testing
test/cflog.test.ts,test/insight.test.ts,test/insight-command.test.ts, plustest/config.test.ts/test/init.test.tscases.npm run build+npm run typecheckclean.npx vitest run→ 342 passed / 3 skipped / 1 failed, where the single failure is the pre-existing environment-dependenttest/skill.test.tspreflight case (fails only when local AWS creds exist; unchanged onmain; passes in CI — this branch touches neither that test norpreflight.mjs).Verification boundary
infra/could not beterraform validated in CI (no Terraform); schemas verified against provider docs and the committed lock file (aws 6.51.0, which has theaws_cloudwatch_log_delivery*resources). A realterraform applyagainst an account is a manual pre/post-merge check — the one surface CI structurally can't cover.Follow-ups (tracked, non-blocking)
--days) scans the full ~30-day bucket;--days/--sincenarrow it.Refs #43
🤖 Generated with Claude Code