/* RFC-1326: cloudflare.permissions.generate rewrites the marked cloudflare-permissions sections in the workspace-root .env.example and docs/engineering/workshop-setup.md from the shared CLOUDFLARE_PERMISSIONS registry; cloudflare.permissions.validate drift-guards both sections (CFPERM-01). Hand-edits inside the markers are forbidden — change the registry and re-run generate. Do not manage the site-level .env.example — env.example.generate renders its hint from the same registry. Do not probe the Cloudflare API — that is cloudflare.token.check. Markers are seeded by hand once; generate refuses when a target file carries no marked section (the file would otherwise grow a duplicated block). RFC-1326: initial — generate + validate pair over the two marked permission surfaces. RFC-1326: single Cloudflare permission registry, token preflight, birth provisioning RFC-1326: review-fix pass — siteName targeting for app-scoped provisioning, allow-list completion */ import { join } from "node:path"; import type { KernelCommandDefinition, KernelCommandInput, KernelCommandResult, KernelRuntimeContext, } from "@warpgogol/werkstatt-engine/kernel"; import { renderCloudflarePermissionCommentLines, renderCloudflarePermissionTableRows, } from "@warpgogol/werkstatt-shared/cloudflare/permissions"; import { diagnosticsResult, failResult, passResult, } from "@warpgogol/werkstatt-shared/checks/result-helpers"; import type { Diagnostic } from "@warpgogol/werkstatt-shared/kernel"; const ENV_EXAMPLE_PATH = ".env.example"; const WORKSHOP_SETUP_PATH = join("docs", "engineering", "workshop-setup.md"); const ENV_BEGIN = "# BEGIN cloudflare-permissions"; const ENV_END = "# END cloudflare-permissions"; const DOC_BEGIN = "