/** * The architecture questions asked in the terminal, all before a single file is written. * Enter takes the shown recommendation — an explicit choice, recorded as the owner's answer. * Agents pass the same answers as JSON with `--answers` instead. */ import { createInterface } from 'node:readline/promises' import type { AnalyticsTool, ContentCollection, StarterAnswers } from './answers.js' type Ask = (question: string) => Promise function asker(ask: Ask) { const text = async (question: string, recommended?: string): Promise => { for (;;) { const answer = (await ask(`${question}${recommended ? ` [${recommended}]` : ''}: `)).trim() if (answer) {return answer} if (recommended !== undefined) {return recommended} } } const choice = async (question: string, options: readonly T[], recommended: T): Promise => { for (;;) { const answer = await text(`${question} (${options.join(' / ')})`, recommended) if ((options as readonly string[]).includes(answer)) {return answer as T} } } const yes = async (question: string, recommended: boolean) => (await choice(question, ['yes', 'no'] as const, recommended ? 'yes' : 'no')) === 'yes' const list = async (question: string, recommended: string): Promise => (await text(`${question} (comma-separated, "none" for none)`, recommended)).split(',').map((s) => s.trim()).filter((s) => s && s !== 'none') return { choice, list, text, yes } } /** Asks every topic of AGENT.md "Ask before you build" and returns the answers (not yet validated). */ export async function askAnswers(ask: Ask): Promise { const { choice, list, text, yes } = asker(ask) const siteName = await text('1. Site / company name (also the 2FA issuer)') const market = await text(' Market', 'PL') const industry = await text(' Industry, one line') const extra = await list('2. Languages besides pl (default) and en, as code:Label', 'none') const locales = [{ code: 'pl', label: 'Polski' }, { code: 'en', label: 'English' }, ...extra.map((e) => { const [code = '', label = code] = e.split(':').map((s) => s.trim()) return { code, label } })] const primary = await text('3. Brand primary colour (any CSS colour)') const secondary = await text(' Secondary colour ("none")', 'none') const accent = await text(' Accent colour ("none")', 'none') const fontBody = await text(' Body font (Google font name)', 'Inter') const fontHeading = await text(' Heading font (Google font name)', fontBody) const theme = await choice(' Theme', ['both', 'light', 'dark'] as const, 'both') const defaultTheme = theme === 'both' ? await choice(' Default theme', ['system', 'light', 'dark'] as const, 'system') : theme const radius = await choice(' Corner style', ['sharp', 'soft', 'round'] as const, 'soft') const fluid = await choice(' Scale (standard = to 1280px, wide = to 1920px)', ['wide', 'standard'] as const, 'wide') const pages = await list('4. Pages (site map)', 'Home, About, Services, Contact, Privacy policy, Cookie policy') const collections = (await list(' Collections with their own URLs: posts, caseStudies', 'none')) as ContentCollection[] const forms = await list('5. Forms', 'Contact form') const recipient = await text(' Inbox that receives submissions') const transport = await choice(' E-mail transport', ['smtp', 'graph'] as const, 'smtp') const tools = (await list('6. Analytics: ga4, gtm, metaPixel, linkedIn, tiktok, clarity', 'ga4')) as AnalyticsTool[] const consentMode = await choice(' Consent Mode', ['advanced', 'basic'] as const, 'advanced') const banner = await choice(' Cookie settings window', ['detailed', 'modal', 'inline'] as const, 'detailed') const cookieScanner = await yes(' Cookie scanner', true) const cookieScannerOffReason = cookieScanner ? undefined : await text(' Why off (owner\'s reason)') const crawl = cookieScanner ? await yes(' Browser crawl through the shared cookie-crawler service', true) : false const localBusiness = await yes('7. Local business (address, opening hours in JSON-LD)', true) const businessType = localBusiness ? await text(' schema.org type', 'ProfessionalService') : '' const aiBots = await choice(' AI crawlers', ['allow', 'block-training', 'disallow'] as const, 'allow') const aiBotsReason = aiBots === 'allow' ? undefined : await text(' Client decision behind it') const media = await choice('8. Media', ['r2', 'local'] as const, 'r2') const twoFactor = await yes('9. 2FA for the panel', true) const twoFactorOffReason = twoFactor ? undefined : await text(' Why off (owner\'s reason)') const whiteLabel = await yes(' White-label (client brand in the panel)', true) const agencyChoice = await choice(' Agency credit', ['intecion', 'none', 'other'] as const, 'intecion') const agency = agencyChoice === 'other' ? { name: await text(' Agency name'), url: await text(' Agency URL (https://…)') } : agencyChoice const adminMeta = await yes(' Panel link preview (adminMeta)', true) const adminMetaOffReason = adminMeta ? undefined : await text(' Why off (owner\'s reason)') const canonical = await choice('10. Canonical host', ['apex', 'www'] as const, 'apex') const coolify = await text(' Coolify server / project') const dns = await text(' Who adds the DNS records', 'the team') const external = await list('11. External skills (ext-react-best-practices, ext-composition-patterns, ext-accessibility, ext-frontend-design, ext-payload)', 'none') const optional = (value: string) => (value === 'none' ? undefined : value) return { admin: { adminMeta, adminMetaOffReason, agency, twoFactor, twoFactorOffReason, whiteLabel }, consent: { banner, consentMode, cookieScanner, cookieScannerOffReason, crawl, tools }, content: { collections, pages }, forms: { list: forms, recipient, transport }, hosting: { canonical, coolify, dns }, industry, languages: { default: 'pl', locales }, market, media, seo: { aiBots, aiBotsReason, localBusiness: localBusiness ? { type: businessType } : false }, siteName, styling: { accent: optional(accent), defaultTheme, fluid, fontBody, fontHeading, primary, radius, secondary: optional(secondary), theme }, tooling: { external }, } } /** Runs the questions on stdin/stdout. */ export async function askInTerminal(): Promise { const rl = createInterface({ input: process.stdin, output: process.stdout }) try { process.stdout.write('Architecture questions (AGENT.md "Ask before you build"). Enter = the recommendation in [brackets].\n\n') return await askAnswers((q) => rl.question(q)) } finally { rl.close() } }