create-kywi-app 0.27.0 → 0.29.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.
- package/assets/agent-patterns.md +23 -17
- package/lib/templates.mjs +57 -34
- package/lib/upgrade.mjs +82 -0
- package/package.json +1 -1
package/assets/agent-patterns.md
CHANGED
|
@@ -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
|
-
|
|
858
|
-
404, and every response carries
|
|
859
|
-
`
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
switch.
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
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
|
-
|
|
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
|
|
@@ -407,10 +409,19 @@ function nextConfig(a) {
|
|
|
407
409
|
* - serverExternalPackages: core's server deps (sharp, drizzle, postgres, …)
|
|
408
410
|
* stay server-side and out of the client bundle.
|
|
409
411
|
*
|
|
412
|
+
* - withKywi: core's \`beforeFiles\` rewrite that completes
|
|
413
|
+
* \`Accept: text/markdown\` on page URLs. The middleware
|
|
414
|
+
* marks such a request; this rewrite, which (unlike the
|
|
415
|
+
* middleware) still sees Next's RSC headers, sends it to
|
|
416
|
+
* the page's Markdown copy and lets client navigations
|
|
417
|
+
* through. Without it page URLs always answer HTML.
|
|
418
|
+
*
|
|
410
419
|
* Note: core sanitizes all CMS HTML itself with a DOM-free sanitizer
|
|
411
420
|
* (sanitize-html), so there is no jsdom-based sanitizer to work around and no
|
|
412
421
|
* client-side sanitizer stub to wire up here.
|
|
413
422
|
*/
|
|
423
|
+
import { withKywi } from '@kywi-software/core/next/config'
|
|
424
|
+
|
|
414
425
|
/** @type {import('next').NextConfig} */
|
|
415
426
|
const nextConfig = {
|
|
416
427
|
transpilePackages: ['@kywi-software/core'],
|
|
@@ -432,7 +443,7 @@ const nextConfig = {
|
|
|
432
443
|
},
|
|
433
444
|
}
|
|
434
445
|
|
|
435
|
-
export default nextConfig
|
|
446
|
+
export default withKywi(nextConfig)
|
|
436
447
|
`
|
|
437
448
|
}
|
|
438
449
|
|
|
@@ -462,21 +473,10 @@ AUTH_SECRET=CHANGE_ME
|
|
|
462
473
|
# KYWI_API_URL=http://localhost:3000/api/v1
|
|
463
474
|
# KYWI_API_KEY=
|
|
464
475
|
|
|
465
|
-
# Search indexing.
|
|
466
|
-
# (
|
|
467
|
-
#
|
|
468
|
-
#
|
|
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
|
|
476
|
+
# Search indexing, llms.txt and Markdown copies are per-site switches in the
|
|
477
|
+
# admin (Settings → Agent Experience), stored in the database. Platform preview
|
|
478
|
+
# addresses (*.up.railway.app, *.vercel.app, *.netlify.app, …) are blocked
|
|
479
|
+
# from search unless a switch or kywi.config.ts says otherwise.
|
|
480
480
|
`
|
|
481
481
|
}
|
|
482
482
|
|
|
@@ -803,25 +803,46 @@ export const { getKywi, getKywiHandler, getActiveSite } = kywi
|
|
|
803
803
|
`)
|
|
804
804
|
}
|
|
805
805
|
|
|
806
|
-
// ── middleware.ts (
|
|
806
|
+
// ── middleware.ts (core's middleware, built over this app's runtime) ─────────
|
|
807
807
|
|
|
808
808
|
/**
|
|
809
809
|
* The auth gate, transparent session refresh, cookie→bearer bridge, visitor /
|
|
810
|
-
* UTM / entry-page cookies
|
|
811
|
-
*
|
|
810
|
+
* UTM / entry-page cookies, `.md` content negotiation and the Agent Experience
|
|
811
|
+
* switches all live in `@kywi-software/core/next/middleware`; this file hands
|
|
812
|
+
* it the app's runtime (`lib/kywi.ts`) so it can read the switches.
|
|
812
813
|
*
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
*
|
|
814
|
+
* Since 0.28.0 it runs on the Node runtime (`runtime: 'nodejs'`, Next ≥ 15.5)
|
|
815
|
+
* because the switches live in the database. The matcher is written out as a
|
|
816
|
+
* literal: Next extracts `config` statically, and a `config` whose matcher is
|
|
817
|
+
* an imported binding is dropped whole — runtime included — which puts the
|
|
818
|
+
* file back on the edge, where it cannot build. The scaffold tests pin this
|
|
819
|
+
* literal to core's exported `middlewareMatcher`.
|
|
818
820
|
*/
|
|
821
|
+
export const MIDDLEWARE_MATCHER = [
|
|
822
|
+
'/admin/:path*',
|
|
823
|
+
'/api/v1/:path*',
|
|
824
|
+
'/((?!_next/|.*\\..*).*)',
|
|
825
|
+
'/((?!_next/|api/).*\\.md)',
|
|
826
|
+
]
|
|
827
|
+
|
|
819
828
|
function middleware() {
|
|
820
829
|
return stamped(`// Auth gate, session refresh, the cookie→bearer bridge, the visitor/UTM/entry
|
|
821
|
-
// cookies
|
|
822
|
-
//
|
|
823
|
-
//
|
|
824
|
-
|
|
830
|
+
// cookies, .md content negotiation and the Agent Experience switches (Settings
|
|
831
|
+
// → Agent Experience) — all core's, all upgraded with the package. It reads the
|
|
832
|
+
// switches through this app's runtime, so it runs on Node, not the edge.
|
|
833
|
+
import { createKywiMiddleware } from '@kywi-software/core/next/middleware'
|
|
834
|
+
import { kywi } from './lib/kywi'
|
|
835
|
+
|
|
836
|
+
export const middleware = createKywiMiddleware(kywi)
|
|
837
|
+
|
|
838
|
+
export const config = {
|
|
839
|
+
runtime: 'nodejs',
|
|
840
|
+
// Core's \`middlewareMatcher\`, written out: Next reads this object statically
|
|
841
|
+
// and cannot follow an imported binding.
|
|
842
|
+
matcher: [
|
|
843
|
+
${MIDDLEWARE_MATCHER.map((p) => ` ${JSON.stringify(p).replace(/^"|"$/g, "'")},`).join('\n')}
|
|
844
|
+
],
|
|
845
|
+
}
|
|
825
846
|
`)
|
|
826
847
|
}
|
|
827
848
|
|
|
@@ -1664,7 +1685,7 @@ kywi.config.ts your config: sites, themes, content types, cus
|
|
|
1664
1685
|
AGENTS.md guidance for AI agents working on this site (Kywi's building patterns)
|
|
1665
1686
|
CLAUDE.md points AI agents to AGENTS.md
|
|
1666
1687
|
${SKILLS.map(({ slug }) => `.claude/skills/${slug}/SKILL.md ${slug.replace(/^kywi-/, '')} skill (loaded automatically)`).join('\n')}
|
|
1667
|
-
middleware.ts
|
|
1688
|
+
middleware.ts core's middleware over lib/kywi.ts (auth gate, session refresh, AX switches)
|
|
1668
1689
|
next.config.mjs required Next config to consume @kywi-software/core
|
|
1669
1690
|
lib/kywi.ts the ONE wiring point: kywi.config.ts → core's render path
|
|
1670
1691
|
app/api/v1/[...kywi]/route.ts the versioned API (delegates to core)
|
|
@@ -1955,10 +1976,12 @@ export function agentsMd(a, landmarks = scaffoldLandmarks(a.mode)) {
|
|
|
1955
1976
|
)
|
|
1956
1977
|
}
|
|
1957
1978
|
if (L.middleware) {
|
|
1958
|
-
bullets.push(`- \`middleware.ts\` — auth gate
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1979
|
+
bullets.push(`- \`middleware.ts\` — auth gate, session refresh and the Agent Experience
|
|
1980
|
+
switches. Since 0.28.0 it builds core's middleware over \`lib/kywi.ts\` with
|
|
1981
|
+
\`createKywiMiddleware(kywi)\` on the Node runtime; projects scaffolded since
|
|
1982
|
+
the layered render path re-exported the bare \`middleware\` (deprecated, still
|
|
1983
|
+
works for one release with Markdown copies and the llms.txt header off), and
|
|
1984
|
+
older projects hold their own copy over \`@kywi-software/core/host\`.`)
|
|
1962
1985
|
}
|
|
1963
1986
|
bullets.push(`- \`.claude/skills/kywi-content-model/SKILL.md\` — content-model planning
|
|
1964
1987
|
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), ...withKywiWarns(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,87 @@ 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
|
+
/**
|
|
414
|
+
* Since 0.29.0 `Accept: text/markdown` on a page URL needs the project's
|
|
415
|
+
* `next.config` wrapped with core's `withKywi`: the middleware only marks the
|
|
416
|
+
* request, and that config's `beforeFiles` rewrite completes it. `upgrade`
|
|
417
|
+
* never edits next.config, so a config that never calls `withKywi(` is a
|
|
418
|
+
* warn (`.md` addresses keep working either way).
|
|
419
|
+
* @returns {string[]}
|
|
420
|
+
*/
|
|
421
|
+
function withKywiWarns(projectDir) {
|
|
422
|
+
for (const name of ['next.config.mjs', 'next.config.js', 'next.config.ts', 'next.config.cjs', 'next.config.mts']) {
|
|
423
|
+
let text
|
|
424
|
+
try {
|
|
425
|
+
text = readFileSync(join(projectDir, name), 'utf8')
|
|
426
|
+
} catch {
|
|
427
|
+
continue
|
|
428
|
+
}
|
|
429
|
+
if (/\bwithKywi\s*\(/.test(text)) return []
|
|
430
|
+
return [
|
|
431
|
+
`${name} does not use withKywi, so Accept: text/markdown on page URLs answers HTML (.md addresses still work) — ` +
|
|
432
|
+
`import { withKywi } from '@kywi-software/core/next/config' and export default withKywi(nextConfig)`,
|
|
433
|
+
]
|
|
434
|
+
}
|
|
435
|
+
return []
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function nodeMiddlewareWarns(projectDir) {
|
|
439
|
+
const warns = []
|
|
440
|
+
let pkg = null
|
|
441
|
+
try {
|
|
442
|
+
pkg = JSON.parse(readFileSync(join(projectDir, 'package.json'), 'utf8'))
|
|
443
|
+
} catch {
|
|
444
|
+
/* no/invalid package.json — nothing to check */
|
|
445
|
+
}
|
|
446
|
+
const range = pkg?.dependencies?.next ?? pkg?.devDependencies?.next
|
|
447
|
+
const floor = typeof range === 'string' ? /(\d+)\.(\d+)/.exec(range) : null
|
|
448
|
+
if (floor && (Number(floor[1]) < 15 || (Number(floor[1]) === 15 && Number(floor[2]) < 5))) {
|
|
449
|
+
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`)
|
|
450
|
+
}
|
|
451
|
+
for (const file of ['.env', '.env.local']) {
|
|
452
|
+
let text
|
|
453
|
+
try {
|
|
454
|
+
text = readFileSync(join(projectDir, file), 'utf8')
|
|
455
|
+
} catch {
|
|
456
|
+
continue
|
|
457
|
+
}
|
|
458
|
+
const set = ['KYWI_INDEXING', 'KYWI_AX_MARKDOWN', 'KYWI_AX_LLMS'].filter((k) => new RegExp(`^\\s*${k}\\s*=`, 'm').test(text))
|
|
459
|
+
if (set.length > 0) {
|
|
460
|
+
warns.push(`${file} sets ${set.join(', ')}, which core 0.28 no longer reads — use the switches in Settings → Agent Experience instead${indexingCarryOver(text)}`)
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return warns
|
|
464
|
+
}
|
|
465
|
+
|
|
384
466
|
const SCAN_SKIP_DIRS =new Set(['node_modules', '.next', '.git', '.kywi-upgrade'])
|
|
385
467
|
|
|
386
468
|
/** Every `.ts`/`.tsx` under the project, as sorted posix-relative paths. */
|
package/package.json
CHANGED