prunelle 0.1.1 → 0.7.2
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/LICENSE +21 -0
- package/llms.txt +137 -40
- package/package.json +11 -2
- package/src/a11y/declaration.ts +373 -0
- package/src/a11y/index.ts +477 -0
- package/src/a11y/rgaa-map.ts +230 -0
- package/src/attrs.ts +11 -3
- package/src/build/bundle.ts +89 -41
- package/src/build/byte-size.ts +11 -0
- package/src/build/client-entries.ts +3 -2
- package/src/build/client-plugin.ts +11 -5
- package/src/build/client-prune.ts +56 -6
- package/src/build/compile.ts +13 -10
- package/src/build/ecoindex.ts +238 -0
- package/src/build/files.ts +15 -0
- package/src/build/first-load.ts +85 -14
- package/src/build/graph.ts +29 -39
- package/src/build/index.ts +225 -122
- package/src/build/island-promote.ts +311 -0
- package/src/build/islands.ts +14 -203
- package/src/build/manifest.ts +56 -116
- package/src/build/output.ts +3 -6
- package/src/build/plugin-host.ts +115 -41
- package/src/build/precompress.ts +16 -3
- package/src/build/prerender.ts +177 -39
- package/src/build/reach.ts +200 -0
- package/src/build/render-rules.ts +2 -2
- package/src/build/report.ts +48 -5
- package/src/build/resolve.ts +8 -6
- package/src/build/routes.ts +175 -10
- package/src/build/static-headers.ts +112 -0
- package/src/build/static.ts +139 -39
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +636 -0
- package/src/cli/check-imports.ts +31 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check-security.ts +64 -0
- package/src/cli/check.ts +101 -26
- package/src/cli/commands.ts +120 -11
- package/src/cli/docs.ts +403 -0
- package/src/cli/inspect.ts +105 -15
- package/src/cli/mcp-tools.ts +492 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +16 -5
- package/src/cli/render.ts +416 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +156 -22
- package/src/compiler/analyze.ts +87 -54
- package/src/compiler/browser-globals.ts +140 -17
- package/src/compiler/cacheability-private.ts +566 -0
- package/src/compiler/cacheability.ts +335 -0
- package/src/compiler/compliance-eco.ts +71 -0
- package/src/compiler/compliance-rgaa.ts +614 -0
- package/src/compiler/compliance-urls.ts +148 -0
- package/src/compiler/compliance.ts +407 -352
- package/src/compiler/data-keys.ts +199 -192
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +138 -65
- package/src/compiler/dom.ts +517 -442
- package/src/compiler/expr-context.ts +260 -81
- package/src/compiler/foreign-imports.ts +88 -0
- package/src/compiler/mistakes.ts +23 -2
- package/src/compiler/props-body.ts +60 -0
- package/src/compiler/props.ts +87 -36
- package/src/compiler/scope.ts +400 -333
- package/src/compiler/server-only.ts +190 -151
- package/src/compiler/shared.ts +42 -14
- package/src/compiler/signal-reads.ts +6 -2
- package/src/compiler/spread-handlers.ts +295 -0
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +220 -89
- package/src/context.ts +34 -0
- package/src/dev/error-log.ts +177 -0
- package/src/dev/host-check.ts +32 -0
- package/src/dev/index.ts +94 -34
- package/src/dev/open-editor.ts +228 -0
- package/src/dev/protocol.ts +3 -0
- package/src/dev/reload.ts +5 -3
- package/src/dev/supervisor.ts +50 -25
- package/src/dev/watchers.ts +74 -13
- package/src/dom/action.ts +47 -21
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +57 -40
- package/src/dom/index.ts +54 -14
- package/src/dom/island.ts +102 -68
- package/src/dom/loop.ts +66 -32
- package/src/eco/declaration.ts +328 -0
- package/src/eco/index.ts +69 -0
- package/src/index.ts +2 -2
- package/src/jsx-runtime.ts +2 -2
- package/src/plugins/config.ts +18 -12
- package/src/plugins/context.ts +44 -1
- package/src/plugins/index.ts +2 -2
- package/src/plugins/load.ts +30 -10
- package/src/plugins/order.ts +38 -1
- package/src/plugins/public.ts +6 -3
- package/src/plugins/services.ts +84 -0
- package/src/plugins/types.ts +51 -2
- package/src/reactivity/graph.ts +10 -0
- package/src/reactivity/index.ts +24 -16
- package/src/reactivity/selector.ts +31 -4
- package/src/reactivity/store.ts +64 -20
- package/src/server/action-flash.ts +158 -0
- package/src/server/action-protect.ts +199 -0
- package/src/server/action-registry.ts +1 -1
- package/src/server/action.ts +188 -152
- package/src/server/app-secret.ts +63 -0
- package/src/server/assets.ts +34 -2
- package/src/server/compress.ts +96 -10
- package/src/server/consent.ts +59 -22
- package/src/server/cookies.ts +16 -2
- package/src/server/document.ts +25 -10
- package/src/server/env.ts +14 -0
- package/src/server/errors.ts +308 -65
- package/src/server/form-schema.ts +337 -0
- package/src/server/health.ts +275 -0
- package/src/server/http.ts +186 -39
- package/src/server/index.ts +272 -273
- package/src/server/loader.ts +15 -2
- package/src/server/page.ts +15 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +125 -88
- package/src/server/public.ts +6 -5
- package/src/server/rate-limit.ts +102 -36
- package/src/server/request-body.ts +1 -1
- package/src/server/route-cache.ts +541 -0
- package/src/server/route-table.ts +356 -11
- package/src/server/router.ts +125 -40
- package/src/server/routing.ts +112 -63
- package/src/server/sanitize-html.ts +309 -0
- package/src/server/security.ts +279 -52
- package/src/server/serve-handlers.ts +31 -7
- package/src/server/standard-schema.ts +17 -0
- package/src/server/start.ts +60 -16
- package/src/server/static-dir.ts +91 -12
- package/src/server/stream.ts +68 -27
- package/src/ssr/consent-banner.ts +58 -0
- package/src/ssr/context.ts +106 -8
- package/src/ssr/index.ts +151 -4
- package/src/ssr/navigation.ts +2 -2
- package/src/ssr/region.ts +40 -19
- package/src/style.ts +64 -1
- package/src/test/browser.ts +28 -13
- package/src/test/index.ts +97 -12
- package/src/ts-plugin/diagnostics.ts +505 -0
- package/src/ts-plugin/fixes.ts +364 -0
- package/src/ts-plugin/index.ts +194 -0
- package/templates/_shared/AGENTS.md +2 -2
- package/templates/_shared/gitignore +5 -0
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/src/routes/legal.tsx +15 -1
- package/templates/_shared/tsconfig.json +5 -0
- package/templates/app/.env.example +4 -0
- package/templates/app/package.json +2 -1
- package/templates/app/prunelle.config.ts +2 -0
- package/templates/app/src/auth.ts +4 -6
- package/templates/app/src/mail.ts +4 -0
- package/templates/app/src/routes/_layout.tsx +9 -1
- package/templates/app/src/routes/dashboard/index.tsx +42 -8
- package/templates/app/src/routes/login.tsx +49 -30
- package/templates/app/src/routes/privacy.tsx +25 -0
- package/templates/app/src/styles/app.css +8 -1
- package/templates/app/tests/app.test.ts +44 -3
- package/templates/blog/package.json +1 -1
- package/templates/blog/prunelle.config.ts +1 -1
- package/templates/blog/src/routes/_layout.tsx +6 -1
- package/templates/blog/src/routes/index.tsx +5 -1
- package/templates/blog/src/styles/app.css +6 -1
- package/templates/fullstack/package.json +1 -1
- package/templates/fullstack/src/components/GreetForm.tsx +2 -1
- package/templates/fullstack/src/routes/_layout.tsx +4 -0
- package/templates/fullstack/src/styles/app.css +11 -1
- package/templates/minimal/package.json +1 -1
- package/templates/minimal/src/routes/_layout.tsx +4 -0
- package/templates/minimal/src/styles/app.css +11 -1
- package/ts-plugin.cjs +4277 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// `prunelle check` warnings about what weakens an app's defences: dotfiles under public/, and the security opt-outs in its config.
|
|
2
|
+
|
|
3
|
+
import type { SecurityHeadersOptions } from '../server/security'
|
|
4
|
+
import { relative } from 'node:path'
|
|
5
|
+
import { isHiddenPublicPath, walkAllFiles } from '../build/files'
|
|
6
|
+
import { formatDiagnostic } from '../compiler/shared'
|
|
7
|
+
import { resolveCspPolicy } from '../server/security'
|
|
8
|
+
|
|
9
|
+
/** One warning per dotfile in `public/` (other than `.well-known`): the build leaves it out, so it is either dead weight or a secret about to be committed. */
|
|
10
|
+
export function publicDotfileWarnings(publicDir: string, root: string): string[] {
|
|
11
|
+
return walkAllFiles(publicDir)
|
|
12
|
+
.map(abs => ({ abs, rel: relative(publicDir, abs) }))
|
|
13
|
+
.filter(file => isHiddenPublicPath(file.rel))
|
|
14
|
+
.sort((a, b) => a.rel.localeCompare(b.rel))
|
|
15
|
+
.map(file => formatDiagnostic(`${relative(root, file.abs)}:1:1`, `[security/public-dotfile] "${file.rel}" is in public/ but the build does not copy dotfiles, so it is never served: delete it, or move it out of public/ (only .well-known/ is kept).`, 'warning'))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// `.redirect("https://…"` or `.redirect("//…"`: a literal address on another site, up to the closing parenthesis of the call.
|
|
19
|
+
const EXTERNAL_REDIRECT_RE = /\.redirect\(\s*(['"`])(?:https?:)?\/\/[^)]*\)/g
|
|
20
|
+
|
|
21
|
+
/** One warning per `ctx.redirect("https://other.site/…")` that lacks `{ external: true }`: since 0.x it throws at runtime. */
|
|
22
|
+
export function externalRedirectWarnings(files: readonly string[], read: (file: string) => string, locate: (file: string, offset: number) => string): string[] {
|
|
23
|
+
const warnings: string[] = []
|
|
24
|
+
for (const file of files) {
|
|
25
|
+
const code = read(file)
|
|
26
|
+
for (const match of code.matchAll(EXTERNAL_REDIRECT_RE)) {
|
|
27
|
+
if (!match[0].includes('external'))
|
|
28
|
+
warnings.push(formatDiagnostic(locate(file, match.index), '[security/external-redirect] ctx.redirect() to another site throws unless the app passes { external: true } as its third argument: add `{ external: true }` if the address is the app\'s own, and never pass one read from the request.', 'warning'))
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return warnings
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Fetch directives whose `'unsafe-inline'` lets an injected script or stylesheet run; `style-src-attr` is left out, as the default policy allows `style=""` attributes.
|
|
35
|
+
const INLINE_CODE_DIRECTIVES = new Set(['default-src', 'script-src', 'script-src-elem', 'style-src', 'style-src-elem'])
|
|
36
|
+
|
|
37
|
+
/** One warning for each way `security` in `prunelle.config.ts` turns a default defence off: all headers, the CSP, or `'unsafe-inline'` in it. */
|
|
38
|
+
export function securityConfigWarnings(security: SecurityHeadersOptions | false | undefined): string[] {
|
|
39
|
+
const at = 'prunelle.config.ts:1:1'
|
|
40
|
+
if (security === false)
|
|
41
|
+
return [formatDiagnostic(at, '[security/headers-off] security: false sends no CSP, HSTS, nosniff, frame, referrer, permissions, opener or resource policy header: drop it, and relax only the one header an integration needs (`security: { frameOptions: false }`).', 'warning')]
|
|
42
|
+
if (security?.csp === false)
|
|
43
|
+
return [formatDiagnostic(at, '[security/csp-off] security.csp is false, so no page carries a Content-Security-Policy: drop it, or extend the default with `security: { csp: { \'img-src\': [\'https://cdn.example\'] } }`.', 'warning')]
|
|
44
|
+
const csp = resolveCspPolicy(security)
|
|
45
|
+
const loose = (csp ?? '').split(';')
|
|
46
|
+
.map(part => part.trim().split(/\s+/))
|
|
47
|
+
.filter(([name, ...tokens]) => INLINE_CODE_DIRECTIVES.has(name!.toLowerCase()) && tokens.includes('\'unsafe-inline\''))
|
|
48
|
+
.map(([name]) => name!.toLowerCase())
|
|
49
|
+
return loose.length === 0
|
|
50
|
+
? []
|
|
51
|
+
: [formatDiagnostic(at, `[security/unsafe-inline] the CSP allows 'unsafe-inline' in ${loose.join(', ')}, which lets an injected script or style run: remove it, since prunelle hashes its own inline scripts and styles, or add a hash of the inline one you need.`, 'warning')]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const CSRF_OFF_RE = /export\s+const\s+csrf\s*=\s*false\b/g
|
|
55
|
+
|
|
56
|
+
/** One warning per route file that exports `csrf = false`: it accepts a cross-site POST, so it must check a signature or a token itself. */
|
|
57
|
+
export function csrfOffWarnings(files: readonly string[], read: (file: string) => string, locate: (file: string, offset: number) => string): string[] {
|
|
58
|
+
const warnings: string[] = []
|
|
59
|
+
for (const file of files) {
|
|
60
|
+
for (const match of read(file).matchAll(CSRF_OFF_RE))
|
|
61
|
+
warnings.push(formatDiagnostic(locate(file, match.index), '[security/csrf-off] this route skips the cross-site request check, so any site can post to it: keep it only for a webhook or bearer-token API that verifies a signature or token itself, and drop `export const csrf = false` for anything a browser form posts to.', 'warning'))
|
|
62
|
+
}
|
|
63
|
+
return warnings
|
|
64
|
+
}
|
package/src/cli/check.ts
CHANGED
|
@@ -3,20 +3,28 @@
|
|
|
3
3
|
import type { IslandIssue } from '../build/islands'
|
|
4
4
|
import type { ModuleAnalysis } from '../compiler/analyze'
|
|
5
5
|
import type { ComplianceConfig } from '../compiler/compliance'
|
|
6
|
-
import type { CheckPluginContext, PrunellePlugin } from '../plugins/index'
|
|
6
|
+
import type { CheckPluginContext, PrunelleConfig, PrunellePlugin } from '../plugins/index'
|
|
7
7
|
import { existsSync, readFileSync } from 'node:fs'
|
|
8
8
|
import { basename, join, relative, resolve } from 'node:path'
|
|
9
9
|
import { isInNodeModules, isNotSourceDir, isTsFile, relPosix, walkFiles, walkRoutes } from '../build/files'
|
|
10
10
|
import { ModuleGraph } from '../build/graph'
|
|
11
|
+
import { formatIslandValueWarnings } from '../build/island-promote'
|
|
11
12
|
import { nodeEnvWarning, renderProblems, serverNodeEnvReads } from '../build/render-rules'
|
|
12
13
|
import { analyzeIslands } from '../build/islands'
|
|
13
|
-
import { fileToRoutePath, hasRouteHandlerExport, missingPathsProblem, normalizeRoutePattern, routeExportProblemLocation, routeFileProblem, SPECIAL_ROUTE_FILES } from '../build/routes'
|
|
14
|
+
import { ancestorFiles, discoverRouteMatchers, fileToRoutePath, hasRouteHandlerExport, missingPathsProblem, normalizeRoutePattern, routeExportProblemLocation, routeFileProblem, SPECIAL_ROUTE_FILES } from '../build/routes'
|
|
15
|
+
import { findUnknownStatusPages } from '../build/status-pages'
|
|
14
16
|
import { analyzeModule } from '../compiler/analyze'
|
|
15
|
-
import {
|
|
17
|
+
import { findCachedRoutePrivateReads } from '../compiler/cacheability'
|
|
18
|
+
import { collectProjectComplianceWarnings, pluginSetsLang, shouldEmitWarning } from '../compiler/compliance'
|
|
16
19
|
import { collectMistakes, PrunelleMistake, serverOnlyTagError } from '../compiler/mistakes'
|
|
17
20
|
import { DIAGNOSTIC_PREFIX_RE, formatDiagnostic, formatLoc } from '../compiler/shared'
|
|
18
21
|
import { createAppContext, loadConfig, resolvePlugins, runWithAppContext } from '../plugins/index'
|
|
19
22
|
import { collectRequirements } from '../plugins/requires'
|
|
23
|
+
import { normalizeConsentConfig } from '../server/consent'
|
|
24
|
+
import { checkAppForms } from './check-forms'
|
|
25
|
+
import { unresolvedImport } from './check-imports'
|
|
26
|
+
import { checkAppLinks } from './check-links'
|
|
27
|
+
import { csrfOffWarnings, externalRedirectWarnings, publicDotfileWarnings, securityConfigWarnings } from './check-security'
|
|
20
28
|
|
|
21
29
|
/** Whether `prunelle check` typechecked the app, with which tool, or why it did not. */
|
|
22
30
|
export type TypecheckRun = { ran: true, tool: string } | { ran: false, reason: string }
|
|
@@ -162,10 +170,13 @@ function formatIslandIssue(issue: IslandIssue, root: string, sources: Map<string
|
|
|
162
170
|
return formatDiagnostic(locOf(root, issue.file, sources, issue.offset), message)
|
|
163
171
|
}
|
|
164
172
|
case 'private-env': {
|
|
165
|
-
const
|
|
173
|
+
const isImportMeta = issue.envKind === 'process' && sources.get(issue.file)?.slice(issue.offset, issue.offset + 15).startsWith('import.meta') === true
|
|
174
|
+
const envName = issue.envKind === 'bun' ? 'Bun.env' : isImportMeta ? 'import.meta.env' : 'process.env'
|
|
166
175
|
const hint = issue.envKind === 'bun'
|
|
167
176
|
? 'Bun.env is server-only and is not inlined in browser bundles; use process.env.PUBLIC_* for build-time client values.'
|
|
168
|
-
:
|
|
177
|
+
: isImportMeta
|
|
178
|
+
? 'Only import.meta.env.PUBLIC_* and MODE/DEV/PROD reach the browser.'
|
|
179
|
+
: 'Only process.env.PUBLIC_* reaches the browser.'
|
|
169
180
|
return formatDiagnostic(locOf(root, issue.file, sources, issue.offset), `prunelle check: reads ${envName} and is reachable from the island in ${relPosix(root, issue.island)}. ${hint}`)
|
|
170
181
|
}
|
|
171
182
|
case 'compiler-mistake':
|
|
@@ -174,16 +185,19 @@ function formatIslandIssue(issue: IslandIssue, root: string, sources: Map<string
|
|
|
174
185
|
}
|
|
175
186
|
|
|
176
187
|
// Each plugin's check(ctx) runs inside a real AppRuntimeContext; what it reports without a place lands on prunelle.config.ts.
|
|
177
|
-
async function runPluginChecks(plugins: readonly PrunellePlugin[], paths: { root: string, routesDir: string, outDir: string, assetPrefix: string, site: string | undefined }, errors: string[], warnings: string[]): Promise<void> {
|
|
178
|
-
const { root, routesDir, outDir, assetPrefix, site } = paths
|
|
179
|
-
const appCtx = createAppContext({ root, outDir, publicDir: join(outDir, 'public'), assetPrefix, dev: false })
|
|
188
|
+
async function runPluginChecks(plugins: readonly PrunellePlugin[], paths: { root: string, routesDir: string, publicDir: string, outDir: string, assetPrefix: string, site: string | undefined, consentCategories: readonly string[] }, errors: string[], warnings: string[]): Promise<void> {
|
|
189
|
+
const { root, routesDir, publicDir, outDir, assetPrefix, site, consentCategories } = paths
|
|
190
|
+
const appCtx = createAppContext({ root, outDir, publicDir: join(outDir, 'public'), assetPrefix, site, dev: false })
|
|
180
191
|
const placed = (message: string, severity: 'error' | 'warning'): string =>
|
|
181
192
|
DIAGNOSTIC_PREFIX_RE.test(message) ? message : formatDiagnostic('prunelle.config.ts:1:1', message, severity)
|
|
182
193
|
const pluginCtx: CheckPluginContext = {
|
|
183
194
|
root,
|
|
184
195
|
routesDir,
|
|
196
|
+
publicDir,
|
|
185
197
|
error: message => errors.push(placed(message, 'error')),
|
|
186
198
|
warn: message => warnings.push(placed(message, 'warning')),
|
|
199
|
+
provide: appCtx.provide,
|
|
200
|
+
inject: appCtx.inject,
|
|
187
201
|
}
|
|
188
202
|
for (const plugin of plugins) {
|
|
189
203
|
if (plugin.check === undefined)
|
|
@@ -195,7 +209,7 @@ async function runPluginChecks(plugins: readonly PrunellePlugin[], paths: { root
|
|
|
195
209
|
errors.push(placed(`${plugin.name}: ${err instanceof Error ? err.message : String(err)}`, 'error'))
|
|
196
210
|
}
|
|
197
211
|
}
|
|
198
|
-
const { unmet, failed } = await runWithAppContext(appCtx, () => collectRequirements(plugins, { root, site }))
|
|
212
|
+
const { unmet, failed } = await runWithAppContext(appCtx, () => collectRequirements(plugins, { root, site, consentCategories }))
|
|
199
213
|
for (const line of unmet)
|
|
200
214
|
warnings.push(placed(`${line} (a production start refuses until it is set)`, 'warning'))
|
|
201
215
|
for (const line of failed)
|
|
@@ -203,6 +217,17 @@ async function runPluginChecks(plugins: readonly PrunellePlugin[], paths: { root
|
|
|
203
217
|
}
|
|
204
218
|
|
|
205
219
|
|
|
220
|
+
function discoverProjectFiles(srcDir: string, routesDir: string, configFile: string): string[] {
|
|
221
|
+
const fileSet = new Set<string>()
|
|
222
|
+
if (existsSync(srcDir))
|
|
223
|
+
walkTsFiles(srcDir).forEach(f => fileSet.add(f))
|
|
224
|
+
if (existsSync(routesDir))
|
|
225
|
+
walkTsFiles(routesDir).forEach(f => fileSet.add(f))
|
|
226
|
+
if (existsSync(configFile))
|
|
227
|
+
fileSet.add(configFile)
|
|
228
|
+
return [...fileSet].sort()
|
|
229
|
+
}
|
|
230
|
+
|
|
206
231
|
export async function checkProject(rootDir: string, options: { skipTypecheck?: boolean } = {}): Promise<CheckResult> {
|
|
207
232
|
const root = resolve(rootDir)
|
|
208
233
|
const errors: string[] = []
|
|
@@ -210,19 +235,26 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
210
235
|
// 1. Validate prunelle.config.ts
|
|
211
236
|
let routesDir = resolve(root, 'src/routes')
|
|
212
237
|
let outDir = resolve(root, 'dist')
|
|
238
|
+
let publicDir = resolve(root, 'public')
|
|
213
239
|
let assetPrefix = '/_pru'
|
|
214
240
|
let site: string | undefined
|
|
215
241
|
let compliance: ComplianceConfig | undefined
|
|
242
|
+
let loadedConfig: PrunelleConfig = {}
|
|
216
243
|
let plugins: Awaited<ReturnType<typeof loadConfig>>['plugins'] = []
|
|
244
|
+
let consentCategories: readonly string[] = []
|
|
217
245
|
try {
|
|
218
246
|
const cfg = await loadConfig(root)
|
|
247
|
+
loadedConfig = cfg
|
|
219
248
|
plugins = resolvePlugins(cfg.plugins)
|
|
249
|
+
consentCategories = normalizeConsentConfig(cfg.consent)?.categories ?? []
|
|
220
250
|
site = cfg.site
|
|
221
251
|
compliance = cfg.compliance
|
|
222
252
|
if (cfg.routesDir !== undefined)
|
|
223
253
|
routesDir = resolve(root, cfg.routesDir)
|
|
224
254
|
if (cfg.outDir !== undefined)
|
|
225
255
|
outDir = resolve(root, cfg.outDir)
|
|
256
|
+
if (cfg.publicDir !== undefined)
|
|
257
|
+
publicDir = resolve(root, cfg.publicDir)
|
|
226
258
|
if (cfg.assetPrefix !== undefined)
|
|
227
259
|
assetPrefix = cfg.assetPrefix.replace(/\/$/, '')
|
|
228
260
|
}
|
|
@@ -236,18 +268,10 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
236
268
|
errors.push(formatDiagnostic(`${relRoutes.replace(/\\/g, '/')}:1:1`, `prunelle check: missing routes directory: ${relRoutes}`))
|
|
237
269
|
}
|
|
238
270
|
|
|
239
|
-
// 3. Parse & run Prunelle static compiler analysis across src
|
|
271
|
+
// 3. Parse & run Prunelle static compiler analysis across src/, custom routesDir, and prunelle.config.ts
|
|
240
272
|
const srcDir = resolve(root, 'src')
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
for (const f of walkTsFiles(srcDir))
|
|
244
|
-
fileSet.add(f)
|
|
245
|
-
}
|
|
246
|
-
if (existsSync(routesDir)) {
|
|
247
|
-
for (const f of walkTsFiles(routesDir))
|
|
248
|
-
fileSet.add(f)
|
|
249
|
-
}
|
|
250
|
-
const files = [...fileSet].sort()
|
|
273
|
+
const configFile = resolve(root, 'prunelle.config.ts')
|
|
274
|
+
const files = discoverProjectFiles(srcDir, routesDir, configFile)
|
|
251
275
|
const graph = new ModuleGraph(root)
|
|
252
276
|
const { analyses } = graph
|
|
253
277
|
const sources = new Map<string, string>()
|
|
@@ -265,9 +289,19 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
265
289
|
|
|
266
290
|
// Exact route discovery matching `prunelle build` (`walkRoutes` skips `_components/` dirs, `.d.ts`, `.test.ts`)
|
|
267
291
|
const routeFiles = existsSync(routesDir) ? walkRoutes(routesDir).sort() : []
|
|
292
|
+
for (const unknown of findUnknownStatusPages(root, routeFiles))
|
|
293
|
+
errors.push(formatDiagnostic(`${relPosix(root, unknown.file)}:1:1`, `prunelle check: ${unknown.message}`))
|
|
268
294
|
const routeFileSet = new Set(routeFiles)
|
|
269
295
|
const specialFiles = routeFiles.filter(f => SPECIAL_ROUTE_FILES.has(basename(f)))
|
|
270
296
|
const pageFiles = routeFiles.filter(f => !basename(f).startsWith('_') && analyses.has(f) && hasRouteHandlerExport(analyses.get(f)!))
|
|
297
|
+
const matcherDiscovery = discoverRouteMatchers({
|
|
298
|
+
root,
|
|
299
|
+
routesDir,
|
|
300
|
+
routeFiles: [...specialFiles, ...pageFiles],
|
|
301
|
+
loadAnalysis: load,
|
|
302
|
+
})
|
|
303
|
+
for (const problem of matcherDiscovery.problems)
|
|
304
|
+
errors.push(formatDiagnostic(`${relPosix(root, problem.file)}:1:1`, `prunelle check: ${problem.message}`))
|
|
271
305
|
|
|
272
306
|
// 3a. Unified island planning, state-read promotion, special-file checks & reachability checks (shared with `prunelle build`)
|
|
273
307
|
const islands = analyzeIslands({
|
|
@@ -281,6 +315,11 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
281
315
|
})
|
|
282
316
|
for (const issue of islands.issues)
|
|
283
317
|
errors.push(formatIslandIssue(issue, root, sources))
|
|
318
|
+
warnings.push(...formatIslandValueWarnings(islands.valueUses, root, graph, f => sourceOf(f, sources), compliance))
|
|
319
|
+
for (const { file, warning } of islands.promotedWarnings) {
|
|
320
|
+
if (shouldEmitWarning(warning, compliance, site))
|
|
321
|
+
warnings.push(formatDiagnostic(locOf(root, file, sources, warning.start), warning.message.replaceAll(file, relPosix(root, file)), 'warning'))
|
|
322
|
+
}
|
|
284
323
|
|
|
285
324
|
// 3b. Static guardrails: non-serializable island props, route exports, route conflicts, missing paths()
|
|
286
325
|
const seenRoutes = new Map<string, string>()
|
|
@@ -288,8 +327,20 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
288
327
|
if (isInNodeModules(file))
|
|
289
328
|
continue
|
|
290
329
|
const rel = relPosix(root, file)
|
|
291
|
-
for (const
|
|
292
|
-
|
|
330
|
+
for (const imp of analysis.imports) {
|
|
331
|
+
const unresolved = unresolvedImport(file, rel, imp.source, imp.specifiers)
|
|
332
|
+
if (unresolved !== undefined)
|
|
333
|
+
errors.push(formatDiagnostic(locOf(root, file, sources, imp.start), unresolved))
|
|
334
|
+
if (imp.source === '@prunellejs/auth') {
|
|
335
|
+
const removed = imp.specifiers.find(s => s.imported === 'createRateLimiter' || s.imported === 'RateLimiter')
|
|
336
|
+
if (removed !== undefined)
|
|
337
|
+
warnings.push(formatDiagnostic(locOf(root, file, sources, imp.start), `prunelle check: ${removed.imported} was removed from @prunellejs/auth in 0.2.0: use \`rateLimit\` on \`api.route()\`/\`action()\`, \`api.rateLimiter()\` in a plugin, or \`createRateLimitStore()\` from \`prunelle/server\`.`, 'warning'))
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (file !== configFile) {
|
|
341
|
+
for (const offset of serverNodeEnvReads(analysis, islands, file))
|
|
342
|
+
warnings.push(formatDiagnostic(locOf(root, file, sources, offset), nodeEnvWarning(rel), 'warning'))
|
|
343
|
+
}
|
|
293
344
|
|
|
294
345
|
if (file.endsWith('.tsx')) {
|
|
295
346
|
for (const problem of renderProblems(analysis, islands, file, rel, 'prunelle check'))
|
|
@@ -322,11 +373,35 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
322
373
|
}
|
|
323
374
|
}
|
|
324
375
|
|
|
325
|
-
// 3c.
|
|
326
|
-
|
|
376
|
+
// 3c. Cached route private-read guardrails (#6)
|
|
377
|
+
for (const problem of findCachedRoutePrivateReads({
|
|
378
|
+
graph,
|
|
379
|
+
pageFiles,
|
|
380
|
+
layoutsFor: file => ancestorFiles(routesDir, file, ['_layout.tsx']),
|
|
381
|
+
toRel: file => relPosix(root, file),
|
|
382
|
+
tool: 'prunelle check',
|
|
383
|
+
})) {
|
|
384
|
+
errors.push(formatDiagnostic(locOf(root, problem.file, sources, problem.offset), problem.message))
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// 3d. French web law compliance checks (CSS third-party URLs, LCEN legal notice, RGAA accessibility statement)
|
|
388
|
+
warnings.push(...collectProjectComplianceWarnings({ root, srcDir, routesDir, publicDir, routeFiles, analyses, compliance, consentMaxAge: loadedConfig.consent?.maxAge, site, lang: loadedConfig.lang, langFromPlugin: pluginSetsLang(plugins) }))
|
|
389
|
+
|
|
390
|
+
// 3d. Form field / schema checks & public action protection warnings (#4, #5)
|
|
391
|
+
const formCheck = await checkAppForms({ root, routesDir, routeFiles, graph, sources, compliance })
|
|
392
|
+
errors.push(...formCheck.errors)
|
|
393
|
+
warnings.push(...formCheck.warnings)
|
|
394
|
+
|
|
395
|
+
warnings.push(...publicDotfileWarnings(publicDir, root))
|
|
396
|
+
warnings.push(...securityConfigWarnings(loadedConfig.security))
|
|
397
|
+
warnings.push(...csrfOffWarnings(routeFiles, file => sourceOf(file, sources), (file, offset) => locOf(root, file, sources, offset)))
|
|
398
|
+
warnings.push(...externalRedirectWarnings(files, file => sourceOf(file, sources), (file, offset) => locOf(root, file, sources, offset)))
|
|
399
|
+
|
|
400
|
+
// 3e. Broken internal link checks (#3)
|
|
401
|
+
warnings.push(...await checkAppLinks({ root, routesDir, publicDir, assetPrefix, site, config: loadedConfig, plugins, routeFiles, analyses, sources }))
|
|
327
402
|
|
|
328
|
-
//
|
|
329
|
-
await runPluginChecks(plugins, { root, routesDir, outDir, assetPrefix, site }, errors, warnings)
|
|
403
|
+
// 3f. Plugin check(ctx) hooks
|
|
404
|
+
await runPluginChecks(plugins, { root, routesDir, publicDir, outDir, assetPrefix, site, consentCategories }, errors, warnings)
|
|
330
405
|
|
|
331
406
|
const typecheck = options.skipTypecheck === true ? { ran: false as const, reason: "skipped by --no-typecheck" } : runTypecheck(root, errors)
|
|
332
407
|
|
package/src/cli/commands.ts
CHANGED
|
@@ -4,9 +4,10 @@ import type { Commands, ExitRow } from '@kaynooo/cli-kit'
|
|
|
4
4
|
import type { ScaffoldTemplate } from './new'
|
|
5
5
|
import { resolve } from 'node:path'
|
|
6
6
|
import { badUsage, Exit, fail, parse } from '@kaynooo/cli-kit'
|
|
7
|
+
import { parseByteSize } from '../build/byte-size'
|
|
7
8
|
|
|
8
9
|
const TEMPLATES = ['minimal', 'fullstack', 'blog', 'app'] as const
|
|
9
|
-
|
|
10
|
+
|
|
10
11
|
|
|
11
12
|
const ROOT = { type: 'string', description: 'the app folder, when it is not the current one or the [dir] argument' } as const
|
|
12
13
|
const PORT = { type: 'string', description: 'the port to listen on (PORT, then prunelle.config.ts port, then 3000; 0 picks a free one)' } as const
|
|
@@ -17,10 +18,7 @@ const USAGE_EXIT: ExitRow = [2, 'a usage error']
|
|
|
17
18
|
|
|
18
19
|
// `--max-js 40kb`, `--max-js 40KB` or `--max-js 40960` (bytes).
|
|
19
20
|
function parseSize(raw: string): number {
|
|
20
|
-
|
|
21
|
-
if (match === null)
|
|
22
|
-
return badUsage(`invalid --max-js "${raw}": give the gzipped size of a route's eager JS in bytes or KB, e.g. --max-js 40kb`)
|
|
23
|
-
return Math.round(Number(match[1]) * (match[2] === undefined ? 1 : 1024))
|
|
21
|
+
return parseByteSize(raw) ?? badUsage(`invalid --max-js "${raw}": give the gzipped size of a route's eager JS in bytes or KB, e.g. --max-js 40kb`)
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
function parsePort(raw: string | number | undefined, fallback: number): number {
|
|
@@ -64,6 +62,9 @@ function newCommand(cwd: string): Commands[string] {
|
|
|
64
62
|
const { scaffoldProject } = await import('./new')
|
|
65
63
|
const template = (values.template ?? 'minimal') as ScaffoldTemplate
|
|
66
64
|
const res = await failing('new', async () => scaffoldProject(rootOf(cwd, values.root, dir), { template, force: values.force === true }))
|
|
65
|
+
|
|
66
|
+
for (const file of res.overwritten)
|
|
67
|
+
console.log(`prunelle new: overwrote ${file}`)
|
|
67
68
|
console.log(`Created Prunelle (${template}) project in ${res.root} (${res.files.length} files)`)
|
|
68
69
|
console.log(`\nNext steps:\n cd ${dir}\n bun install\n bun run dev`)
|
|
69
70
|
return 0
|
|
@@ -119,17 +120,22 @@ function upgradeCommand(cwd: string): Commands[string] {
|
|
|
119
120
|
'root': ROOT,
|
|
120
121
|
}, { positionals: ['[dir]'], exits: [[0, 'every file was rewritten and nothing is left to do by hand'], [1, 'bun install failed, or steps are left to do by hand (printed)'], USAGE_EXIT] })
|
|
121
122
|
const root = rootOf(cwd, values.root, dir)
|
|
122
|
-
const { upgradeProject } = await import('./upgrade')
|
|
123
|
+
const { notAnApp, upgradeProject } = await import('./upgrade')
|
|
124
|
+
const refused = notAnApp(root)
|
|
125
|
+
if (refused !== undefined)
|
|
126
|
+
return fail(refused, 1, 'run prunelle upgrade in the app\'s folder, or pass that folder as [dir]')
|
|
123
127
|
const res = upgradeProject(root)
|
|
124
128
|
for (const file of res.changed)
|
|
125
129
|
console.log(` ${file}`)
|
|
126
|
-
console.log(`prunelle upgrade rewrote ${res.changed.length}
|
|
127
|
-
|
|
130
|
+
console.log(`prunelle upgrade rewrote ${res.changed.length} file${res.changed.length === 1 ? '' : 's'}`)
|
|
131
|
+
// The dependencies moved: the first run for this app, which renames its cookies; a later run only fixes what an older prunelle left.
|
|
132
|
+
const moved = res.changed.some(file => file === 'package.json' || file.endsWith('/package.json'))
|
|
133
|
+
if (moved && values['no-install'] !== true) {
|
|
128
134
|
const install = Bun.spawnSync(['bun', 'install'], { cwd: root, stdout: 'inherit', stderr: 'inherit' })
|
|
129
135
|
if (install.exitCode !== 0)
|
|
130
136
|
return 1
|
|
131
137
|
}
|
|
132
|
-
if (
|
|
138
|
+
if (moved)
|
|
133
139
|
console.log('Signed-in users sign in again and visitors answer the cookie banner again: prunelle names its cookies pru_session and pru_consent.')
|
|
134
140
|
for (const line of res.manual)
|
|
135
141
|
console.error(line)
|
|
@@ -163,6 +169,7 @@ function buildCommand(cwd: string): Commands[string] {
|
|
|
163
169
|
run: async (args) => {
|
|
164
170
|
const { values, positionals: [dir] } = parse(args, 'prunelle build [options] [dir]: builds the app into dist/', {
|
|
165
171
|
'static': { type: 'boolean', description: 'export plain HTML files instead of a server' },
|
|
172
|
+
'auto-prerender': { type: 'boolean', description: 'prerender static pages that read nothing from the request or clock' },
|
|
166
173
|
'compile': { type: 'string', optional: { bare: '' }, description: 'also produce one binary, at [out] when given' },
|
|
167
174
|
'analyze': { type: 'boolean', description: 'list each island with why it is one' },
|
|
168
175
|
'json': { type: 'boolean', description: 'with --analyze, print the bundle report as JSON' },
|
|
@@ -176,7 +183,8 @@ function buildCommand(cwd: string): Commands[string] {
|
|
|
176
183
|
const analyzeJson = values.analyze === true && values.json === true
|
|
177
184
|
const { build } = await import('../build/index')
|
|
178
185
|
const t0 = performance.now()
|
|
179
|
-
const
|
|
186
|
+
const autoPrerender = values['auto-prerender'] === true ? true : undefined
|
|
187
|
+
const manifest = await failing('build', async () => build({ root: rootOf(cwd, values.root, dir), static: values.static === true, autoPrerender, compile, analyze: values.analyze === true, analyzeJson, maxJs }))
|
|
180
188
|
const ms = (performance.now() - t0).toFixed(1)
|
|
181
189
|
if (!analyzeJson)
|
|
182
190
|
console.log(`prunelle build done in ${ms} ms (${manifest.routes.length} routes, ${manifest.assets.length} client assets, ${manifest.actions.length} actions)`)
|
|
@@ -185,6 +193,25 @@ function buildCommand(cwd: string): Commands[string] {
|
|
|
185
193
|
}
|
|
186
194
|
}
|
|
187
195
|
|
|
196
|
+
function ecoCommand(cwd: string): Commands[string] {
|
|
197
|
+
return {
|
|
198
|
+
summary: 'judge the RGESN eco-design criteria prunelle can measure, and draft the declaration',
|
|
199
|
+
run: async (args) => {
|
|
200
|
+
const { values, positionals: [dir] } = parse(args, 'prunelle eco [options] [dir]: builds the app and judges the RGESN 2024 criteria prunelle can measure', {
|
|
201
|
+
declaration: { type: 'string', optional: { bare: '' }, description: 'write an editable RGESN 2024 eco-design declaration page (default: src/routes/ecoconception.tsx)' },
|
|
202
|
+
service: { type: 'string', description: 'the service\'s name, written into --declaration' },
|
|
203
|
+
org: { type: 'string', description: 'the entity running the evaluation, written into --declaration' },
|
|
204
|
+
contact: { type: 'string', description: 'the contact email, written into --declaration' },
|
|
205
|
+
root: ROOT,
|
|
206
|
+
}, { positionals: ['[dir]'], exits: [OK, [1, 'the build failed'], USAGE_EXIT] })
|
|
207
|
+
const { formatEcoResult, runEco } = await import('../eco/index')
|
|
208
|
+
const result = await failing('eco', () => runEco({ root: rootOf(cwd, values.root, dir), declaration: values.declaration, service: values.service, organization: values.org, contactEmail: values.contact }))
|
|
209
|
+
console.log(formatEcoResult(result))
|
|
210
|
+
return 0
|
|
211
|
+
},
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
188
215
|
const SERVE_EXITS: ExitRow[] = [[0, 'the server started'], [1, 'the config or the server failed to load'], USAGE_EXIT]
|
|
189
216
|
|
|
190
217
|
function startCommand(cwd: string): Commands[string] {
|
|
@@ -203,6 +230,10 @@ function startCommand(cwd: string): Commands[string] {
|
|
|
203
230
|
const { app, server } = await failing('start', async () => startServer({ root, port, hostname }))
|
|
204
231
|
handleSignals(app, server)
|
|
205
232
|
console.log(`prunelle server listening on http://${hostname}:${server.port}`)
|
|
233
|
+
const { loopbackBindNotice } = await import('../server/security')
|
|
234
|
+
const notice = process.env.NODE_ENV === 'production' ? loopbackBindNotice(hostname, values.host !== undefined || Boolean(process.env.HOST)) : undefined
|
|
235
|
+
if (notice !== undefined)
|
|
236
|
+
console.warn(notice)
|
|
206
237
|
return 0
|
|
207
238
|
},
|
|
208
239
|
}
|
|
@@ -219,7 +250,7 @@ function devCommand(cwd: string): Commands[string] {
|
|
|
219
250
|
const port = parsePort(values.port ?? (process.env.PORT || config.port), 3000)
|
|
220
251
|
const hostname = values.host ?? (process.env.HOST || '127.0.0.1')
|
|
221
252
|
const { devSupervisor } = await import('../dev/supervisor')
|
|
222
|
-
const dev = await failing('dev', async () => devSupervisor({ root, port, hostname, maxRequestBodySize: resolveServerConfig(config, {}).maxRequestBodySize }))
|
|
253
|
+
const dev = await failing('dev', async () => devSupervisor({ root, port, hostname, maxRequestBodySize: resolveServerConfig(config, {}).maxRequestBodySize, allowedOrigins: [config.site, ...config.trustedOrigins ?? []] }))
|
|
223
254
|
for (const signal of ['SIGINT', 'SIGTERM'] as const)
|
|
224
255
|
process.once(signal, () => void dev.stop().finally(() => process.exit(0)))
|
|
225
256
|
return 0
|
|
@@ -227,13 +258,91 @@ function devCommand(cwd: string): Commands[string] {
|
|
|
227
258
|
}
|
|
228
259
|
}
|
|
229
260
|
|
|
261
|
+
function docsCommand(cwd: string): Commands[string] {
|
|
262
|
+
return {
|
|
263
|
+
summary: 'search llms.txt across prunelle and installed plugins',
|
|
264
|
+
run: async (args) => {
|
|
265
|
+
const { values, positionals } = parse(args, 'prunelle docs [options] <words...>: searches llms.txt of prunelle and every installed @prunellejs/* package', {
|
|
266
|
+
json: { type: 'boolean', description: 'print { query, words, packages, matches } as JSON' },
|
|
267
|
+
limit: { type: 'string', description: 'maximum matching sections to print (default: 20)' },
|
|
268
|
+
root: ROOT,
|
|
269
|
+
}, { positionals: ['<words...>'], exits: [OK, [1, 'no matching section found'], USAGE_EXIT] })
|
|
270
|
+
const limit = values.limit === undefined ? undefined : Number(values.limit)
|
|
271
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit <= 0))
|
|
272
|
+
return badUsage(`invalid --limit "${values.limit}": give a positive integer`)
|
|
273
|
+
const query = positionals.join(' ').trim()
|
|
274
|
+
if (query === '')
|
|
275
|
+
return badUsage('give at least one search word, e.g. prunelle docs action')
|
|
276
|
+
const { formatDocsSearchResult, searchLlmsDocs } = await import('./docs')
|
|
277
|
+
const result = searchLlmsDocs(rootOf(cwd, values.root, undefined), query, { limit })
|
|
278
|
+
if (values.json === true) {
|
|
279
|
+
console.log(JSON.stringify(result, null, 2))
|
|
280
|
+
return result.matches.length > 0 ? 0 : 1
|
|
281
|
+
}
|
|
282
|
+
console.log(formatDocsSearchResult(result))
|
|
283
|
+
return result.matches.length > 0 ? 0 : 1
|
|
284
|
+
},
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function renderCommand(cwd: string): Commands[string] {
|
|
289
|
+
return {
|
|
290
|
+
summary: 'render a URL in-process without binding a port',
|
|
291
|
+
run: async (args) => {
|
|
292
|
+
const { values, positionals: [url] } = parse(args, 'prunelle render [options] <url>: builds or reuses a test build and prints the response with no port bound', {
|
|
293
|
+
method: { type: 'string', short: 'X', description: 'HTTP method (default: GET, or POST when --body is passed)' },
|
|
294
|
+
body: { type: 'string', short: 'd', description: 'request body string' },
|
|
295
|
+
header: { type: 'string', short: 'H', multiple: true, description: 'request header as "Name: Value" (repeatable)' },
|
|
296
|
+
cookie: { type: 'string', short: 'b', multiple: true, description: 'request cookie as "name=value" (repeatable)' },
|
|
297
|
+
include: { type: 'boolean', short: 'i', description: 'include HTTP status line and response headers before the body' },
|
|
298
|
+
fresh: { type: 'boolean', description: 'force a fresh build instead of reusing the cached render build' },
|
|
299
|
+
root: ROOT,
|
|
300
|
+
}, { positionals: ['<url>'], exits: [[0, 'response status is 2xx or 3xx'], [1, 'response status is 4xx/5xx or the render failed'], USAGE_EXIT] })
|
|
301
|
+
const { renderUrl, writeRenderResult } = await import('./render')
|
|
302
|
+
const result = await failing('render', () => renderUrl({
|
|
303
|
+
root: rootOf(cwd, values.root, undefined),
|
|
304
|
+
url: url!,
|
|
305
|
+
method: values.method,
|
|
306
|
+
body: values.body,
|
|
307
|
+
headers: values.header,
|
|
308
|
+
cookies: values.cookie,
|
|
309
|
+
includeHeaders: values.include === true,
|
|
310
|
+
fresh: values.fresh === true,
|
|
311
|
+
}))
|
|
312
|
+
writeRenderResult(result, values.include === true)
|
|
313
|
+
return result.ok ? 0 : 1
|
|
314
|
+
},
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function mcpCommand(cwd: string): Commands[string] {
|
|
319
|
+
return {
|
|
320
|
+
summary: 'run the Prunelle stdio MCP server for coding agents',
|
|
321
|
+
run: async (args) => {
|
|
322
|
+
const { values, positionals: [dir] } = parse(args, 'prunelle mcp [options] [dir]: runs a stdio MCP server exposing check, inspect, build analysis, render, docs, dev errors, and llms.txt resources', {
|
|
323
|
+
'allow-write': { type: 'boolean', description: 'allow MCP tools that write build output to disk' },
|
|
324
|
+
'root': ROOT,
|
|
325
|
+
}, { positionals: ['[dir]'], exits: [OK, [1, 'the MCP server exited with an error'], USAGE_EXIT] })
|
|
326
|
+
const { runPrunelleMcpStdio } = await import('./mcp')
|
|
327
|
+
return await failing('mcp', () => runPrunelleMcpStdio({
|
|
328
|
+
root: rootOf(cwd, values.root, dir),
|
|
329
|
+
allowWrite: values['allow-write'] === true,
|
|
330
|
+
}))
|
|
331
|
+
},
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
230
335
|
export function builtinCommands(cwd: string): Commands {
|
|
231
336
|
return {
|
|
232
337
|
new: newCommand(cwd),
|
|
233
338
|
check: checkCommand(cwd),
|
|
234
339
|
inspect: inspectCommand(cwd),
|
|
340
|
+
docs: docsCommand(cwd),
|
|
341
|
+
render: renderCommand(cwd),
|
|
342
|
+
mcp: mcpCommand(cwd),
|
|
235
343
|
dev: devCommand(cwd),
|
|
236
344
|
build: buildCommand(cwd),
|
|
345
|
+
eco: ecoCommand(cwd),
|
|
237
346
|
start: startCommand(cwd),
|
|
238
347
|
upgrade: upgradeCommand(cwd),
|
|
239
348
|
}
|