sceneview-mcp 4.0.14 → 4.0.16

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/dist/validator.js CHANGED
@@ -1,8 +1,20 @@
1
+ import { didYouMean, isKnownTopLevelFunction, isKnownTypeName, knownTypeNames, membersOfClass, rememberHelperNames, resolveImport, } from "./symbols.js";
1
2
  function findLines(lines, pattern) {
2
3
  return lines
3
4
  .map((l, i) => (pattern.test(l) ? i + 1 : -1))
4
5
  .filter((n) => n !== -1);
5
6
  }
7
+ // Symbols the snippet declares itself (`fun MyShowcaseScene(…)`, `class ShelfNode(…) :
8
+ // Node(engine)`) exist by definition — they are the caller's own wrappers, not calls into
9
+ // SceneView, and the SDK's naming idiom (`WallPlacementScene`, `PhysicsNode`) makes such
10
+ // suffixes natural. The optional `<…>` skips a generic parameter list before the name.
11
+ function locallyDeclaredNames(code) {
12
+ const names = new Set();
13
+ for (const m of code.matchAll(/\b(?:fun|class|interface|object)\s+(?:<[^>]*>\s+)?(\w+)/g)) {
14
+ names.add(m[1]);
15
+ }
16
+ return names;
17
+ }
6
18
  const RULES = [
7
19
  // ─── Threading ────────────────────────────────────────────────────────────
8
20
  {
@@ -450,6 +462,193 @@ const RULES = [
450
462
  return issues;
451
463
  },
452
464
  },
465
+ // ─── Symbol existence (#2760) — backed by the generated .api index ────────
466
+ //
467
+ // These rules answer "does this API actually exist?", the #1 failure mode
468
+ // of AI-generated snippets. The index covers the Android/KMP surface
469
+ // (sceneview, arsceneview, sceneview-core) — see `symbols.ts`. Each rule is
470
+ // deliberately narrow so its false-positive space is ~zero.
471
+ {
472
+ // `import io.github.sceneview.…` that resolves to nothing. Our own
473
+ // namespace: nothing outside the index can legitimately live there.
474
+ // Known tolerated false NEGATIVE: aliased imports (`import … as MN`)
475
+ // don't match the end-of-line anchor and are silently skipped — an
476
+ // unchecked alias can never become a false positive.
477
+ id: "symbols/unknown-import",
478
+ severity: "error",
479
+ check(code, lines) {
480
+ const issues = [];
481
+ const importRe = /^\s*import\s+(io\.github\.sceneview(?:\.\w+)*)(\.\*)?\s*$/;
482
+ lines.forEach((content, i) => {
483
+ const m = importRe.exec(content);
484
+ if (!m)
485
+ return;
486
+ const path = m[1];
487
+ const isWildcard = m[2] !== undefined;
488
+ const resolved = resolveImport(path);
489
+ const ok = isWildcard ? resolved === "package" : resolved !== null;
490
+ if (ok)
491
+ return;
492
+ const leaf = path.slice(path.lastIndexOf(".") + 1);
493
+ const suggestion = didYouMean(leaf, knownTypeNames());
494
+ issues.push({
495
+ severity: "error",
496
+ rule: "symbols/unknown-import",
497
+ message: `\`import ${path}${isWildcard ? ".*" : ""}\` does not exist in the SceneView public API.${suggestion} Check the class name and package against \`llms.txt\`.`,
498
+ line: i + 1,
499
+ });
500
+ });
501
+ return issues;
502
+ },
503
+ },
504
+ {
505
+ // A made-up `…Node(` / `…Node {` / `…Scene(` type or declarative factory.
506
+ id: "symbols/unknown-type",
507
+ severity: "error",
508
+ check(code, lines) {
509
+ const issues = [];
510
+ // Names already handled (with a better, migration-specific message) by
511
+ // `migration/old-api` — don't double-report them here.
512
+ const migrationCovered = new Set([
513
+ "Scene",
514
+ "ARScene",
515
+ "ArSceneView",
516
+ "PlacementNode",
517
+ "TransformableNode",
518
+ ]);
519
+ const callRe = /\b([A-Z]\w*(?:Node|Scene))\s*[({]/g;
520
+ const localNames = locallyDeclaredNames(code);
521
+ const seen = new Set();
522
+ for (const match of code.matchAll(callRe)) {
523
+ const name = match[1];
524
+ if (seen.has(name))
525
+ continue;
526
+ seen.add(name);
527
+ if (migrationCovered.has(name))
528
+ continue;
529
+ if (localNames.has(name))
530
+ continue;
531
+ if (isKnownTypeName(name))
532
+ continue;
533
+ const suggestion = didYouMean(name, knownTypeNames());
534
+ findLines(lines, new RegExp(`\\b${name}\\s*[({]`)).forEach((line) => issues.push({
535
+ severity: "error",
536
+ rule: "symbols/unknown-type",
537
+ message: `\`${name}\` does not exist in the SceneView public API.${suggestion} Node types and declarative factories are listed in \`llms.txt\`.`,
538
+ line,
539
+ }));
540
+ }
541
+ return issues;
542
+ },
543
+ },
544
+ {
545
+ // A nonexistent member called on a canonically-named loader variable —
546
+ // e.g. `modelLoader.createModelInstanceAsync(...)` (the real API is
547
+ // `loadModelInstanceAsync`). Heuristic on the receiver NAME, which the
548
+ // docs and every sample use consistently.
549
+ id: "symbols/unknown-member",
550
+ severity: "error",
551
+ check(code, lines) {
552
+ const issues = [];
553
+ const receivers = {
554
+ modelLoader: "ModelLoader",
555
+ materialLoader: "MaterialLoader",
556
+ environmentLoader: "EnvironmentLoader",
557
+ };
558
+ // Kotlin stdlib scope/extension functions callable on any receiver.
559
+ const stdlib = new Set([
560
+ "apply",
561
+ "also",
562
+ "let",
563
+ "run",
564
+ "takeIf",
565
+ "takeUnless",
566
+ "to",
567
+ "use",
568
+ "toString",
569
+ ]);
570
+ // A snippet may rebind a canonical name to its own type
571
+ // (`val modelLoader = MyRepository()`) — member-checking that variable
572
+ // against the SceneView loader would be a false positive
573
+ // (adversarial-review finding #3 on PR #2814). Keep checking only when
574
+ // the declaration is recognizably the real loader: a `remember<Class>`
575
+ // call, a direct constructor, a `: <Class>` type annotation, or a
576
+ // `.<receiver>` property access — or when there is no local
577
+ // declaration at all (the scope provides it, the canonical case).
578
+ const rebound = new Set();
579
+ for (const [receiver, className] of Object.entries(receivers)) {
580
+ const decl = new RegExp(`\\b(?:val|var)\\s+${receiver}\\s*(?::\\s*([^=\\n]+?))?\\s*=\\s*(.+)`).exec(code);
581
+ if (!decl)
582
+ continue;
583
+ const [, typeAnnotation, rhs] = decl;
584
+ const looksReal = (typeAnnotation?.includes(className) ?? false) ||
585
+ rhs.includes(`remember${className}`) ||
586
+ rhs.includes(`${className}(`) ||
587
+ rhs.trimEnd().endsWith(`.${receiver}`);
588
+ if (!looksReal)
589
+ rebound.add(receiver);
590
+ }
591
+ const callRe = /\b(modelLoader|materialLoader|environmentLoader)\.(\w+)\s*\(/g;
592
+ const reported = new Set();
593
+ for (const match of code.matchAll(callRe)) {
594
+ const [, receiver, member] = match;
595
+ const key = `${receiver}.${member}`;
596
+ if (reported.has(key))
597
+ continue;
598
+ reported.add(key);
599
+ if (rebound.has(receiver))
600
+ continue;
601
+ if (stdlib.has(member))
602
+ continue;
603
+ const members = membersOfClass(receivers[receiver]);
604
+ if (!members || members.has(member))
605
+ continue;
606
+ const suggestion = didYouMean(member, members);
607
+ findLines(lines, new RegExp(`\\b${receiver}\\.${member}\\s*\\(`)).forEach((line) => issues.push({
608
+ severity: "error",
609
+ rule: "symbols/unknown-member",
610
+ message: `\`${receivers[receiver]}.${member}()\` does not exist.${suggestion} The full member list is in \`llms.txt\`.`,
611
+ line,
612
+ }));
613
+ }
614
+ return issues;
615
+ },
616
+ },
617
+ {
618
+ // `remember<SceneView-ish>` helper that isn't a real top-level function —
619
+ // e.g. an invented `rememberModelInstanceAsync`. Warning, not error: a
620
+ // snippet may legitimately mix non-SceneView Compose libraries whose
621
+ // helpers match the keyword net (e.g. Maps `rememberCameraPositionState`).
622
+ id: "symbols/unknown-remember-helper",
623
+ severity: "warning",
624
+ check(code, lines) {
625
+ const issues = [];
626
+ const sceneViewish = /^(Engine|Model|Material|Environment|Scene|Node|Collision|Render|Skybox|View|AR|Camera|Splat)/;
627
+ const callRe = /\bremember([A-Z]\w*)\s*\(/g;
628
+ const localNames = locallyDeclaredNames(code);
629
+ const seen = new Set();
630
+ for (const match of code.matchAll(callRe)) {
631
+ const fullName = `remember${match[1]}`;
632
+ if (seen.has(fullName))
633
+ continue;
634
+ seen.add(fullName);
635
+ if (!sceneViewish.test(match[1]))
636
+ continue;
637
+ if (localNames.has(fullName))
638
+ continue;
639
+ if (isKnownTopLevelFunction(fullName))
640
+ continue;
641
+ const suggestion = didYouMean(fullName, rememberHelperNames());
642
+ findLines(lines, new RegExp(`\\b${fullName}\\s*\\(`)).forEach((line) => issues.push({
643
+ severity: "warning",
644
+ rule: "symbols/unknown-remember-helper",
645
+ message: `\`${fullName}\` is not a SceneView composable helper.${suggestion} If it comes from another library, add its import; otherwise check \`llms.txt\`.`,
646
+ line,
647
+ }));
648
+ }
649
+ return issues;
650
+ },
651
+ },
453
652
  ];
454
653
  // ─── Swift Validation Rules ──────────────────────────────────────────────────
455
654
  const SWIFT_RULES = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sceneview-mcp",
3
- "version": "4.0.14",
3
+ "version": "4.0.16",
4
4
  "mcpName": "io.github.sceneview/mcp",
5
5
  "description": "MCP server for SceneView — cross-platform 3D & AR SDK for Android and iOS. Give Claude the full SceneView SDK so it writes correct, compilable code.",
6
6
  "keywords": [
@@ -59,12 +59,12 @@
59
59
  "node": ">=18"
60
60
  },
61
61
  "scripts": {
62
- "prebuild": "node scripts/generate-llms-txt.js && node scripts/generate-version.js",
62
+ "prebuild": "node scripts/generate-llms-txt.js && node scripts/generate-version.js && node scripts/generate-symbols.js",
63
63
  "build": "tsc",
64
- "prepare": "node scripts/generate-llms-txt.js && node scripts/generate-version.js && tsc",
64
+ "prepare": "node scripts/generate-llms-txt.js && node scripts/generate-version.js && node scripts/generate-symbols.js && tsc",
65
65
  "start": "node dist/index.js",
66
66
  "dev": "tsx src/index.ts",
67
- "test": "node scripts/generate-llms-txt.js && node scripts/generate-version.js && vitest run",
67
+ "test": "node scripts/generate-llms-txt.js && node scripts/generate-version.js && node scripts/generate-symbols.js && vitest run",
68
68
  "biome": "cd .. && mcp/node_modules/.bin/biome check",
69
69
  "biome:fix": "cd .. && mcp/node_modules/.bin/biome check --write"
70
70
  },