mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-21 21:09:49 +08:00
## Summary
Replaces `writeConfigObject` (destructive overwrite) with
`updateConfigObject` — an async, AI-aware updater that preserves
user-authored config structure (imports, external file references,
helpers).
**Dual-path approach:**
- **Fast path** (deterministic, no AI): plain static literal configs →
`override()` + in-memory validation + atomic write
- **Agent path** (custom structure): configs with `import x from
"./file.txt" with { type: "text" }` etc. → Claude agent edits the
external files in place, then validates
**Safety guarantees:**
- Snapshot/restore: config + all relative imports are captured before
the agent runs; rolled back on any failure
- In-memory validation on fast path (never write unvalidated bytes)
- Semantic check when config is evaluable; no-op detection + structural
check when it isn't
- Path traversal guard on imports (rejects `../` escapes)
- Agent isolation: `settingSources: []`, `strictMcpConfig: true`,
`CLAUDE_CODE_DISABLE_AUTO_MEMORY`, no Bash tool
- `scheduleSync` only fires after a successful update
- Bounded 120s timeout on agent runs (configurable via env var)
CI failures are preexisting on `dev`
(`ERR_PNPM_LOCKFILE_CONFIG_MISMATCH` from overrides move without
lockfile regen); this branch has zero lockfile changes vs dev.
Link to Devin session:
https://app.devin.ai/sessions/cc7409a357bc472ea19fbed065f1229f
Requested by: @mantrakp04
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Introduced partial configuration update functionality with validation
and automatic rollback on failures.
* Enhanced configuration management with support for more complex file
structures and external references.
* **Chores**
* Added Claude Agent SDK dependency for configuration update operations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
## Documentation
Docs for this feature were added in this branch:
- **New page**
`docs-mintlify/guides/going-further/local-development.mdx` — covers
`stack dev`, the development-environment flow, and how dashboard edits
are written back to the local config file (structure-preserving fast
path vs. assistant path, external `import … with { type: "text" }`
templates, validation + rollback). Added to `docs.json` nav; also fixes
the previously-broken `/guides/going-further/local-development` links
from `index.mdx` and `self-host.mdx`.
- **`docs-mintlify/guides/going-further/cli.mdx`** — added a `stack dev`
("Run a development environment") section.
- **Skill-site AI prompts** — filled in the `config-docs` and
`dashboard-instructions` placeholders under
`packages/stack-shared/src/ai/unified-prompts/skill-site-prompt-parts/`,
and added a structure-preserving note to the setup prompt.
- **`CHANGELOG.md`** — user-facing entry.
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: mantra <mantra@stack-auth.com>
162 lines
5.3 KiB
JavaScript
162 lines
5.3 KiB
JavaScript
import { withSentryConfig } from "@sentry/nextjs";
|
|
import { createRequire } from "module";
|
|
import path from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const sharedBackendRequire = createRequire(path.join(__dirname, "../../packages/shared-backend/package.json"));
|
|
const claudeAgentSdkDir = path.dirname(sharedBackendRequire.resolve("@anthropic-ai/claude-agent-sdk"));
|
|
const claudeAgentSdkTraceDir = path.relative(__dirname, claudeAgentSdkDir);
|
|
|
|
const withConfiguredSentryConfig = (nextConfig) =>
|
|
withSentryConfig(
|
|
nextConfig,
|
|
{
|
|
// For all available options, see:
|
|
// https://github.com/getsentry/sentry-webpack-plugin#options
|
|
|
|
org: "stackframe-pw",
|
|
project: "stack-server",
|
|
|
|
widenClientFileUpload: true,
|
|
telemetry: false,
|
|
},
|
|
{
|
|
// For all available options, see:
|
|
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
|
|
|
|
// Upload a larger set of source maps for prettier stack traces (increases build time)
|
|
widenClientFileUpload: true,
|
|
|
|
// Transpiles SDK to be compatible with IE11 (increases bundle size)
|
|
transpileClientSDK: true,
|
|
|
|
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
|
|
// This can increase your server load as well as your hosting bill.
|
|
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
|
|
// side errors will fail.
|
|
tunnelRoute: "/monitoring",
|
|
|
|
// Hides source maps from generated client bundles
|
|
hideSourceMaps: true,
|
|
|
|
// Automatically tree-shake Sentry logger statements to reduce bundle size
|
|
disableLogger: true,
|
|
|
|
// Enables automatic instrumentation of Vercel Cron Monitors.
|
|
// See the following for more information:
|
|
// https://docs.sentry.io/product/crons/
|
|
// https://vercel.com/docs/cron-jobs
|
|
automaticVercelMonitors: true,
|
|
}
|
|
);
|
|
|
|
/** @type {import('next').NextConfig} */
|
|
const nextConfig = {
|
|
// optionally set output to "standalone" for Docker builds
|
|
// https://nextjs.org/docs/pages/api-reference/next-config-js/output
|
|
output: process.env.NEXT_CONFIG_OUTPUT,
|
|
distDir: process.env.HEXCLAVE_DASHBOARD_NEXT_DIST_DIR,
|
|
outputFileTracingRoot: path.join(__dirname, "../.."),
|
|
outputFileTracingIncludes: {
|
|
"/api/remote-development-environment/config/apply-update": [
|
|
path.join(claudeAgentSdkTraceDir, "cli.js"),
|
|
path.join(claudeAgentSdkTraceDir, "manifest.json"),
|
|
path.join(claudeAgentSdkTraceDir, "manifest.zst.json"),
|
|
path.join(claudeAgentSdkTraceDir, "resvg.wasm"),
|
|
path.join(claudeAgentSdkTraceDir, "vendor/**/*"),
|
|
],
|
|
},
|
|
|
|
pageExtensions: ["js", "jsx", "mdx", "ts", "tsx"],
|
|
|
|
// we're open-source, so we can provide source maps
|
|
productionBrowserSourceMaps: true,
|
|
|
|
poweredByHeader: false,
|
|
|
|
typescript: {
|
|
ignoreBuildErrors: process.env.STACK_NEXT_CONFIG_DISABLE_TYPESCRIPT === "true",
|
|
},
|
|
|
|
images: {
|
|
// Disable image optimization in standalone/RDE builds to avoid shipping
|
|
// the sharp native binary (~17 MB). The RDE runs locally so optimized
|
|
// images are not needed.
|
|
...(process.env.NEXT_CONFIG_OUTPUT === "standalone" ? { unoptimized: true } : {}),
|
|
remotePatterns: [
|
|
{
|
|
protocol: 'https',
|
|
hostname: '*.featurebase-attachments.com',
|
|
port: '',
|
|
pathname: '/**',
|
|
},
|
|
{
|
|
protocol: 'https',
|
|
hostname: 'raw.githubusercontent.com',
|
|
port: '',
|
|
pathname: '/**',
|
|
},
|
|
],
|
|
},
|
|
|
|
async rewrites() {
|
|
return [
|
|
{
|
|
source: "/consume/static/:path*",
|
|
destination: "https://eu-assets.i.posthog.com/static/:path*",
|
|
},
|
|
{
|
|
source: "/consume/:path*",
|
|
destination: "https://eu.i.posthog.com/:path*",
|
|
},
|
|
{
|
|
source: "/consume/decide",
|
|
destination: "https://eu.i.posthog.com/decide",
|
|
},
|
|
];
|
|
},
|
|
|
|
async headers() {
|
|
const isLocalEmulator = process.env.NEXT_PUBLIC_STACK_IS_LOCAL_EMULATOR === "true";
|
|
return [
|
|
{
|
|
source: "/(.*)",
|
|
headers: [
|
|
{
|
|
// needed for stripe connect embedded components
|
|
key: "Cross-Origin-Opener-Policy",
|
|
value: "same-origin-allow-popups",
|
|
},
|
|
{
|
|
key: "Permissions-Policy",
|
|
value: "",
|
|
},
|
|
{
|
|
key: "Referrer-Policy",
|
|
value: "strict-origin-when-cross-origin",
|
|
},
|
|
{
|
|
key: "X-Content-Type-Options",
|
|
value: "nosniff",
|
|
},
|
|
...process.env.NEXT_PUBLIC_STACK_IS_PREVIEW === "true" ? [] : [{
|
|
key: "X-Frame-Options",
|
|
value: "SAMEORIGIN",
|
|
}],
|
|
{
|
|
key: "Content-Security-Policy",
|
|
// Note: *.localhost requires Chrome 117+ and may not work in Firefox
|
|
// without network.dns.localDomains configuration. Fine for dev tool purposes.
|
|
value: isLocalEmulator ? "frame-ancestors 'self' http://localhost:* https://localhost:* http://127.0.0.1:* https://127.0.0.1:* http://[::1]:* https://[::1]:* http://*.localhost https://*.localhost" : "",
|
|
},
|
|
],
|
|
},
|
|
];
|
|
},
|
|
};
|
|
|
|
export default withConfiguredSentryConfig(
|
|
nextConfig
|
|
);
|