create-kywi-app 0.27.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -852,24 +852,30 @@ early, so ask at scoping time.
852
852
  `robots.txt` at the site root out of the box — a Kywi site is legible to
853
853
  agents and crawlers by default. Don't remove these routes; they're part of
854
854
  the product's value.
855
+ - **Three admin switches decide discovery.** Settings → Agent Experience has
856
+ a **Switches** section with *Markdown copies*, *llms.txt* and *Search
857
+ indexing*, each *Use default* / *On* / *Off*, per site, stored in the
858
+ database. A switch beats `kywi.config.ts`; *Use default* follows it
859
+ (`ax.markdown.enabled`, `ax.llmsTxt.enabled`, `sites[].indexing`).
860
+ `ax.enabled: false` still turns Markdown and llms.txt off whatever the
861
+ switches say. Changes take effect at once: no redeploy, no env var.
855
862
  - **Pre-launch sites are hidden from search.** A site answering on a platform
856
- preview address (`*.up.railway.app`, `*.vercel.app`, …) is blocked
857
- automatically: `robots.txt` says `Disallow: /`, the sitemap and llms files
858
- 404, and every response carries `X-Robots-Tag: noindex, nofollow`. Set
859
- `KYWI_INDEXING=off` on any other pre-launch or staging host. **At launch**,
860
- when the site answers on its real domain, remove `KYWI_INDEXING=off` (or set
861
- `on`) — the admin shows a "Search engines are blocked" banner until you do.
862
- Never hide a site from search by editing robots policy by hand; use this
863
- switch.
864
- - **Every page has a Markdown copy when `ax.markdown` is on.** `/<path>.md`
865
- serves it, and the home page is `/index.md`. The page head advertises it with
866
- `<link rel="alternate" type="text/markdown">`, but only when the copy really
867
- answers. Set `KYWI_AX_MARKDOWN=on` so agents that send
868
- `Accept: text/markdown` to the page URL get the copy too, and
869
- `KYWI_AX_LLMS=on` to advertise `/llms.txt` in a `Link` header. The edge
870
- cannot read `kywi.config.ts`, so these env vars mirror config; keep them in
871
- step. Never write a static `public/llms.txt` or a hand-made `.md` file — the
872
- generated ones follow every publish.
863
+ preview address (`*.up.railway.app`, `*.vercel.app`, …) is blocked unless a
864
+ switch or the config says otherwise: `robots.txt` says `Disallow: /`, the
865
+ sitemap and llms files 404, and every response carries
866
+ `X-Robots-Tag: noindex, nofollow`. On any other pre-launch or staging host,
867
+ set **Search indexing** to *Off*. **At launch**, set it back to *Use
868
+ default* (or *On*) — the admin shows a "Search engines are blocked" banner
869
+ until you do. A staging database restored from production brings
870
+ production's switches with it, so check the switch after a restore. Never
871
+ hide a site from search by editing robots policy by hand; use the switch.
872
+ - **Every page can have a Markdown copy.** With *Markdown copies* on,
873
+ `/<path>.md` serves it, the home page is `/index.md`, agents that send
874
+ `Accept: text/markdown` to the page URL get the same copy, and the page head
875
+ advertises it with `<link rel="alternate" type="text/markdown">`. With
876
+ *llms.txt* on (the default), public pages also advertise `/llms.txt` in a
877
+ `Link` header. Never write a static `public/llms.txt` or a hand-made `.md`
878
+ file — the generated ones follow every publish.
873
879
 
874
880
  ## Other capabilities worth knowing
875
881
 
package/lib/templates.mjs CHANGED
@@ -85,7 +85,9 @@ function packageJson(a) {
85
85
  dependencies: {
86
86
  '@kywi-software/core': CORE_RANGE(a.kywiVersion),
87
87
  '@kywi-software/cli': CORE_RANGE(a.kywiVersion),
88
- next: '^15.0.0',
88
+ // 15.5: the Node.js middleware runtime (core 0.28 reads the Agent
89
+ // Experience switches from the database in middleware.ts).
90
+ next: '^15.5.0',
89
91
  react: '^19.0.0',
90
92
  'react-dom': '^19.0.0',
91
93
  // Server-side image processing used by core's media pipeline. Listed in
@@ -462,21 +464,10 @@ AUTH_SECRET=CHANGE_ME
462
464
  # KYWI_API_URL=http://localhost:3000/api/v1
463
465
  # KYWI_API_KEY=
464
466
 
465
- # Search indexing. Unset = indexable, EXCEPT on platform preview addresses
466
- # (*.up.railway.app, *.vercel.app, *.netlify.app, …), which are blocked
467
- # automatically. off = robots.txt Disallow-all, no sitemap/llms files, and a
468
- # noindex header on every response — use it on a pre-launch or staging host.
469
- # Set on at launch (or remove it once the site answers on its real domain).
470
- # KYWI_INDEXING=off
471
-
472
- # Agent discovery at the edge. The middleware cannot read kywi.config.ts, so
473
- # these mirror the AX config there — keep each in step with its setting.
474
- # KYWI_AX_LLMS=on adds a \`Link: </llms.txt>; rel="describedby"\` header to public
475
- # pages (mirror of ax.llmsTxt.enabled, which is on by default).
476
- # KYWI_AX_MARKDOWN=on answers \`Accept: text/markdown\` on page URLs with the
477
- # page's Markdown copy (mirror of ax.markdown.enabled, which is off by default).
478
- KYWI_AX_LLMS=on
479
- # KYWI_AX_MARKDOWN=on
467
+ # Search indexing, llms.txt and Markdown copies are per-site switches in the
468
+ # admin (Settings → Agent Experience), stored in the database. Platform preview
469
+ # addresses (*.up.railway.app, *.vercel.app, *.netlify.app, …) are blocked
470
+ # from search unless a switch or kywi.config.ts says otherwise.
480
471
  `
481
472
  }
482
473
 
@@ -803,25 +794,46 @@ export const { getKywi, getKywiHandler, getActiveSite } = kywi
803
794
  `)
804
795
  }
805
796
 
806
- // ── middleware.ts (a re-export of core's own) ─────────────────────────────────
797
+ // ── middleware.ts (core's middleware, built over this app's runtime) ─────────
807
798
 
808
799
  /**
809
800
  * The auth gate, transparent session refresh, cookie→bearer bridge, visitor /
810
- * UTM / entry-page cookies and `.md` content negotiation were 242 lines of
811
- * emitted code; they are now `@kywi-software/core/next/middleware`.
801
+ * UTM / entry-page cookies, `.md` content negotiation and the Agent Experience
802
+ * switches all live in `@kywi-software/core/next/middleware`; this file hands
803
+ * it the app's runtime (`lib/kywi.ts`) so it can read the switches.
812
804
  *
813
- * It has its OWN core entry rather than living on the `/next` barrel because
814
- * Next compiles this file for the EDGE runtime: the barrel reaches the
815
- * database, sharp and the AWS SDK, and re-exporting the middleware from it
816
- * would drag all of that into the edge bundle. Same precedent as core's
817
- * `./host` split (see that file's header in core).
805
+ * Since 0.28.0 it runs on the Node runtime (`runtime: 'nodejs'`, Next ≥ 15.5)
806
+ * because the switches live in the database. The matcher is written out as a
807
+ * literal: Next extracts `config` statically, and a `config` whose matcher is
808
+ * an imported binding is dropped whole — runtime included — which puts the
809
+ * file back on the edge, where it cannot build. The scaffold tests pin this
810
+ * literal to core's exported `middlewareMatcher`.
818
811
  */
812
+ export const MIDDLEWARE_MATCHER = [
813
+ '/admin/:path*',
814
+ '/api/v1/:path*',
815
+ '/((?!_next/|.*\\..*).*)',
816
+ '/((?!_next/|api/).*\\.md)',
817
+ ]
818
+
819
819
  function middleware() {
820
820
  return stamped(`// Auth gate, session refresh, the cookie→bearer bridge, the visitor/UTM/entry
821
- // cookies and .md content negotiation — all core's, all upgraded with the
822
- // package. Imported from its OWN entry, never the \`/next\` barrel: that barrel
823
- // reaches the database and sharp, which no edge bundle can carry.
824
- export { middleware, config } from '@kywi-software/core/next/middleware'
821
+ // cookies, .md content negotiation and the Agent Experience switches (Settings
822
+ // → Agent Experience) — all core's, all upgraded with the package. It reads the
823
+ // switches through this app's runtime, so it runs on Node, not the edge.
824
+ import { createKywiMiddleware } from '@kywi-software/core/next/middleware'
825
+ import { kywi } from './lib/kywi'
826
+
827
+ export const middleware = createKywiMiddleware(kywi)
828
+
829
+ export const config = {
830
+ runtime: 'nodejs',
831
+ // Core's \`middlewareMatcher\`, written out: Next reads this object statically
832
+ // and cannot follow an imported binding.
833
+ matcher: [
834
+ ${MIDDLEWARE_MATCHER.map((p) => ` ${JSON.stringify(p).replace(/^"|"$/g, "'")},`).join('\n')}
835
+ ],
836
+ }
825
837
  `)
826
838
  }
827
839
 
@@ -1664,7 +1676,7 @@ kywi.config.ts your config: sites, themes, content types, cus
1664
1676
  AGENTS.md guidance for AI agents working on this site (Kywi's building patterns)
1665
1677
  CLAUDE.md points AI agents to AGENTS.md
1666
1678
  ${SKILLS.map(({ slug }) => `.claude/skills/${slug}/SKILL.md ${slug.replace(/^kywi-/, '')} skill (loaded automatically)`).join('\n')}
1667
- middleware.ts re-exports core's middleware (auth gate, session refresh, cookie→bearer)
1679
+ middleware.ts core's middleware over lib/kywi.ts (auth gate, session refresh, AX switches)
1668
1680
  next.config.mjs required Next config to consume @kywi-software/core
1669
1681
  lib/kywi.ts the ONE wiring point: kywi.config.ts → core's render path
1670
1682
  app/api/v1/[...kywi]/route.ts the versioned API (delegates to core)
@@ -1955,10 +1967,12 @@ export function agentsMd(a, landmarks = scaffoldLandmarks(a.mode)) {
1955
1967
  )
1956
1968
  }
1957
1969
  if (L.middleware) {
1958
- bullets.push(`- \`middleware.ts\` — auth gate + session refresh. In a project scaffolded
1959
- since the layered render path it is a one-line re-export of
1960
- \`@kywi-software/core/next/middleware\`; older projects hold their own copy
1961
- over \`@kywi-software/core/host\`.`)
1970
+ bullets.push(`- \`middleware.ts\` — auth gate, session refresh and the Agent Experience
1971
+ switches. Since 0.28.0 it builds core's middleware over \`lib/kywi.ts\` with
1972
+ \`createKywiMiddleware(kywi)\` on the Node runtime; projects scaffolded since
1973
+ the layered render path re-exported the bare \`middleware\` (deprecated, still
1974
+ works for one release with Markdown copies and the llms.txt header off), and
1975
+ older projects hold their own copy over \`@kywi-software/core/host\`.`)
1962
1976
  }
1963
1977
  bullets.push(`- \`.claude/skills/kywi-content-model/SKILL.md\` — content-model planning
1964
1978
  skill, loaded automatically before building anything.`)
package/lib/upgrade.mjs CHANGED
@@ -243,6 +243,7 @@ export function planUpgrade(projectDir, { force = false, dryRun = false } = {})
243
243
  // ever cause a write or change the exit code.
244
244
  plan.warns.push(...danglingImportWarns(projectDir, plan, expectedFor('runtime', RENDER_LANDMARK_PATHS.runtime)))
245
245
  if (wanted.kywiJs) plan.warns.push(...kywiJsWarns(projectDir))
246
+ if (wanted.middleware) plan.warns.push(...nodeMiddlewareWarns(projectDir))
246
247
  const installedCore = installedCoreVersion(projectDir)
247
248
  for (const { path, artifact, version } of scanEjectedArtifacts(projectDir)) {
248
249
  if (installedCore === null || version === installedCore) continue
@@ -381,6 +382,62 @@ function kywiJsWarns(projectDir) {
381
382
  return warns
382
383
  }
383
384
 
385
+ /**
386
+ * Since 0.28.0 the generated `middleware.ts` runs on the Node runtime (it reads
387
+ * the Agent Experience switches from the database), which needs Next 15.5 or
388
+ * later; on an older Next the project no longer builds. `upgrade` never edits
389
+ * `package.json`, so a declared `next` range whose floor is below 15.5 is a
390
+ * warn. Removed env vars still set in `.env` or `.env.local` are warns too:
391
+ * they are ignored now, and a `KYWI_INDEXING=off` site becomes indexable
392
+ * unless the Search indexing switch or kywi.config.ts says off.
393
+ * @returns {string[]}
394
+ */
395
+ /**
396
+ * How to keep a `KYWI_INDEXING` value across the upgrade — the same three
397
+ * routes as the 0.28.0 CHANGELOG upgrade note. Empty when the file does not
398
+ * set it.
399
+ */
400
+ function indexingCarryOver(envText) {
401
+ const m = /^\s*KYWI_INDEXING\s*=\s*["']?([^"'\s#]*)/m.exec(envText)
402
+ if (!m) return ''
403
+ const v = m[1].toLowerCase()
404
+ const value = v === 'off' || v === 'on' ? v : 'off'
405
+ return (
406
+ `. KYWI_INDEXING stops applying the moment 0.28 is up; to keep it, before you deploy either set ` +
407
+ `sites[].indexing: ${value === 'on'} in kywi.config.ts, or (while still on 0.27) store the switch: ` +
408
+ `PUT /api/v1/sites/{siteId}/settings with {"ax.switches":{"indexing":"${value}"}}. ` +
409
+ `Env vars set on your hosting platform (Railway, Vercel, …) are not checked here — look there too`
410
+ )
411
+ }
412
+
413
+ function nodeMiddlewareWarns(projectDir) {
414
+ const warns = []
415
+ let pkg = null
416
+ try {
417
+ pkg = JSON.parse(readFileSync(join(projectDir, 'package.json'), 'utf8'))
418
+ } catch {
419
+ /* no/invalid package.json — nothing to check */
420
+ }
421
+ const range = pkg?.dependencies?.next ?? pkg?.devDependencies?.next
422
+ const floor = typeof range === 'string' ? /(\d+)\.(\d+)/.exec(range) : null
423
+ if (floor && (Number(floor[1]) < 15 || (Number(floor[1]) === 15 && Number(floor[2]) < 5))) {
424
+ warns.push(`package.json asks for next ${range}; middleware.ts now runs on the Node runtime, which needs next >= 15.5 — pnpm add next@^15.5.0`)
425
+ }
426
+ for (const file of ['.env', '.env.local']) {
427
+ let text
428
+ try {
429
+ text = readFileSync(join(projectDir, file), 'utf8')
430
+ } catch {
431
+ continue
432
+ }
433
+ const set = ['KYWI_INDEXING', 'KYWI_AX_MARKDOWN', 'KYWI_AX_LLMS'].filter((k) => new RegExp(`^\\s*${k}\\s*=`, 'm').test(text))
434
+ if (set.length > 0) {
435
+ warns.push(`${file} sets ${set.join(', ')}, which core 0.28 no longer reads — use the switches in Settings → Agent Experience instead${indexingCarryOver(text)}`)
436
+ }
437
+ }
438
+ return warns
439
+ }
440
+
384
441
  const SCAN_SKIP_DIRS =new Set(['node_modules', '.next', '.git', '.kywi-upgrade'])
385
442
 
386
443
  /** Every `.ts`/`.tsx` under the project, as sorted posix-relative paths. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-kywi-app",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "Scaffold a new Kywi CMS project — npx create-kywi-app my-site",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/Kywi-Software/kywi-cms#readme",