Skip to content

feat(codegen): wire logArchive from env so the Studio archive is turnkey - #156

Merged
prisis merged 3 commits into
alphafrom
feat/log-archive-codegen
Jul 21, 2026
Merged

feat(codegen): wire logArchive from env so the Studio archive is turnkey#156
prisis merged 3 commits into
alphafrom
feat/log-archive-codegen

Conversation

@prisis

@prisis prisis commented Jul 21, 2026

Copy link
Copy Markdown
Member

Closes the one actionable gap left after the durable-archive Studio feed (#155): the logArchive WorkerOption existed and the whole read path worked, but codegen never passed it through — so a Vite-first / scaffolded app couldn't reach the Studio's Logs → Archive feed without hand-editing generated code.

What changed

  • @lunora/runtime — new resolveLogArchiveFromEnv(env): builds the LogArchiveConfig from LUNORA_LOG_ARCHIVE_TABLE (+ optional LUNORA_LOG_ARCHIVE_NAMESPACE), mirroring how the R2 SQL credentials already come from env (R2_SQL_*). Returns undefined — so the feed stays "not configured" — until the operator names the table. (A columnMap override isn't env-expressible; a hand-written worker still passes logArchive to createWorker directly.)
  • @lunora/codegen — the generated worker entry now imports the helper and sets options.logArchive = resolveLogArchiveFromEnv(env) unconditionally, so every scaffolded app supports the archive by setting one env var. Golden fixture regenerated (only the import line + the one wiring line change).
  • Docs — the observability page now documents the env-var opt-in for the scaffolded flow, alongside the existing hand-written-worker example.

Result

Turnkey: set R2_SQL_ACCOUNT_ID / R2_SQL_TOKEN / R2_SQL_BUCKET + LUNORA_LOG_ARCHIVE_TABLE, and the Studio Archive tab lights up — no code edits.

Tests

  • @lunora/runtime: 4 new resolveLogArchiveFromEnv cases (unset → undefined, table→config, +namespace, empty/non-string/non-object rejected, empty-namespace dropped) + existing route suite. Full suite 575 green.
  • @lunora/codegen: golden snapshot regenerated + all variant emit tests. Full suite 838 green.
  • lint:types + eslint (--max-warnings=0) clean; API snapshots updated (additions only); repo-wide prettier clean.

Note: the examples/*/lunora/_generated files are intentionally not regenerated here — they carry pre-existing drift, aren't test-gated, and regenerating them would sweep unrelated changes into this PR. The test-gated golden fixture is updated. Examples can be refreshed in a separate hygiene commit.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • The Logs → Archive feed can now be enabled through environment-based configuration.
    • Scaffolded applications automatically connect the Archive feed when the archive table is configured.
    • Optional namespace settings are supported for archive data.
  • Documentation

    • Clarified configuration options for scaffolded and hand-written applications.
    • Documented credential handling and the Archive feed’s “not configured” state.
    • Clarified that live Requests and Errors feeds continue using the existing log data.

The `logArchive` WorkerOption existed but the generated worker entry never
passed it through, so a Vite-first / scaffolded app couldn't reach the Studio's
Logs → Archive feed without hand-editing generated code.

- `@lunora/runtime`: add `resolveLogArchiveFromEnv(env)` — builds the
  `LogArchiveConfig` from `LUNORA_LOG_ARCHIVE_TABLE` (+ optional
  `LUNORA_LOG_ARCHIVE_NAMESPACE`), mirroring how the `R2_SQL_*` credentials
  already come from env. Returns undefined (→ "not configured") until the
  operator names the table.
- `@lunora/codegen`: the generated worker entry now imports the helper and sets
  `options.logArchive = resolveLogArchiveFromEnv(env)` unconditionally, so every
  scaffolded app supports the archive by setting one env var. Golden fixture
  regenerated.
- Docs: document the env-var opt-in for the scaffolded flow.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0197KjhmBDB3PXAc6TXiPqZ9
@netlify

netlify Bot commented Jul 21, 2026

Copy link
Copy Markdown

Deploy Preview for lunorash ready!

Name Link
🔨 Latest commit 4fb1ea0
🔍 Latest deploy log https://app.netlify.com/projects/lunorash/deploys/6a5fbb9632744c00084accec
😎 Deploy Preview https://deploy-preview-156--lunorash.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for confirming the Contributor License Agreement! 🙏

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 006a6950-5618-46aa-8747-1c7b18d1be1a

📥 Commits

Reviewing files that changed from the base of the PR and between f073c2a and 6ca072f.

⛔ Files ignored due to path filters (4)
  • api-snapshots/lunora.api.md is excluded by none and included by none
  • api-snapshots/runtime.api.md is excluded by none and included by none
  • packages/codegen/__tests__/fixtures/simple/expected/_generated/app.ts is excluded by !**/_generated/**, !**/__tests__/** and included by packages/**
  • packages/runtime/__tests__/log-archive-admin.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
📒 Files selected for processing (4)
  • apps/docs/src/content/docs/concepts/observability.mdx
  • packages/codegen/src/emit-app.ts
  • packages/runtime/src/index.ts
  • packages/runtime/src/log-archive-admin-routes.ts

Walkthrough

The runtime adds environment-based durable archive configuration, generated workers pass it into logArchive, and observability documentation describes scaffolded, hand-written, credential, and unconfigured Archive-feed behavior.

Changes

Log archive configuration

Layer / File(s) Summary
Environment-based archive resolver
packages/runtime/src/log-archive-admin-routes.ts, packages/runtime/src/index.ts
Adds resolveLogArchiveFromEnv, which returns archive table and optional namespace settings only when configured, and re-exports it from the runtime package.
Generated worker archive wiring
packages/codegen/src/emit-app.ts, apps/docs/src/content/docs/concepts/observability.mdx
Generated workers assign the resolved configuration to options.logArchive; documentation explains environment-based and hand-written setup plus the unconfigured Archive state.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GeneratedApp
  participant resolveLogArchiveFromEnv
  participant WorkerOptions
  participant StudioArchive
  GeneratedApp->>resolveLogArchiveFromEnv: Read environment configuration
  resolveLogArchiveFromEnv-->>GeneratedApp: Return LogArchiveConfig or undefined
  GeneratedApp->>WorkerOptions: Set options.logArchive
  WorkerOptions->>StudioArchive: Provide archive configuration
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: wiring logArchive from env for scaffolded Studio archive support.
Description check ✅ Passed The description explains the why/what, links issue #155, and includes tests, but it omits several template sections like Checklist, Notes, and CLA.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/log-archive-codegen

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codspeed-hq

codspeed-hq Bot commented Jul 21, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 160 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing feat/log-archive-codegen (4fb1ea0) with alpha (d1ebb51)2

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

  2. No successful run was found on alpha (49d7a9e) during the generation of this report, so d1ebb51 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@prisis
prisis merged commit 67ca641 into alpha Jul 21, 2026
28 of 29 checks passed
@prisis
prisis deleted the feat/log-archive-codegen branch July 21, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant