prunelle 0.0.0-stage → 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.
Files changed (222) hide show
  1. package/LICENSE +21 -0
  2. package/llms.txt +245 -0
  3. package/package.json +62 -4
  4. package/src/a11y/declaration.ts +373 -0
  5. package/src/a11y/index.ts +477 -0
  6. package/src/a11y/rgaa-map.ts +230 -0
  7. package/src/ambient.d.ts +6 -0
  8. package/src/attrs.ts +43 -0
  9. package/src/build/bundle.ts +661 -0
  10. package/src/build/byte-size.ts +11 -0
  11. package/src/build/carry.ts +57 -0
  12. package/src/build/client-entries.ts +107 -0
  13. package/src/build/client-plugin.ts +175 -0
  14. package/src/build/client-prune.ts +168 -0
  15. package/src/build/compile.ts +130 -0
  16. package/src/build/ecoindex.ts +238 -0
  17. package/src/build/files.ts +171 -0
  18. package/src/build/first-load.ts +235 -0
  19. package/src/build/graph.ts +237 -0
  20. package/src/build/index.ts +678 -0
  21. package/src/build/is-inside.ts +12 -0
  22. package/src/build/island-promote.ts +311 -0
  23. package/src/build/islands.ts +452 -0
  24. package/src/build/manifest.ts +204 -0
  25. package/src/build/output.ts +81 -0
  26. package/src/build/plugin-host.ts +294 -0
  27. package/src/build/precompress.ts +139 -0
  28. package/src/build/prerender.ts +288 -0
  29. package/src/build/reach.ts +200 -0
  30. package/src/build/render-rules.ts +205 -0
  31. package/src/build/report.ts +290 -0
  32. package/src/build/resolve.ts +52 -0
  33. package/src/build/routes.ts +342 -0
  34. package/src/build/server-entry.ts +38 -0
  35. package/src/build/static-headers.ts +112 -0
  36. package/src/build/static.ts +209 -0
  37. package/src/build/status-pages.ts +127 -0
  38. package/src/build/style-bundles.ts +526 -0
  39. package/src/cli/check-forms.ts +636 -0
  40. package/src/cli/check-imports.ts +31 -0
  41. package/src/cli/check-links.ts +632 -0
  42. package/src/cli/check-security.ts +64 -0
  43. package/src/cli/check.ts +409 -0
  44. package/src/cli/commands.ts +372 -0
  45. package/src/cli/docs.ts +403 -0
  46. package/src/cli/index.ts +70 -0
  47. package/src/cli/inspect.ts +406 -0
  48. package/src/cli/mcp-tools.ts +492 -0
  49. package/src/cli/mcp.ts +205 -0
  50. package/src/cli/new.ts +52 -0
  51. package/src/cli/render.ts +416 -0
  52. package/src/cli/upgrade-names.ts +209 -0
  53. package/src/cli/upgrade.ts +367 -0
  54. package/src/compiler/analyze.ts +651 -0
  55. package/src/compiler/ast.ts +82 -0
  56. package/src/compiler/browser-globals.ts +250 -0
  57. package/src/compiler/cacheability-private.ts +566 -0
  58. package/src/compiler/cacheability.ts +335 -0
  59. package/src/compiler/compliance-eco.ts +71 -0
  60. package/src/compiler/compliance-rgaa.ts +614 -0
  61. package/src/compiler/compliance-urls.ts +148 -0
  62. package/src/compiler/compliance.ts +653 -0
  63. package/src/compiler/data-keys.ts +302 -0
  64. package/src/compiler/dev-source.ts +87 -0
  65. package/src/compiler/dom-attrs.ts +452 -0
  66. package/src/compiler/dom.ts +641 -0
  67. package/src/compiler/emit.ts +131 -0
  68. package/src/compiler/expr-context.ts +587 -0
  69. package/src/compiler/foreign-imports.ts +88 -0
  70. package/src/compiler/index.ts +8 -0
  71. package/src/compiler/interactivity.ts +366 -0
  72. package/src/compiler/mistakes.ts +520 -0
  73. package/src/compiler/node-env.ts +50 -0
  74. package/src/compiler/patch.ts +97 -0
  75. package/src/compiler/props-body.ts +60 -0
  76. package/src/compiler/props.ts +511 -0
  77. package/src/compiler/scope.ts +635 -0
  78. package/src/compiler/server-only.ts +365 -0
  79. package/src/compiler/shared.ts +397 -0
  80. package/src/compiler/signal-reads.ts +246 -0
  81. package/src/compiler/slots.ts +227 -0
  82. package/src/compiler/spread-handlers.ts +295 -0
  83. package/src/compiler/ssr-helpers.ts +555 -0
  84. package/src/compiler/ssr-island.ts +90 -0
  85. package/src/compiler/ssr-prunelle-tags.ts +69 -0
  86. package/src/compiler/ssr.ts +525 -0
  87. package/src/context.ts +199 -0
  88. package/src/dev/child.ts +30 -0
  89. package/src/dev/error-log.ts +177 -0
  90. package/src/dev/host-check.ts +32 -0
  91. package/src/dev/index.ts +268 -0
  92. package/src/dev/modules.ts +68 -0
  93. package/src/dev/open-editor.ts +228 -0
  94. package/src/dev/protocol.ts +24 -0
  95. package/src/dev/queue.ts +79 -0
  96. package/src/dev/reload.ts +159 -0
  97. package/src/dev/supervisor.ts +212 -0
  98. package/src/dev/watchers.ts +276 -0
  99. package/src/dom/action.ts +187 -0
  100. package/src/dom/attrs.ts +84 -0
  101. package/src/dom/claim.ts +120 -0
  102. package/src/dom/extras.ts +579 -0
  103. package/src/dom/index.ts +329 -0
  104. package/src/dom/island.ts +318 -0
  105. package/src/dom/loop.ts +484 -0
  106. package/src/dom/revive.ts +36 -0
  107. package/src/eco/declaration.ts +328 -0
  108. package/src/eco/index.ts +69 -0
  109. package/src/index.ts +22 -0
  110. package/src/jsx-runtime.ts +566 -0
  111. package/src/plugins/config.ts +92 -0
  112. package/src/plugins/context.ts +109 -0
  113. package/src/plugins/index.ts +14 -0
  114. package/src/plugins/load.ts +90 -0
  115. package/src/plugins/order.ts +148 -0
  116. package/src/plugins/public.ts +15 -0
  117. package/src/plugins/requires.ts +47 -0
  118. package/src/plugins/services.ts +119 -0
  119. package/src/plugins/types.ts +278 -0
  120. package/src/reactivity/graph.ts +259 -0
  121. package/src/reactivity/index.ts +541 -0
  122. package/src/reactivity/selector.ts +78 -0
  123. package/src/reactivity/store.ts +252 -0
  124. package/src/server/action-flash.ts +158 -0
  125. package/src/server/action-protect.ts +199 -0
  126. package/src/server/action-registry.ts +78 -0
  127. package/src/server/action.ts +511 -0
  128. package/src/server/app-entry.ts +23 -0
  129. package/src/server/app-secret.ts +63 -0
  130. package/src/server/assets.ts +168 -0
  131. package/src/server/compress.ts +646 -0
  132. package/src/server/consent.ts +290 -0
  133. package/src/server/cookies.ts +153 -0
  134. package/src/server/document.ts +286 -0
  135. package/src/server/env.ts +47 -0
  136. package/src/server/errors.ts +396 -0
  137. package/src/server/form-schema.ts +337 -0
  138. package/src/server/health.ts +275 -0
  139. package/src/server/http.ts +588 -0
  140. package/src/server/index.ts +615 -0
  141. package/src/server/lifecycle.ts +75 -0
  142. package/src/server/loader.ts +131 -0
  143. package/src/server/page.ts +122 -0
  144. package/src/server/param-matchers.ts +112 -0
  145. package/src/server/plugin-host.ts +267 -0
  146. package/src/server/prerendered.ts +71 -0
  147. package/src/server/public.ts +20 -0
  148. package/src/server/rate-limit.ts +199 -0
  149. package/src/server/region.ts +96 -0
  150. package/src/server/request-body.ts +27 -0
  151. package/src/server/request-path.ts +73 -0
  152. package/src/server/request-scope.ts +22 -0
  153. package/src/server/route-cache.ts +541 -0
  154. package/src/server/route-table.ts +424 -0
  155. package/src/server/router.ts +261 -0
  156. package/src/server/routing.ts +388 -0
  157. package/src/server/sanitize-html.ts +309 -0
  158. package/src/server/security.ts +550 -0
  159. package/src/server/serve-handlers.ts +93 -0
  160. package/src/server/served-file.ts +128 -0
  161. package/src/server/standard-schema.ts +104 -0
  162. package/src/server/start.ts +143 -0
  163. package/src/server/static-dir.ts +246 -0
  164. package/src/server/stream.ts +233 -0
  165. package/src/ssr/consent-banner.ts +58 -0
  166. package/src/ssr/context.ts +399 -0
  167. package/src/ssr/index.ts +624 -0
  168. package/src/ssr/navigation.ts +96 -0
  169. package/src/ssr/region.ts +192 -0
  170. package/src/style.ts +96 -0
  171. package/src/test/browser.ts +201 -0
  172. package/src/test/index.ts +262 -0
  173. package/src/ts-plugin/diagnostics.ts +505 -0
  174. package/src/ts-plugin/fixes.ts +364 -0
  175. package/src/ts-plugin/index.ts +194 -0
  176. package/src/unrenderable.ts +35 -0
  177. package/templates/_shared/AGENTS.md +10 -0
  178. package/templates/_shared/CLAUDE.md +1 -0
  179. package/templates/_shared/gitignore +8 -0
  180. package/templates/_shared/mcp.json +11 -0
  181. package/templates/_shared/public/robots.txt +2 -0
  182. package/templates/_shared/src/routes/legal.tsx +22 -0
  183. package/templates/_shared/tsconfig.json +25 -0
  184. package/templates/app/.env.example +8 -0
  185. package/templates/app/package.json +22 -0
  186. package/templates/app/prunelle.config.ts +13 -0
  187. package/templates/app/src/auth.ts +12 -0
  188. package/templates/app/src/mail.ts +4 -0
  189. package/templates/app/src/routes/_layout.tsx +40 -0
  190. package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
  191. package/templates/app/src/routes/dashboard/index.tsx +47 -0
  192. package/templates/app/src/routes/index.tsx +15 -0
  193. package/templates/app/src/routes/login.tsx +53 -0
  194. package/templates/app/src/routes/privacy.tsx +25 -0
  195. package/templates/app/src/styles/app.css +14 -0
  196. package/templates/app/tests/app.test.ts +73 -0
  197. package/templates/blog/content/posts/welcome.md +9 -0
  198. package/templates/blog/package.json +22 -0
  199. package/templates/blog/prunelle.config.ts +23 -0
  200. package/templates/blog/src/posts.ts +26 -0
  201. package/templates/blog/src/routes/_layout.tsx +25 -0
  202. package/templates/blog/src/routes/blog/[slug].tsx +31 -0
  203. package/templates/blog/src/routes/index.tsx +33 -0
  204. package/templates/blog/src/styles/app.css +15 -0
  205. package/templates/fullstack/package.json +19 -0
  206. package/templates/fullstack/prunelle.config.ts +6 -0
  207. package/templates/fullstack/src/actions/greet.ts +19 -0
  208. package/templates/fullstack/src/components/Counter.tsx +10 -0
  209. package/templates/fullstack/src/components/GreetForm.tsx +28 -0
  210. package/templates/fullstack/src/routes/_layout.tsx +18 -0
  211. package/templates/fullstack/src/routes/api/health.ts +5 -0
  212. package/templates/fullstack/src/routes/index.tsx +13 -0
  213. package/templates/fullstack/src/styles/app.css +39 -0
  214. package/templates/fullstack/tests/app.test.ts +37 -0
  215. package/templates/minimal/package.json +19 -0
  216. package/templates/minimal/prunelle.config.ts +6 -0
  217. package/templates/minimal/src/components/Counter.tsx +10 -0
  218. package/templates/minimal/src/routes/_layout.tsx +18 -0
  219. package/templates/minimal/src/routes/index.tsx +11 -0
  220. package/templates/minimal/src/styles/app.css +32 -0
  221. package/ts-plugin.cjs +4277 -0
  222. package/README.md +0 -3
@@ -0,0 +1,364 @@
1
+ // Diagnostic codes and mechanical quick fixes for the Prunelle TypeScript language-service plugin.
2
+
3
+ import type { JSXAttribute, Node } from 'oxc-parser'
4
+ import type ts from 'typescript'
5
+ import { unwrapParens, unwrapTsExpr } from '../compiler/shared'
6
+
7
+ export const PRUNELLE_CODE = {
8
+ ERROR: 98001,
9
+ WARNING: 98002,
10
+ BARE_SIGNAL: 98101,
11
+ LOWERCASE_EVENT: 98102,
12
+ RENAMED_EVENT: 98103,
13
+ NAMESPACED_EVENT: 98104,
14
+ CLIENT_DIRECTIVE: 98105,
15
+ SET_HTML: 98106,
16
+ STRIP_NAMESPACE: 98107,
17
+ CAMEL_ARIA: 98108,
18
+ CAMEL_SVG: 98109,
19
+ REACT_DEFAULT: 98110,
20
+ BOOLEAN_FALSE_STRING: 98111,
21
+ DANGEROUSLY_SET_HTML: 98112,
22
+ INNER_HTML_OBJECT: 98113,
23
+ HANDLER_MUTATION: 98114,
24
+ DIRECTIVE: 98115,
25
+ NON_BUBBLING_FOCUS: 98116,
26
+ TEXT_INPUT_ONCHANGE: 98117,
27
+ KAY_IMPORT: 98118,
28
+ } as const
29
+
30
+ export const PRUNELLE_FIXABLE_CODES: readonly number[] = [
31
+ PRUNELLE_CODE.BARE_SIGNAL,
32
+ PRUNELLE_CODE.LOWERCASE_EVENT,
33
+ PRUNELLE_CODE.RENAMED_EVENT,
34
+ PRUNELLE_CODE.NAMESPACED_EVENT,
35
+ PRUNELLE_CODE.CLIENT_DIRECTIVE,
36
+ PRUNELLE_CODE.SET_HTML,
37
+ PRUNELLE_CODE.STRIP_NAMESPACE,
38
+ PRUNELLE_CODE.CAMEL_ARIA,
39
+ PRUNELLE_CODE.CAMEL_SVG,
40
+ PRUNELLE_CODE.REACT_DEFAULT,
41
+ PRUNELLE_CODE.BOOLEAN_FALSE_STRING,
42
+ PRUNELLE_CODE.DANGEROUSLY_SET_HTML,
43
+ PRUNELLE_CODE.INNER_HTML_OBJECT,
44
+ PRUNELLE_CODE.HANDLER_MUTATION,
45
+ PRUNELLE_CODE.DIRECTIVE,
46
+ PRUNELLE_CODE.NON_BUBBLING_FOCUS,
47
+ PRUNELLE_CODE.TEXT_INPUT_ONCHANGE,
48
+ PRUNELLE_CODE.KAY_IMPORT,
49
+ ]
50
+
51
+ export interface PrunelleFixDescriptor {
52
+ fixName: string
53
+ description: string
54
+ span: { start: number, length: number }
55
+ newText: string
56
+ }
57
+
58
+ export interface ClassifiedFix {
59
+ code: number
60
+ /** Highlight span for the diagnostic itself (may differ from edit span, e.g. handler mutation). */
61
+ diagSpan: { start: number, length: number }
62
+ fix: PrunelleFixDescriptor
63
+ }
64
+
65
+ const CLIENT_HYDRATE_MAP: Record<string, string> = {
66
+ load: 'load',
67
+ visible: 'visible',
68
+ idle: 'idle',
69
+ only: 'client',
70
+ }
71
+
72
+ const WRITE_PROP_RE = /^write ([a-zA-Z0-9_:-]+)=\{\.\.\.\}/
73
+ const WRITE_IMPORT_RE = /^write '([^']+)'/
74
+ const BUBBLING_FOCUS_RE = /focus does not bubble, write (onFocus(?:In|Out))=\{\.\.\.\}/
75
+
76
+ function findNode<T extends Node['type']>(nodes: readonly Node[], type: T): Extract<Node, { type: T }> | undefined {
77
+ for (const node of nodes) {
78
+ if (node.type === type)
79
+ return node as Extract<Node, { type: T }>
80
+ }
81
+ return undefined
82
+ }
83
+
84
+ function spanOf(start: number, end: number): { start: number, length: number } {
85
+ return { start, length: Math.max(1, end - start) }
86
+ }
87
+
88
+ function attrRenameFix(
89
+ code: number,
90
+ attr: JSXAttribute,
91
+ fromName: string,
92
+ toName: string,
93
+ fixName: string,
94
+ ): ClassifiedFix {
95
+ const span = spanOf(attr.name.start, attr.name.end)
96
+ return {
97
+ code,
98
+ diagSpan: span,
99
+ fix: { fixName, description: `Change '${fromName}' to '${toName}'`, span, newText: toName },
100
+ }
101
+ }
102
+
103
+ function extractHtmlObjectExpr(value: JSXAttribute['value'], source: string): string | undefined {
104
+ if (value?.type !== 'JSXExpressionContainer' || value.expression.type === 'JSXEmptyExpression')
105
+ return undefined
106
+ const obj = unwrapParens(value.expression)
107
+ if (obj.type !== 'ObjectExpression')
108
+ return undefined
109
+ const prop = obj.properties.find(p =>
110
+ p.type === 'Property'
111
+ && ((p.key.type === 'Identifier' && p.key.name === '__html')
112
+ || (p.key.type === 'Literal' && p.key.value === '__html')),
113
+ )
114
+ return prop?.type === 'Property' ? source.slice(prop.value.start, prop.value.end) : undefined
115
+ }
116
+
117
+ function staticLiteralString(value: JSXAttribute['value']): string | undefined {
118
+ if (value?.type === 'Literal' && typeof value.value === 'string')
119
+ return value.value
120
+ if (value?.type === 'JSXExpressionContainer' && value.expression.type !== 'JSXEmptyExpression') {
121
+ const inner = unwrapTsExpr(value.expression)
122
+ if (inner.type === 'Literal' && typeof inner.value === 'string')
123
+ return inner.value
124
+ }
125
+ return undefined
126
+ }
127
+
128
+ function directiveDeleteSpan(code: string, start: number, end: number): { start: number, length: number } {
129
+ let delStart = start
130
+ let lineStart = start
131
+ while (lineStart > 0 && code.charCodeAt(lineStart - 1) !== 10 && code.charCodeAt(lineStart - 1) !== 13)
132
+ lineStart--
133
+ if (/^[ \t]*$/.test(code.slice(lineStart, start)))
134
+ delStart = lineStart
135
+
136
+ let delEnd = end
137
+ while (delEnd < code.length && (code.charCodeAt(delEnd) === 32 || code.charCodeAt(delEnd) === 9))
138
+ delEnd++
139
+ if (code.charCodeAt(delEnd) === 13 && code.charCodeAt(delEnd + 1) === 10)
140
+ delEnd += 2
141
+ else if (code.charCodeAt(delEnd) === 10)
142
+ delEnd += 1
143
+ return { start: delStart, length: delEnd - delStart }
144
+ }
145
+
146
+ function classifyNamespacedAttrFix(attr: JSXAttribute, what: string, fixText: string): ClassifiedFix | undefined {
147
+ if (attr.name.type !== 'JSXNamespacedName')
148
+ return undefined
149
+ const ns = attr.name.namespace.name
150
+ const local = attr.name.name.name
151
+ if (ns === 'on') {
152
+ const match = WRITE_PROP_RE.exec(fixText)
153
+ return match !== null ? attrRenameFix(PRUNELLE_CODE.NAMESPACED_EVENT, attr, what, match[1]!, 'prunelle-namespaced-event') : undefined
154
+ }
155
+ if (ns === 'client') {
156
+ let mode = CLIENT_HYDRATE_MAP[local]
157
+ if (mode === undefined && local === 'media') {
158
+ const query = staticLiteralString(attr.value)
159
+ if (query !== undefined && query.trim() !== '')
160
+ mode = `media(${query})`
161
+ }
162
+ if (mode === undefined)
163
+ return undefined
164
+ const span = spanOf(attr.start, attr.end)
165
+ const newText = `$hydrate="${mode}"`
166
+ return {
167
+ code: PRUNELLE_CODE.CLIENT_DIRECTIVE,
168
+ diagSpan: span,
169
+ fix: { fixName: 'prunelle-client-directive', description: `Replace '${what}' with '${newText}'`, span, newText },
170
+ }
171
+ }
172
+ if (what === 'set:html')
173
+ return attrRenameFix(PRUNELLE_CODE.SET_HTML, attr, 'set:html', 'innerHTML', 'prunelle-set-html')
174
+ if (ns === 'prop' || ns === 'attr' || ns === 'bool')
175
+ return attrRenameFix(PRUNELLE_CODE.STRIP_NAMESPACE, attr, what, local, 'prunelle-strip-namespace')
176
+ return undefined
177
+ }
178
+
179
+ function classifyInnerHtmlFix(attr: JSXAttribute, what: string, code: string): ClassifiedFix | undefined {
180
+ const isDangerous = what === 'dangerouslySetInnerHTML'
181
+ if (!isDangerous && what !== 'innerHTML={{ __html }}')
182
+ return undefined
183
+ const expr = extractHtmlObjectExpr(attr.value, code)
184
+ if (expr === undefined)
185
+ return undefined
186
+ const span = spanOf(attr.start, attr.end)
187
+ const newText = `innerHTML={${expr}}`
188
+ return {
189
+ code: isDangerous ? PRUNELLE_CODE.DANGEROUSLY_SET_HTML : PRUNELLE_CODE.INNER_HTML_OBJECT,
190
+ diagSpan: span,
191
+ fix: {
192
+ fixName: isDangerous ? 'prunelle-dangerously-set-html' : 'prunelle-inner-html-object',
193
+ description: `Replace with '${newText}'`,
194
+ span,
195
+ newText,
196
+ },
197
+ }
198
+ }
199
+
200
+ function classifyJsxAttrMistake(attr: JSXAttribute, what: string, fixText: string, code: string): ClassifiedFix | undefined {
201
+ if (attr.name.type === 'JSXNamespacedName')
202
+ return classifyNamespacedAttrFix(attr, what, fixText)
203
+ const attrName = attr.name.name
204
+ const htmlFix = classifyInnerHtmlFix(attr, what, code)
205
+ if (htmlFix !== undefined)
206
+ return htmlFix
207
+ if (fixText.includes('prunelle binds camelCase event props only')) {
208
+ const match = WRITE_PROP_RE.exec(fixText)
209
+ return match !== null ? attrRenameFix(PRUNELLE_CODE.LOWERCASE_EVENT, attr, attrName, match[1]!, 'prunelle-lowercase-event') : undefined
210
+ }
211
+ if (fixText.includes('ARIA attributes use kebab-case')) {
212
+ const match = WRITE_PROP_RE.exec(fixText)
213
+ return match !== null ? attrRenameFix(PRUNELLE_CODE.CAMEL_ARIA, attr, attrName, match[1]!, 'prunelle-kebab-aria') : undefined
214
+ }
215
+ if (fixText.includes('SVG attributes are case-sensitive') || what === 'xlinkHref') {
216
+ const target = what === 'xlinkHref' ? 'xlink:href' : WRITE_PROP_RE.exec(fixText)?.[1]
217
+ return target !== undefined ? attrRenameFix(PRUNELLE_CODE.CAMEL_SVG, attr, attrName, target, 'prunelle-kebab-svg') : undefined
218
+ }
219
+ if (what === 'defaultValue' || what === 'defaultChecked') {
220
+ const target = what === 'defaultValue' ? 'value' : 'checked'
221
+ return attrRenameFix(PRUNELLE_CODE.REACT_DEFAULT, attr, attrName, target, 'prunelle-react-default')
222
+ }
223
+ if (fixText.includes('any string turns it on')) {
224
+ const span = spanOf(attr.start, attr.end)
225
+ const newText = `${attrName}={false}`
226
+ return {
227
+ code: PRUNELLE_CODE.BOOLEAN_FALSE_STRING,
228
+ diagSpan: span,
229
+ fix: { fixName: 'prunelle-boolean-false', description: `Change '${what}' to '${newText}'`, span, newText },
230
+ }
231
+ }
232
+ if (what.includes(' runs ') && what.endsWith(' at render') && attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
233
+ const inner = unwrapParens(attr.value.expression)
234
+ const exprSrc = code.slice(inner.start, inner.end)
235
+ const newText = `() => ${exprSrc}`
236
+ return {
237
+ code: PRUNELLE_CODE.HANDLER_MUTATION,
238
+ diagSpan: spanOf(attr.start, attr.end),
239
+ fix: {
240
+ fixName: 'prunelle-wrap-handler',
241
+ description: `Wrap handler in '${newText}'`,
242
+ span: spanOf(attr.value.expression.start, attr.value.expression.end),
243
+ newText,
244
+ },
245
+ }
246
+ }
247
+ const focusMatch = BUBBLING_FOCUS_RE.exec(fixText)
248
+ if (focusMatch !== null)
249
+ return attrRenameFix(PRUNELLE_CODE.NON_BUBBLING_FOCUS, attr, attrName, focusMatch[1]!, 'prunelle-bubbling-focus')
250
+ if (what === attrName && attrName.startsWith('on')) {
251
+ const match = WRITE_PROP_RE.exec(fixText)
252
+ if (match !== null && match[1]!.startsWith('on'))
253
+ return attrRenameFix(PRUNELLE_CODE.RENAMED_EVENT, attr, attrName, match[1]!, 'prunelle-renamed-event')
254
+ }
255
+ return undefined
256
+ }
257
+
258
+ /** Splits a standard `prunelle compiler: <what> in <file>: <fix>.` message. */
259
+ function parseMistakeParts(message: string, fileName: string): { what: string, fixText: string } | undefined {
260
+ const prefix = 'prunelle compiler: '
261
+ if (!message.startsWith(prefix))
262
+ return undefined
263
+ const marker = ` in ${fileName}: `
264
+ const idx = message.indexOf(marker, prefix.length)
265
+ if (idx === -1)
266
+ return undefined
267
+ const what = message.slice(prefix.length, idx)
268
+ const rawFix = message.slice(idx + marker.length)
269
+ const fixText = rawFix.endsWith('.') ? rawFix.slice(0, -1) : rawFix
270
+ return { what, fixText }
271
+ }
272
+
273
+ /** Classifies a compiler mistake and builds a mechanical quick fix when one exists. */
274
+ export function classifyMistakeFix(
275
+ message: string,
276
+ fileName: string,
277
+ nodesAtStart: readonly Node[],
278
+ code: string,
279
+ ): ClassifiedFix | undefined {
280
+ const parts = parseMistakeParts(message, fileName)
281
+ if (parts === undefined)
282
+ return undefined
283
+ const { what, fixText } = parts
284
+
285
+ if (what.endsWith(' without .value')) {
286
+ const name = what.slice(0, -' without .value'.length)
287
+ const node = name.includes('.') ? findNode(nodesAtStart, 'MemberExpression') : findNode(nodesAtStart, 'Identifier')
288
+ if (node === undefined)
289
+ return undefined
290
+ const span = spanOf(node.start, node.end)
291
+ const exprText = code.slice(node.start, node.end)
292
+ return {
293
+ code: PRUNELLE_CODE.BARE_SIGNAL,
294
+ diagSpan: span,
295
+ fix: { fixName: 'prunelle-add-signal-value', description: `Add '.value' to '${name}'`, span, newText: `${exprText}.value` },
296
+ }
297
+ }
298
+
299
+ if (what === "'use client'" || what === "'use server'") {
300
+ const stmt = findNode(nodesAtStart, 'ExpressionStatement')
301
+ if (stmt === undefined)
302
+ return undefined
303
+ return {
304
+ code: PRUNELLE_CODE.DIRECTIVE,
305
+ diagSpan: spanOf(stmt.start, stmt.end),
306
+ fix: {
307
+ fixName: 'prunelle-remove-directive',
308
+ description: `Remove ${what} directive`,
309
+ span: directiveDeleteSpan(code, stmt.start, stmt.end),
310
+ newText: '',
311
+ },
312
+ }
313
+ }
314
+
315
+ if (what.startsWith("import from '@kayjs/")) {
316
+ const lit = findNode(nodesAtStart, 'Literal')
317
+ const match = WRITE_IMPORT_RE.exec(fixText)
318
+ if (lit === undefined || match === null)
319
+ return undefined
320
+ const quote = code[lit.start] === '"' ? '"' : "'"
321
+ const replacement = match[1]!
322
+ const span = spanOf(lit.start, lit.end)
323
+ return {
324
+ code: PRUNELLE_CODE.KAY_IMPORT,
325
+ diagSpan: span,
326
+ fix: {
327
+ fixName: 'prunelle-rewrite-kay-import',
328
+ description: `Replace import with '${replacement}'`,
329
+ span,
330
+ newText: `${quote}${replacement}${quote}`,
331
+ },
332
+ }
333
+ }
334
+
335
+ const attr = findNode(nodesAtStart, 'JSXAttribute')
336
+ if (attr !== undefined)
337
+ return classifyJsxAttrMistake(attr, what, fixText, code)
338
+ return undefined
339
+ }
340
+
341
+ /** Classifies a compiler warning and builds a mechanical quick fix when one exists. */
342
+ export function classifyWarningFix(message: string, nodesAtStart: readonly Node[]): ClassifiedFix | undefined {
343
+ if (message.includes('fires when the field loses focus, not per keystroke; write onInput={...}')) {
344
+ const attr = findNode(nodesAtStart, 'JSXAttribute')
345
+ if (attr !== undefined)
346
+ return attrRenameFix(PRUNELLE_CODE.TEXT_INPUT_ONCHANGE, attr, 'onChange', 'onInput', 'prunelle-text-input-oninput')
347
+ }
348
+ return undefined
349
+ }
350
+
351
+ /** Converts a Prunelle quick fix descriptor into a TypeScript `CodeFixAction`. */
352
+ export function toCodeFixAction(fileName: string, fix: PrunelleFixDescriptor): ts.CodeFixAction {
353
+ return {
354
+ fixName: fix.fixName,
355
+ description: fix.description,
356
+ changes: [{
357
+ fileName,
358
+ textChanges: [{
359
+ span: { start: fix.span.start, length: fix.span.length },
360
+ newText: fix.newText,
361
+ }],
362
+ }],
363
+ }
364
+ }
@@ -0,0 +1,194 @@
1
+ // TypeScript Language Service plugin surfacing Prunelle compiler errors, compliance warnings, and quick fixes in editors.
2
+
3
+ import type ts from 'typescript'
4
+ import type { ComplianceConfig } from '../compiler/compliance'
5
+ import type { PrunelleDiagnosticItem, PrunellePluginOptions } from './diagnostics'
6
+ import { collectPrunelleDiagnostics, isCheckableFile, PRUNELLE_DIAG_SOURCE, toTsDiagnostic } from './diagnostics'
7
+ import { PRUNELLE_CODE, PRUNELLE_FIXABLE_CODES, toCodeFixAction } from './fixes'
8
+
9
+ const MAX_CACHE_ENTRIES = 200
10
+
11
+ interface CachedFileDiagnostics {
12
+ text: string
13
+ projectVersion: string
14
+ items: PrunelleDiagnosticItem[]
15
+ }
16
+
17
+ function readPluginConfig(raw: unknown): Pick<PrunellePluginOptions, 'compliance' | 'site'> {
18
+ if (raw === null || typeof raw !== 'object')
19
+ return {}
20
+ const rec = raw as Record<string, unknown>
21
+ const site = typeof rec.site === 'string' ? rec.site : undefined
22
+ const compliance = rec.compliance !== null && typeof rec.compliance === 'object'
23
+ ? (rec.compliance as ComplianceConfig)
24
+ : undefined
25
+ return { site, compliance }
26
+ }
27
+
28
+ // Advertises Prunelle's custom fixable diagnostic codes to tsserver/VS Code when TypeScript's supported-codes array is extensible.
29
+ function registerSupportedCodeFixes(tsLib: typeof ts): void {
30
+ if (typeof tsLib.getSupportedCodeFixes !== 'function')
31
+ return
32
+ try {
33
+ const supported = tsLib.getSupportedCodeFixes() as string[]
34
+ if (!Array.isArray(supported) || Object.isFrozen(supported))
35
+ return
36
+ const existing = new Set(supported)
37
+ for (const code of PRUNELLE_FIXABLE_CODES) {
38
+ const str = String(code)
39
+ if (!existing.has(str))
40
+ supported.push(str)
41
+ }
42
+ }
43
+ catch {
44
+ // Some TypeScript builds freeze the supported-codes array; editors still invoke getCodeFixesAtPosition directly.
45
+ return
46
+ }
47
+ }
48
+
49
+ function readFileSource(
50
+ prior: ts.LanguageService,
51
+ host: ts.LanguageServiceHost,
52
+ fileName: string,
53
+ ): { sourceFile: ts.SourceFile | undefined, text: string | undefined } {
54
+ const sourceFile = prior.getProgram()?.getSourceFile(fileName)
55
+ if (sourceFile !== undefined)
56
+ return { sourceFile, text: sourceFile.text }
57
+ const snapshot = host.getScriptSnapshot(fileName)
58
+ if (snapshot !== undefined)
59
+ return { sourceFile: undefined, text: snapshot.getText(0, snapshot.getLength()) }
60
+ return { sourceFile: undefined, text: undefined }
61
+ }
62
+
63
+ /** Direct helper for retrieving TypeScript `ts.Diagnostic`s for a single file. */
64
+ export function getPrunelleDiagnostics(
65
+ tsLib: typeof ts,
66
+ fileName: string,
67
+ code: string,
68
+ options: PrunellePluginOptions = {},
69
+ sourceFile?: ts.SourceFile,
70
+ ): ts.Diagnostic[] {
71
+ return collectPrunelleDiagnostics(fileName, code, options).map(item => toTsDiagnostic(tsLib, item, sourceFile))
72
+ }
73
+
74
+ /** Direct helper for retrieving TypeScript `ts.CodeFixAction`s overlapping `[start, end]`. */
75
+ export function getPrunelleCodeFixes(
76
+ fileName: string,
77
+ code: string,
78
+ start: number,
79
+ end: number,
80
+ errorCodes: readonly number[],
81
+ options: PrunellePluginOptions = {},
82
+ ): ts.CodeFixAction[] {
83
+ const items = collectPrunelleDiagnostics(fileName, code, options)
84
+ return selectCodeFixes(fileName, items, start, end, errorCodes)
85
+ }
86
+
87
+ function selectCodeFixes(
88
+ fileName: string,
89
+ items: readonly PrunelleDiagnosticItem[],
90
+ start: number,
91
+ end: number,
92
+ errorCodes: readonly number[],
93
+ ): ts.CodeFixAction[] {
94
+ const out: ts.CodeFixAction[] = []
95
+ for (const item of items) {
96
+ if (item.fix === undefined)
97
+ continue
98
+ if (errorCodes.length > 0 && !errorCodes.includes(item.code))
99
+ continue
100
+ const itemEnd = item.start + item.length
101
+ if (item.start <= end && start <= itemEnd)
102
+ out.push(toCodeFixAction(fileName, item.fix))
103
+ }
104
+ return out
105
+ }
106
+
107
+ /** Creates the wrapped `ts.LanguageService` for a TypeScript plugin instance. */
108
+ export function createPrunellePlugin(tsLib: typeof ts, info: ts.server.PluginCreateInfo): ts.LanguageService {
109
+ const prior = info.languageService
110
+ const log = (msg: string): void => {
111
+ info.project?.projectService?.logger?.info(`[prunelle/ts-plugin] ${msg}`)
112
+ }
113
+
114
+ registerSupportedCodeFixes(tsLib)
115
+
116
+ const cache = new Map<string, CachedFileDiagnostics>()
117
+ const pluginCfg = readPluginConfig(info.config)
118
+ const readFile = (path: string): string | undefined => readFileSource(prior, info.languageServiceHost, path).text
119
+ const getOptions = (): PrunellePluginOptions => ({
120
+ projectRoot: typeof info.project?.getCurrentDirectory === 'function' ? info.project.getCurrentDirectory() : undefined,
121
+ compliance: pluginCfg.compliance,
122
+ site: pluginCfg.site,
123
+ readFile,
124
+ })
125
+
126
+ const getItems = (fileName: string): { sourceFile: ts.SourceFile | undefined, items: PrunelleDiagnosticItem[] } => {
127
+ if (!isCheckableFile(fileName))
128
+ return { sourceFile: undefined, items: [] }
129
+ const { sourceFile, text } = readFileSource(prior, info.languageServiceHost, fileName)
130
+ if (text === undefined)
131
+ return { sourceFile, items: [] }
132
+ const projectVersion = typeof info.languageServiceHost.getProjectVersion === 'function'
133
+ ? info.languageServiceHost.getProjectVersion()
134
+ : ''
135
+ const cached = cache.get(fileName)
136
+ if (cached !== undefined && cached.text === text && cached.projectVersion === projectVersion)
137
+ return { sourceFile, items: cached.items }
138
+ try {
139
+ const items = collectPrunelleDiagnostics(fileName, text, getOptions())
140
+ if (cache.size >= MAX_CACHE_ENTRIES) {
141
+ const oldest = cache.keys().next().value
142
+ if (oldest !== undefined)
143
+ cache.delete(oldest)
144
+ }
145
+ cache.set(fileName, { text, projectVersion, items })
146
+ return { sourceFile, items }
147
+ }
148
+ catch (err) {
149
+ log(`analysis failed for ${fileName}: ${err instanceof Error ? err.message : String(err)}`)
150
+ return { sourceFile, items: [] }
151
+ }
152
+ }
153
+
154
+ const proxy = Object.create(null) as ts.LanguageService
155
+ for (const key of Object.keys(prior) as (keyof ts.LanguageService)[]) {
156
+ const member = prior[key]
157
+ if (typeof member === 'function') {
158
+ ;(proxy as unknown as Record<string, unknown>)[key] = (...args: unknown[]) =>
159
+ (member as (...a: unknown[]) => unknown).apply(prior, args)
160
+ }
161
+ }
162
+
163
+ proxy.getSemanticDiagnostics = (fileName) => {
164
+ const base = prior.getSemanticDiagnostics(fileName)
165
+ const { sourceFile, items } = getItems(fileName)
166
+ if (items.length === 0)
167
+ return base
168
+ return [...base, ...items.map(item => toTsDiagnostic(tsLib, item, sourceFile))]
169
+ }
170
+
171
+ proxy.getCodeFixesAtPosition = (fileName, start, end, errorCodes, formatOptions, preferences) => {
172
+ const base = prior.getCodeFixesAtPosition(fileName, start, end, errorCodes, formatOptions, preferences)
173
+ const { items } = getItems(fileName)
174
+ if (items.length === 0)
175
+ return base
176
+ const prunelleFixes = selectCodeFixes(fileName, items, start, end, errorCodes)
177
+ return prunelleFixes.length === 0 ? base : [...base, ...prunelleFixes]
178
+ }
179
+
180
+ return proxy
181
+ }
182
+
183
+ function init(modules: { typescript: typeof ts }): ts.server.PluginModule {
184
+ const tsLib = modules.typescript
185
+ return {
186
+ create(info: ts.server.PluginCreateInfo): ts.LanguageService {
187
+ return createPrunellePlugin(tsLib, info)
188
+ },
189
+ }
190
+ }
191
+
192
+ export default init
193
+ export type { PrunelleDiagnosticItem, PrunellePluginOptions }
194
+ export { collectPrunelleDiagnostics, PRUNELLE_CODE, PRUNELLE_DIAG_SOURCE, PRUNELLE_FIXABLE_CODES }
@@ -0,0 +1,35 @@
1
+ // Values whose String() is never what the author meant, shared by the SSR and DOM renderers so both refuse them alike.
2
+
3
+ // A value with its own toString, such as a server action printing its URL, renders as that string on purpose.
4
+ function hasOwnToString(value: object): boolean {
5
+ const { toString } = value
6
+ return typeof toString === 'function' && toString !== Function.prototype.toString && toString !== Object.prototype.toString && toString !== Array.prototype.toString
7
+ }
8
+
9
+ function describe(value: unknown, asClass: boolean): [string, string] | undefined {
10
+ if (typeof value === 'function')
11
+ return hasOwnToString(value) ? undefined : ['a function', 'call it, or pass it to an event prop']
12
+ if (typeof value !== 'object' || value === null)
13
+ return undefined
14
+ if (typeof (value as { then?: unknown }).then === 'function')
15
+ return ['a Promise', 'await it in an async component, or make that component the only child of <Suspense>']
16
+ if ('peek' in value && 'value' in value)
17
+ return ['a signal', 'read its .value']
18
+ if ('__html' in value)
19
+ return ['a { __html } object', 'pass the string to innerHTML, or wrap trusted HTML in raw()']
20
+ if (asClass && Array.isArray(value))
21
+ return ['an array', 'join the names into one string']
22
+ if (hasOwnToString(value))
23
+ return undefined
24
+ const proto = Object.getPrototypeOf(value)
25
+ if (proto === Object.prototype || proto === null)
26
+ return ['a plain object', 'render one of its fields']
27
+ return undefined
28
+ }
29
+
30
+ /** Throws when `value` would print as `[object Object]`, `[object Promise]` or a function's source; `place` is `text` or an attribute name. */
31
+ export function assertRenderable(value: unknown, place: string): void {
32
+ const found = describe(value, place === 'class')
33
+ if (found !== undefined)
34
+ throw new TypeError(`prunelle: cannot render ${found[0]} as ${place === 'text' ? 'text' : `the ${place} attribute`}; ${found[1]}.`)
35
+ }
@@ -0,0 +1,10 @@
1
+ # __APP_NAME__
2
+
3
+ A prunelle app. Read `node_modules/prunelle/llms.txt` before writing code: it holds prunelle's whole API for the version installed here, on one page. When using first-party plugins (`@prunellejs/*`), also read each installed plugin's `node_modules/@prunellejs/<plugin>/llms.txt` if present.
4
+
5
+ ## Workflow
6
+
7
+ - **Verify changes**: run `bun run check` (`prunelle check` + TypeScript), `prunelle render <url>` to inspect a rendered response without starting a dev server, `bun test` (in-process `testApp` from `prunelle/test` — no dev server needed), and `prunelle build --analyze` to inspect each route's JS weight and islands.
8
+ - **Discover, don't guess**: use `prunelle docs <words> [--json]` to search installed `llms.txt` files, `.mcp.json` (`prunelle mcp`) for MCP tooling, and plugin commands when installed — `prunelle icons-find <words>` for icon names, `prunelle i18n-check` for translation keys, and `prunelle mcp-footprint` for MCP tool token budgets.
9
+
10
+ @node_modules/prunelle/llms.txt
@@ -0,0 +1 @@
1
+ @AGENTS.md
@@ -0,0 +1,8 @@
1
+ node_modules/
2
+ dist/
3
+ .prunelle-cache/
4
+ .prunelle-dev/
5
+ .env
6
+ .env.*
7
+ !.env.example
8
+ data/
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "prunelle": {
4
+ "command": "bunx",
5
+ "args": [
6
+ "prunelle",
7
+ "mcp"
8
+ ]
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,2 @@
1
+ User-agent: *
2
+ Allow: /
@@ -0,0 +1,22 @@
1
+ import { Head } from 'prunelle'
2
+
3
+ // French law (LCEN art. 1-1) asks every site for these details; `prunelle check` warns until every placeholder below is replaced.
4
+ // A private individual publishing without a business may give only the host's details, the host keeping their identity.
5
+ export default function LegalNotice() {
6
+ return (
7
+ <section>
8
+ <Head>
9
+ <title>Legal Notice</title>
10
+ </Head>
11
+ <h1>Legal Notice</h1>
12
+ <h2>Publisher</h2>
13
+ <p>__APP_NAME__ is published by [to fill in: your full name, or your company's name, legal form and share capital].</p>
14
+ <p>Address: [to fill in: your home address, or your company's registered office]</p>
15
+ <p>Phone: [to fill in] / Email: [to fill in]</p>
16
+ <p>Registration: [to fill in: RCS or RNE number and VAT number, or remove this line if you have none]</p>
17
+ <p>Publication director: [to fill in: full name]</p>
18
+ <h2>Host</h2>
19
+ <p>[to fill in: the host's name, address and phone number]</p>
20
+ </section>
21
+ )
22
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "jsx": "react-jsx",
7
+ "jsxImportSource": "prunelle",
8
+ "strict": true,
9
+ "noEmit": true,
10
+ "skipLibCheck": true,
11
+ "plugins": [
12
+ {
13
+ "name": "prunelle/ts-plugin"
14
+ }
15
+ ],
16
+ "types": [
17
+ "bun"
18
+ ]
19
+ },
20
+ "include": [
21
+ "src",
22
+ "tests",
23
+ "prunelle.config.ts"
24
+ ]
25
+ }