sceneview-mcp 4.0.16 → 4.1.1
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/README.md +246 -62
- package/dist/analyze-project.js +4 -2
- package/dist/artifact.js +38 -13
- package/dist/debug-issue.js +101 -19
- package/dist/discover.js +106 -0
- package/dist/extra-guides.js +3 -3
- package/dist/generate-scene.js +380 -61
- package/dist/generated/llms-txt.js +1 -1
- package/dist/generated/symbols.js +1040 -22
- package/dist/generated/version.js +12 -3
- package/dist/guides.js +10 -6
- package/dist/http.js +178 -0
- package/dist/index.js +34 -139
- package/dist/issues.js +1 -1
- package/dist/migrate-code.js +5 -3
- package/dist/platform-setup.js +33 -16
- package/dist/samples.js +31 -31
- package/dist/search-models.js +1 -1
- package/dist/server.js +197 -0
- package/dist/surfaces.js +32 -0
- package/dist/telemetry.js +14 -8
- package/dist/tools/definitions.js +176 -14
- package/dist/tools/handler.js +207 -66
- package/dist/tools/index.js +4 -4
- package/dist/tools/types.js +0 -4
- package/dist/validator.js +262 -161
- package/dist/widgets.js +915 -0
- package/package.json +16 -12
- package/dist/proxy.js +0 -176
- package/dist/tiers.js +0 -138
package/dist/validator.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { didYouMean, isKnownTopLevelFunction, isKnownTypeName, knownTypeNames, membersOfClass, rememberHelperNames, resolveImport, } from "./symbols.js";
|
|
2
2
|
function findLines(lines, pattern) {
|
|
3
|
-
return lines
|
|
4
|
-
.map((l, i) => (pattern.test(l) ? i + 1 : -1))
|
|
5
|
-
.filter((n) => n !== -1);
|
|
3
|
+
return lines.map((l, i) => (pattern.test(l) ? i + 1 : -1)).filter((n) => n !== -1);
|
|
6
4
|
}
|
|
7
5
|
// Symbols the snippet declares itself (`fun MyShowcaseScene(…)`, `class ShelfNode(…) :
|
|
8
6
|
// Node(engine)`) exist by definition — they are the caller's own wrappers, not calls into
|
|
@@ -33,12 +31,14 @@ const RULES = [
|
|
|
33
31
|
];
|
|
34
32
|
for (const [pat, name] of filamentCallPatterns) {
|
|
35
33
|
if (pat.test(code)) {
|
|
36
|
-
findLines(lines, pat).forEach((line) =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
findLines(lines, pat).forEach((line) => {
|
|
35
|
+
issues.push({
|
|
36
|
+
severity: "error",
|
|
37
|
+
rule: "threading/filament-off-main-thread",
|
|
38
|
+
message: `\`${name}\` detected alongside a background dispatcher. Filament JNI calls must run on the **main thread**. Use \`rememberModelInstance\` in composables, or wrap imperative code in \`withContext(Dispatchers.Main)\`.`,
|
|
39
|
+
line,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
return issues;
|
|
@@ -53,12 +53,14 @@ const RULES = [
|
|
|
53
53
|
if (!code.includes("ARScene") && !code.includes("AnchorNode"))
|
|
54
54
|
return issues;
|
|
55
55
|
if (/\.worldPosition\s*=/.test(code)) {
|
|
56
|
-
findLines(lines, /\.worldPosition\s*=/).forEach((line) =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
findLines(lines, /\.worldPosition\s*=/).forEach((line) => {
|
|
57
|
+
issues.push({
|
|
58
|
+
severity: "warning",
|
|
59
|
+
rule: "ar/node-not-anchor",
|
|
60
|
+
message: "Manually setting `worldPosition` inside an AR scene causes drift — ARCore remaps coordinates during tracking and plain nodes don't compensate. Use `AnchorNode(anchor = hitResult.createAnchor())` instead.",
|
|
61
|
+
line,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
62
64
|
}
|
|
63
65
|
return issues;
|
|
64
66
|
},
|
|
@@ -76,12 +78,14 @@ const RULES = [
|
|
|
76
78
|
// Flag ModelNode uses where the variable is passed without null-guard (no ?. !! or ?: )
|
|
77
79
|
const unsafeUse = new RegExp(`ModelNode\\s*\\([^)]*modelInstance\\s*=\\s*${varName}(?![?!])`);
|
|
78
80
|
if (unsafeUse.test(code)) {
|
|
79
|
-
findLines(lines, new RegExp(`modelInstance\\s*=\\s*${varName}(?![?!])`)).forEach((line) =>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
findLines(lines, new RegExp(`modelInstance\\s*=\\s*${varName}(?![?!])`)).forEach((line) => {
|
|
82
|
+
issues.push({
|
|
83
|
+
severity: "error",
|
|
84
|
+
rule: "composable/model-instance-null-check",
|
|
85
|
+
message: `\`${varName}\` from \`rememberModelInstance\` is \`null\` while the asset loads. Guard it: \`${varName}?.let { ModelNode(modelInstance = it, ...) }\`.`,
|
|
86
|
+
line,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
85
89
|
}
|
|
86
90
|
return issues;
|
|
87
91
|
},
|
|
@@ -94,12 +98,14 @@ const RULES = [
|
|
|
94
98
|
const issues = [];
|
|
95
99
|
// Matches: LightNode(...) { — trailing lambda, not apply = { inside parens
|
|
96
100
|
if (/LightNode\s*\([^)]*\)\s*\{/.test(code)) {
|
|
97
|
-
findLines(lines, /LightNode\s*\([^)]*\)\s*\{/).forEach((line) =>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
findLines(lines, /LightNode\s*\([^)]*\)\s*\{/).forEach((line) => {
|
|
102
|
+
issues.push({
|
|
103
|
+
severity: "error",
|
|
104
|
+
rule: "api/light-node-trailing-lambda",
|
|
105
|
+
message: "`LightNode`'s configuration block is a **named parameter** `apply`, not a trailing lambda. Write `LightNode(engine = engine, type = ..., apply = { intensity(100_000f) })`. Without `apply =` the block is silently ignored and your light has default (zero) settings.",
|
|
106
|
+
line,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
103
109
|
}
|
|
104
110
|
return issues;
|
|
105
111
|
},
|
|
@@ -110,12 +116,14 @@ const RULES = [
|
|
|
110
116
|
severity: "error",
|
|
111
117
|
check(code, lines) {
|
|
112
118
|
const issues = [];
|
|
113
|
-
findLines(lines, /Engine\.create\(/).forEach((line) =>
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
findLines(lines, /Engine\.create\(/).forEach((line) => {
|
|
120
|
+
issues.push({
|
|
121
|
+
severity: "error",
|
|
122
|
+
rule: "lifecycle/manual-engine-create",
|
|
123
|
+
message: "`Engine.create()` called directly. In composables use `rememberEngine()` — it ties the Engine to the composition lifecycle and destroys it automatically on disposal, preventing leaks and double-destroy SIGABRTs.",
|
|
124
|
+
line,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
119
127
|
return issues;
|
|
120
128
|
},
|
|
121
129
|
},
|
|
@@ -127,12 +135,14 @@ const RULES = [
|
|
|
127
135
|
const issues = [];
|
|
128
136
|
if (!code.includes("rememberEngine"))
|
|
129
137
|
return issues;
|
|
130
|
-
findLines(lines, /engine\.(safeD|d)estroy\(\)/).forEach((line) =>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
findLines(lines, /engine\.(safeD|d)estroy\(\)/).forEach((line) => {
|
|
139
|
+
issues.push({
|
|
140
|
+
severity: "warning",
|
|
141
|
+
rule: "lifecycle/manual-engine-destroy",
|
|
142
|
+
message: "`engine.destroy()` called manually alongside `rememberEngine()`. The engine is already destroyed on composition disposal — calling it again triggers a SIGABRT. Remove the manual call.",
|
|
143
|
+
line,
|
|
144
|
+
});
|
|
145
|
+
});
|
|
136
146
|
return issues;
|
|
137
147
|
},
|
|
138
148
|
},
|
|
@@ -145,12 +155,14 @@ const RULES = [
|
|
|
145
155
|
const texIdx = code.indexOf("safeDestroyTexture");
|
|
146
156
|
const matIdx = code.indexOf("destroyMaterialInstance");
|
|
147
157
|
if (texIdx !== -1 && matIdx !== -1 && texIdx < matIdx) {
|
|
148
|
-
findLines(lines, /safeDestroyTexture|engine\.destroyTexture/).forEach((line) =>
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
158
|
+
findLines(lines, /safeDestroyTexture|engine\.destroyTexture/).forEach((line) => {
|
|
159
|
+
issues.push({
|
|
160
|
+
severity: "error",
|
|
161
|
+
rule: "lifecycle/texture-destroy-order",
|
|
162
|
+
message: 'Texture destroyed **before** the MaterialInstance that references it → SIGABRT ("Invalid texture still bound to MaterialInstance"). Destroy the MaterialInstance first: `materialLoader.destroyMaterialInstance(instance)`, then `engine.safeDestroyTexture(texture)`.',
|
|
163
|
+
line,
|
|
164
|
+
});
|
|
165
|
+
});
|
|
154
166
|
}
|
|
155
167
|
return issues;
|
|
156
168
|
},
|
|
@@ -161,12 +173,14 @@ const RULES = [
|
|
|
161
173
|
severity: "warning",
|
|
162
174
|
check(code, lines) {
|
|
163
175
|
const issues = [];
|
|
164
|
-
findLines(lines, /modelLoader\.createModelInstance\(/).forEach((line) =>
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
176
|
+
findLines(lines, /modelLoader\.createModelInstance\(/).forEach((line) => {
|
|
177
|
+
issues.push({
|
|
178
|
+
severity: "warning",
|
|
179
|
+
rule: "composable/prefer-remember-model-instance",
|
|
180
|
+
message: "`modelLoader.createModelInstance()` blocks the main thread. In composables, use `rememberModelInstance(modelLoader, path)` — it loads asynchronously, returns `null` while loading, and recomposes when ready.",
|
|
181
|
+
line,
|
|
182
|
+
});
|
|
183
|
+
});
|
|
170
184
|
return issues;
|
|
171
185
|
},
|
|
172
186
|
},
|
|
@@ -176,12 +190,14 @@ const RULES = [
|
|
|
176
190
|
severity: "error",
|
|
177
191
|
check(code, lines) {
|
|
178
192
|
const issues = [];
|
|
179
|
-
findLines(lines, /AnchorNode\s*\(\s*\)/).forEach((line) =>
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
193
|
+
findLines(lines, /AnchorNode\s*\(\s*\)/).forEach((line) => {
|
|
194
|
+
issues.push({
|
|
195
|
+
severity: "error",
|
|
196
|
+
rule: "ar/anchor-node-missing-anchor",
|
|
197
|
+
message: "`AnchorNode()` requires an `anchor` from a hit result. Use `AnchorNode(anchor = hitResult.createAnchor())` inside `onTouchEvent` or `onSessionUpdated`.",
|
|
198
|
+
line,
|
|
199
|
+
});
|
|
200
|
+
});
|
|
185
201
|
return issues;
|
|
186
202
|
},
|
|
187
203
|
},
|
|
@@ -202,15 +218,32 @@ const RULES = [
|
|
|
202
218
|
[/\bScene\s*\{/, "`Scene { }` → renamed to `SceneView { }` in 4.0"],
|
|
203
219
|
[/\bARScene\s*\{/, "`ARScene { }` → renamed to `ARSceneView { }` in 4.0"],
|
|
204
220
|
[/\bArSceneView\s*\(/, "`ArSceneView(…)` → renamed to `ARSceneView(…)` in 3.0"],
|
|
205
|
-
[
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
[
|
|
221
|
+
[
|
|
222
|
+
/\bPlacementNode\b/,
|
|
223
|
+
"`PlacementNode` removed → use `AnchorNode` + `HitResultNode` in 3.0",
|
|
224
|
+
],
|
|
225
|
+
[
|
|
226
|
+
/\bTransformableNode\b/,
|
|
227
|
+
"`TransformableNode` removed → set `isEditable = true` on `ModelNode` in 3.0",
|
|
228
|
+
],
|
|
229
|
+
[
|
|
230
|
+
/\bViewRenderable\b/,
|
|
231
|
+
"`ViewRenderable` removed → use `ViewNode` with a `@Composable` content lambda in 3.0",
|
|
232
|
+
],
|
|
233
|
+
[
|
|
234
|
+
/\bmodelLoader\.loadModelAsync\b/,
|
|
235
|
+
"`loadModelAsync` removed → use `rememberModelInstance` in composables (3.0)",
|
|
236
|
+
],
|
|
237
|
+
[
|
|
238
|
+
/\bmodelLoader\.loadModel\b(?!Instance)/,
|
|
239
|
+
"`loadModel` → use `rememberModelInstance` or `loadModelInstanceAsync` (3.0)",
|
|
240
|
+
],
|
|
210
241
|
];
|
|
211
242
|
for (const [pat, msg] of renames) {
|
|
212
243
|
if (pat.test(code)) {
|
|
213
|
-
findLines(lines, pat).forEach((line) =>
|
|
244
|
+
findLines(lines, pat).forEach((line) => {
|
|
245
|
+
issues.push({ severity: "error", rule: "migration/old-api", message: msg, line });
|
|
246
|
+
});
|
|
214
247
|
}
|
|
215
248
|
}
|
|
216
249
|
return issues;
|
|
@@ -295,12 +328,14 @@ const RULES = [
|
|
|
295
328
|
return issues;
|
|
296
329
|
// If DynamicSkyNode appears but SceneView { } doesn't, it's likely wrong
|
|
297
330
|
if (!code.includes("SceneView(") && !code.includes("SceneView {")) {
|
|
298
|
-
findLines(lines, /DynamicSkyNode\s*\(/).forEach((line) =>
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
331
|
+
findLines(lines, /DynamicSkyNode\s*\(/).forEach((line) => {
|
|
332
|
+
issues.push({
|
|
333
|
+
severity: "warning",
|
|
334
|
+
rule: "api/dynamic-sky-outside-scene",
|
|
335
|
+
message: "`DynamicSkyNode` is a `SceneScope` extension composable — it must be declared inside a `SceneView { }` content block, not at the top level.",
|
|
336
|
+
line,
|
|
337
|
+
});
|
|
338
|
+
});
|
|
304
339
|
}
|
|
305
340
|
return issues;
|
|
306
341
|
},
|
|
@@ -311,12 +346,14 @@ const RULES = [
|
|
|
311
346
|
severity: "error",
|
|
312
347
|
check(code, lines) {
|
|
313
348
|
const issues = [];
|
|
314
|
-
findLines(lines, /import\s+com\.google\.ar\.sceneform/).forEach((line) =>
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
349
|
+
findLines(lines, /import\s+com\.google\.ar\.sceneform/).forEach((line) => {
|
|
350
|
+
issues.push({
|
|
351
|
+
severity: "error",
|
|
352
|
+
rule: "migration/sceneform-import",
|
|
353
|
+
message: "Sceneform imports detected (`com.google.ar.sceneform.*`). Sceneform was deprecated by Google in 2021. Use `io.github.sceneview.*` imports instead — SceneView is the official successor.",
|
|
354
|
+
line,
|
|
355
|
+
});
|
|
356
|
+
});
|
|
320
357
|
return issues;
|
|
321
358
|
},
|
|
322
359
|
},
|
|
@@ -350,12 +387,14 @@ const RULES = [
|
|
|
350
387
|
const issues = [];
|
|
351
388
|
const engineCreations = findLines(lines, /rememberEngine\(\)|Engine\.create\(/);
|
|
352
389
|
if (engineCreations.length > 1) {
|
|
353
|
-
engineCreations.slice(1).forEach((line) =>
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
390
|
+
engineCreations.slice(1).forEach((line) => {
|
|
391
|
+
issues.push({
|
|
392
|
+
severity: "warning",
|
|
393
|
+
rule: "performance/multiple-engines",
|
|
394
|
+
message: "Multiple Engine instances detected. Each Engine allocates significant GPU memory. Use a single `rememberEngine()` at the top level and pass it to all Scene composables.",
|
|
395
|
+
line,
|
|
396
|
+
});
|
|
397
|
+
});
|
|
359
398
|
}
|
|
360
399
|
return issues;
|
|
361
400
|
},
|
|
@@ -368,12 +407,14 @@ const RULES = [
|
|
|
368
407
|
const issues = [];
|
|
369
408
|
// Detect modelLoader calls inside LaunchedEffect — should use rememberModelInstance instead
|
|
370
409
|
if (/LaunchedEffect/.test(code) && /modelLoader\.(createModel|loadModel)/.test(code)) {
|
|
371
|
-
findLines(lines, /modelLoader\.(createModel|loadModel)/).forEach((line) =>
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
410
|
+
findLines(lines, /modelLoader\.(createModel|loadModel)/).forEach((line) => {
|
|
411
|
+
issues.push({
|
|
412
|
+
severity: "error",
|
|
413
|
+
rule: "threading/model-in-launched-effect",
|
|
414
|
+
message: "Model loading inside `LaunchedEffect` is risky — if the coroutine runs on a background dispatcher, Filament will crash. Use `rememberModelInstance(modelLoader, path)` instead, which handles threading and lifecycle automatically.",
|
|
415
|
+
line,
|
|
416
|
+
});
|
|
417
|
+
});
|
|
377
418
|
}
|
|
378
419
|
return issues;
|
|
379
420
|
},
|
|
@@ -384,13 +425,17 @@ const RULES = [
|
|
|
384
425
|
severity: "error",
|
|
385
426
|
check(code, lines) {
|
|
386
427
|
const issues = [];
|
|
387
|
-
if (code.includes("rememberModelInstance") &&
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
428
|
+
if (code.includes("rememberModelInstance") &&
|
|
429
|
+
!code.includes("modelLoader") &&
|
|
430
|
+
!code.includes("rememberModelLoader")) {
|
|
431
|
+
findLines(lines, /rememberModelInstance\(/).forEach((line) => {
|
|
432
|
+
issues.push({
|
|
433
|
+
severity: "error",
|
|
434
|
+
rule: "api/remember-model-missing-loader",
|
|
435
|
+
message: "`rememberModelInstance` requires a `ModelLoader`. Add `val modelLoader = rememberModelLoader(engine)` and pass it as the first parameter.",
|
|
436
|
+
line,
|
|
437
|
+
});
|
|
438
|
+
});
|
|
394
439
|
}
|
|
395
440
|
return issues;
|
|
396
441
|
},
|
|
@@ -408,12 +453,14 @@ const RULES = [
|
|
|
408
453
|
/createHDREnvironment\s*\(\s*"\/[^"]+"/,
|
|
409
454
|
];
|
|
410
455
|
for (const pat of patterns) {
|
|
411
|
-
findLines(lines, pat).forEach((line) =>
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
456
|
+
findLines(lines, pat).forEach((line) => {
|
|
457
|
+
issues.push({
|
|
458
|
+
severity: "warning",
|
|
459
|
+
rule: "api/asset-path-leading-slash",
|
|
460
|
+
message: 'Asset path starts with `/`. Android asset paths are relative to `src/main/assets/` — use `"models/file.glb"` without a leading slash.',
|
|
461
|
+
line,
|
|
462
|
+
});
|
|
463
|
+
});
|
|
417
464
|
}
|
|
418
465
|
return issues;
|
|
419
466
|
},
|
|
@@ -427,7 +474,10 @@ const RULES = [
|
|
|
427
474
|
const sceneLines = findLines(lines, /\b(AR)?SceneView\s*\(/);
|
|
428
475
|
sceneLines.forEach((line) => {
|
|
429
476
|
const block = lines.slice(line - 1, line + 5).join("\n");
|
|
430
|
-
if (!block.includes("fillMaxSize") &&
|
|
477
|
+
if (!block.includes("fillMaxSize") &&
|
|
478
|
+
!block.includes("size") &&
|
|
479
|
+
!block.includes("height") &&
|
|
480
|
+
!block.includes("width")) {
|
|
431
481
|
issues.push({
|
|
432
482
|
severity: "info",
|
|
433
483
|
rule: "api/scene-zero-size",
|
|
@@ -531,12 +581,14 @@ const RULES = [
|
|
|
531
581
|
if (isKnownTypeName(name))
|
|
532
582
|
continue;
|
|
533
583
|
const suggestion = didYouMean(name, knownTypeNames());
|
|
534
|
-
findLines(lines, new RegExp(`\\b${name}\\s*[({]`)).forEach((line) =>
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
584
|
+
findLines(lines, new RegExp(`\\b${name}\\s*[({]`)).forEach((line) => {
|
|
585
|
+
issues.push({
|
|
586
|
+
severity: "error",
|
|
587
|
+
rule: "symbols/unknown-type",
|
|
588
|
+
message: `\`${name}\` does not exist in the SceneView public API.${suggestion} Node types and declarative factories are listed in \`llms.txt\`.`,
|
|
589
|
+
line,
|
|
590
|
+
});
|
|
591
|
+
});
|
|
540
592
|
}
|
|
541
593
|
return issues;
|
|
542
594
|
},
|
|
@@ -604,12 +656,14 @@ const RULES = [
|
|
|
604
656
|
if (!members || members.has(member))
|
|
605
657
|
continue;
|
|
606
658
|
const suggestion = didYouMean(member, members);
|
|
607
|
-
findLines(lines, new RegExp(`\\b${receiver}\\.${member}\\s*\\(`)).forEach((line) =>
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
659
|
+
findLines(lines, new RegExp(`\\b${receiver}\\.${member}\\s*\\(`)).forEach((line) => {
|
|
660
|
+
issues.push({
|
|
661
|
+
severity: "error",
|
|
662
|
+
rule: "symbols/unknown-member",
|
|
663
|
+
message: `\`${receivers[receiver]}.${member}()\` does not exist.${suggestion} The full member list is in \`llms.txt\`.`,
|
|
664
|
+
line,
|
|
665
|
+
});
|
|
666
|
+
});
|
|
613
667
|
}
|
|
614
668
|
return issues;
|
|
615
669
|
},
|
|
@@ -639,12 +693,14 @@ const RULES = [
|
|
|
639
693
|
if (isKnownTopLevelFunction(fullName))
|
|
640
694
|
continue;
|
|
641
695
|
const suggestion = didYouMean(fullName, rememberHelperNames());
|
|
642
|
-
findLines(lines, new RegExp(`\\b${fullName}\\s*\\(`)).forEach((line) =>
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
696
|
+
findLines(lines, new RegExp(`\\b${fullName}\\s*\\(`)).forEach((line) => {
|
|
697
|
+
issues.push({
|
|
698
|
+
severity: "warning",
|
|
699
|
+
rule: "symbols/unknown-remember-helper",
|
|
700
|
+
message: `\`${fullName}\` is not a SceneView composable helper.${suggestion} If it comes from another library, add its import; otherwise check \`llms.txt\`.`,
|
|
701
|
+
line,
|
|
702
|
+
});
|
|
703
|
+
});
|
|
648
704
|
}
|
|
649
705
|
return issues;
|
|
650
706
|
},
|
|
@@ -661,12 +717,14 @@ const SWIFT_RULES = [
|
|
|
661
717
|
// If there's an async function that loads models but no @MainActor annotation
|
|
662
718
|
if (/func\s+\w+.*async/.test(code) && /ModelNode\.load\(/.test(code)) {
|
|
663
719
|
if (!code.includes("@MainActor")) {
|
|
664
|
-
findLines(lines, /func\s+\w+.*async/).forEach((line) =>
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
720
|
+
findLines(lines, /func\s+\w+.*async/).forEach((line) => {
|
|
721
|
+
issues.push({
|
|
722
|
+
severity: "warning",
|
|
723
|
+
rule: "swift/missing-main-actor",
|
|
724
|
+
message: "Async function that loads RealityKit models should be annotated with `@MainActor` or called from a `@MainActor` context. RealityKit entity operations are main-thread-bound. Using `.task { }` in SwiftUI is already `@MainActor`-isolated, but standalone functions should be annotated.",
|
|
725
|
+
line,
|
|
726
|
+
});
|
|
727
|
+
});
|
|
670
728
|
}
|
|
671
729
|
}
|
|
672
730
|
return issues;
|
|
@@ -686,7 +744,7 @@ const SWIFT_RULES = [
|
|
|
686
744
|
issues.push({
|
|
687
745
|
severity: "error",
|
|
688
746
|
rule: "swift/model-load-not-async",
|
|
689
|
-
message:
|
|
747
|
+
message: '`ModelNode.load()` is `async throws` — you must call it with `try await ModelNode.load("model.usdz")` inside a `.task { }` block or async function.',
|
|
690
748
|
line,
|
|
691
749
|
});
|
|
692
750
|
}
|
|
@@ -702,7 +760,27 @@ const SWIFT_RULES = [
|
|
|
702
760
|
check(code, lines) {
|
|
703
761
|
const issues = [];
|
|
704
762
|
// Check if SceneViewSwift types are used but not imported
|
|
705
|
-
const svTypes = [
|
|
763
|
+
const svTypes = [
|
|
764
|
+
"SceneView",
|
|
765
|
+
"ARSceneView",
|
|
766
|
+
"ModelNode",
|
|
767
|
+
"GeometryNode",
|
|
768
|
+
"LightNode",
|
|
769
|
+
"TextNode",
|
|
770
|
+
"VideoNode",
|
|
771
|
+
"PhysicsNode",
|
|
772
|
+
"BillboardNode",
|
|
773
|
+
"AnchorNode",
|
|
774
|
+
"AugmentedImageNode",
|
|
775
|
+
"ImageNode",
|
|
776
|
+
"CameraNode",
|
|
777
|
+
"PathNode",
|
|
778
|
+
"LineNode",
|
|
779
|
+
"MeshNode",
|
|
780
|
+
"FogNode",
|
|
781
|
+
"DynamicSkyNode",
|
|
782
|
+
"ReflectionProbeNode",
|
|
783
|
+
];
|
|
706
784
|
const usesSceneView = svTypes.some((t) => code.includes(t));
|
|
707
785
|
if (usesSceneView && !code.includes("import SceneViewSwift")) {
|
|
708
786
|
issues.push({
|
|
@@ -713,7 +791,14 @@ const SWIFT_RULES = [
|
|
|
713
791
|
});
|
|
714
792
|
}
|
|
715
793
|
// Check for RealityKit types without import
|
|
716
|
-
const rkTypes = [
|
|
794
|
+
const rkTypes = [
|
|
795
|
+
"Entity",
|
|
796
|
+
"ModelEntity",
|
|
797
|
+
"AnchorEntity",
|
|
798
|
+
"RealityView",
|
|
799
|
+
"MeshResource",
|
|
800
|
+
"SimpleMaterial",
|
|
801
|
+
];
|
|
717
802
|
const usesRK = rkTypes.some((t) => new RegExp(`\\b${t}\\b`).test(code));
|
|
718
803
|
if (usesRK && !code.includes("import RealityKit")) {
|
|
719
804
|
issues.push({
|
|
@@ -742,13 +827,16 @@ const SWIFT_RULES = [
|
|
|
742
827
|
];
|
|
743
828
|
for (const [pat, name] of patterns) {
|
|
744
829
|
// Only flag if the variable is likely a SceneViewSwift node wrapper, not a raw Entity
|
|
745
|
-
if (pat.test(code) &&
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
830
|
+
if (pat.test(code) &&
|
|
831
|
+
new RegExp(`(ModelNode|GeometryNode|LightNode|TextNode|VideoNode|BillboardNode).*\\b${name}\\b`).test(code)) {
|
|
832
|
+
findLines(lines, pat).forEach((line) => {
|
|
833
|
+
issues.push({
|
|
834
|
+
severity: "error",
|
|
835
|
+
rule: "swift/add-child-wrong-type",
|
|
836
|
+
message: `\`addChild(${name})\` — SceneViewSwift node wrappers are not \`Entity\` subclasses. Use \`addChild(${name}.entity)\` to add the underlying RealityKit entity.`,
|
|
837
|
+
line,
|
|
838
|
+
});
|
|
839
|
+
});
|
|
752
840
|
}
|
|
753
841
|
}
|
|
754
842
|
return issues;
|
|
@@ -762,12 +850,14 @@ const SWIFT_RULES = [
|
|
|
762
850
|
const issues = [];
|
|
763
851
|
if (code.includes("ARSceneView")) {
|
|
764
852
|
if (code.includes("macOS") || code.includes("visionOS")) {
|
|
765
|
-
findLines(lines, /ARSceneView/).forEach((line) =>
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
853
|
+
findLines(lines, /ARSceneView/).forEach((line) => {
|
|
854
|
+
issues.push({
|
|
855
|
+
severity: "info",
|
|
856
|
+
rule: "swift/ar-platform-check",
|
|
857
|
+
message: "`ARSceneView` uses `ARView` which is only available on iOS. For macOS use `SceneView` (3D only). For visionOS, use RealityKit's `RealityView` with `ARKitSession` directly.",
|
|
858
|
+
line,
|
|
859
|
+
});
|
|
860
|
+
});
|
|
771
861
|
}
|
|
772
862
|
}
|
|
773
863
|
return issues;
|
|
@@ -781,12 +871,14 @@ const SWIFT_RULES = [
|
|
|
781
871
|
const issues = [];
|
|
782
872
|
// Using try? silently swallows errors — warning but not error
|
|
783
873
|
if (/try\?\s+await\s+ModelNode\.load/.test(code)) {
|
|
784
|
-
findLines(lines, /try\?\s+await\s+ModelNode\.load/).forEach((line) =>
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
874
|
+
findLines(lines, /try\?\s+await\s+ModelNode\.load/).forEach((line) => {
|
|
875
|
+
issues.push({
|
|
876
|
+
severity: "warning",
|
|
877
|
+
rule: "swift/unhandled-model-load-error",
|
|
878
|
+
message: "`try?` on `ModelNode.load()` silently swallows load failures. Consider using `do { try await ... } catch { print(error) }` to at least log failures, or show a loading indicator.",
|
|
879
|
+
line,
|
|
880
|
+
});
|
|
881
|
+
});
|
|
790
882
|
}
|
|
791
883
|
return issues;
|
|
792
884
|
},
|
|
@@ -818,13 +910,18 @@ const WEB_RULES = [
|
|
|
818
910
|
severity: "warning",
|
|
819
911
|
check(code, lines) {
|
|
820
912
|
const issues = [];
|
|
821
|
-
if (code.includes("getElementById") &&
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
913
|
+
if (code.includes("getElementById") &&
|
|
914
|
+
!code.includes("as?") &&
|
|
915
|
+
!code.includes("?: ") &&
|
|
916
|
+
!code.includes("== null")) {
|
|
917
|
+
findLines(lines, /getElementById/).forEach((line) => {
|
|
918
|
+
issues.push({
|
|
919
|
+
severity: "warning",
|
|
920
|
+
rule: "web/missing-canvas-null-check",
|
|
921
|
+
message: "Canvas element lookup should include a null check. Use `as? HTMLCanvasElement` with a null guard.",
|
|
922
|
+
line,
|
|
923
|
+
});
|
|
924
|
+
});
|
|
828
925
|
}
|
|
829
926
|
return issues;
|
|
830
927
|
},
|
|
@@ -834,7 +931,9 @@ const WEB_RULES = [
|
|
|
834
931
|
severity: "info",
|
|
835
932
|
check(code, lines) {
|
|
836
933
|
const issues = [];
|
|
837
|
-
if (code.includes("SceneView.create(") &&
|
|
934
|
+
if (code.includes("SceneView.create(") &&
|
|
935
|
+
!code.includes("clientWidth") &&
|
|
936
|
+
!code.includes("resize")) {
|
|
838
937
|
issues.push({
|
|
839
938
|
severity: "info",
|
|
840
939
|
rule: "web/missing-canvas-resize",
|
|
@@ -850,12 +949,14 @@ const WEB_RULES = [
|
|
|
850
949
|
check(code, lines) {
|
|
851
950
|
const issues = [];
|
|
852
951
|
if (code.includes("ARScene") || code.includes("ARSceneView")) {
|
|
853
|
-
findLines(lines, /ARScene|ARSceneView/).forEach((line) =>
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
952
|
+
findLines(lines, /ARScene|ARSceneView/).forEach((line) => {
|
|
953
|
+
issues.push({
|
|
954
|
+
severity: "error",
|
|
955
|
+
rule: "web/ar-not-supported",
|
|
956
|
+
message: "AR is not supported on the web platform. SceneView Web only supports 3D scenes (no camera/sensor access in browsers). Use `SceneView.create()` for 3D-only web rendering.",
|
|
957
|
+
line,
|
|
958
|
+
});
|
|
959
|
+
});
|
|
859
960
|
}
|
|
860
961
|
return issues;
|
|
861
962
|
},
|