@snaptrude/plugin-core 0.3.0 → 0.5.0

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 (266) hide show
  1. package/AGENTS.md +130 -48
  2. package/CHANGELOG.md +111 -0
  3. package/api-manifest.full.json +3999 -0
  4. package/api-manifest.json +3845 -0
  5. package/dist/api/core/buildings.d.ts +427 -0
  6. package/dist/api/core/buildings.d.ts.map +1 -0
  7. package/dist/api/core/comment/index.d.ts +230 -0
  8. package/dist/api/core/comment/index.d.ts.map +1 -0
  9. package/dist/api/core/geom/create/index.d.ts +247 -0
  10. package/dist/api/core/geom/create/index.d.ts.map +1 -0
  11. package/dist/api/core/geom/delete/index.d.ts +72 -0
  12. package/dist/api/core/geom/delete/index.d.ts.map +1 -0
  13. package/dist/api/core/geom/index.d.ts +24 -23
  14. package/dist/api/core/geom/index.d.ts.map +1 -1
  15. package/dist/api/core/geom/query/arc.d.ts +169 -0
  16. package/dist/api/core/geom/query/arc.d.ts.map +1 -0
  17. package/dist/api/core/geom/query/brep.d.ts +402 -0
  18. package/dist/api/core/geom/query/brep.d.ts.map +1 -0
  19. package/dist/api/core/geom/query/circle.d.ts +378 -0
  20. package/dist/api/core/geom/query/circle.d.ts.map +1 -0
  21. package/dist/api/core/geom/query/contour.d.ts +450 -0
  22. package/dist/api/core/geom/query/contour.d.ts.map +1 -0
  23. package/dist/api/core/geom/query/curve.d.ts +918 -0
  24. package/dist/api/core/geom/query/curve.d.ts.map +1 -0
  25. package/dist/api/core/geom/query/edge.d.ts +128 -0
  26. package/dist/api/core/geom/query/edge.d.ts.map +1 -0
  27. package/dist/api/core/geom/query/face.d.ts +363 -0
  28. package/dist/api/core/geom/query/face.d.ts.map +1 -0
  29. package/dist/api/core/geom/query/halfedge.d.ts +206 -0
  30. package/dist/api/core/geom/query/halfedge.d.ts.map +1 -0
  31. package/dist/api/core/geom/query/index.d.ts +61 -0
  32. package/dist/api/core/geom/query/index.d.ts.map +1 -0
  33. package/dist/api/core/geom/query/profile.d.ts +410 -0
  34. package/dist/api/core/geom/query/profile.d.ts.map +1 -0
  35. package/dist/api/core/geom/query/vertex.d.ts +187 -0
  36. package/dist/api/core/geom/query/vertex.d.ts.map +1 -0
  37. package/dist/api/core/geom/update/contour.d.ts +272 -0
  38. package/dist/api/core/geom/update/contour.d.ts.map +1 -0
  39. package/dist/api/core/geom/update/curve.d.ts +180 -0
  40. package/dist/api/core/geom/update/curve.d.ts.map +1 -0
  41. package/dist/api/core/geom/update/index.d.ts +27 -0
  42. package/dist/api/core/geom/update/index.d.ts.map +1 -0
  43. package/dist/api/core/geom/update/profile.d.ts +329 -0
  44. package/dist/api/core/geom/update/profile.d.ts.map +1 -0
  45. package/dist/api/core/groups.d.ts +485 -0
  46. package/dist/api/core/groups.d.ts.map +1 -0
  47. package/dist/api/core/history/index.d.ts +78 -0
  48. package/dist/api/core/history/index.d.ts.map +1 -0
  49. package/dist/api/core/index.d.ts +46 -1
  50. package/dist/api/core/index.d.ts.map +1 -1
  51. package/dist/api/core/layers.d.ts +402 -0
  52. package/dist/api/core/layers.d.ts.map +1 -0
  53. package/dist/api/core/math/quat.d.ts +111 -128
  54. package/dist/api/core/math/quat.d.ts.map +1 -1
  55. package/dist/api/core/math/vec3.d.ts +120 -102
  56. package/dist/api/core/math/vec3.d.ts.map +1 -1
  57. package/dist/api/core/project/index.d.ts +399 -0
  58. package/dist/api/core/project/index.d.ts.map +1 -0
  59. package/dist/api/core/tags.d.ts +755 -0
  60. package/dist/api/core/tags.d.ts.map +1 -0
  61. package/dist/api/core/units/index.d.ts +175 -0
  62. package/dist/api/core/units/index.d.ts.map +1 -0
  63. package/dist/api/core/zoom/index.d.ts +45 -0
  64. package/dist/api/core/zoom/index.d.ts.map +1 -0
  65. package/dist/api/design/boolean/index.d.ts +168 -0
  66. package/dist/api/design/boolean/index.d.ts.map +1 -0
  67. package/dist/api/design/create/index.d.ts +828 -0
  68. package/dist/api/design/create/index.d.ts.map +1 -0
  69. package/dist/api/design/delete/index.d.ts +63 -0
  70. package/dist/api/design/delete/index.d.ts.map +1 -0
  71. package/dist/api/design/doors/index.d.ts +268 -0
  72. package/dist/api/design/doors/index.d.ts.map +1 -0
  73. package/dist/api/design/edit/index.d.ts +49 -0
  74. package/dist/api/design/edit/index.d.ts.map +1 -0
  75. package/dist/api/design/erase/index.d.ts +160 -0
  76. package/dist/api/design/erase/index.d.ts.map +1 -0
  77. package/dist/api/design/furniture/index.d.ts +123 -0
  78. package/dist/api/design/furniture/index.d.ts.map +1 -0
  79. package/dist/api/design/index.d.ts +153 -0
  80. package/dist/api/design/index.d.ts.map +1 -0
  81. package/dist/api/design/lock.d.ts +41 -0
  82. package/dist/api/design/lock.d.ts.map +1 -0
  83. package/dist/api/design/materials/index.d.ts +297 -0
  84. package/dist/api/design/materials/index.d.ts.map +1 -0
  85. package/dist/api/design/query/geometry/index.d.ts +140 -0
  86. package/dist/api/design/query/geometry/index.d.ts.map +1 -0
  87. package/dist/api/design/query/index.d.ts +1011 -0
  88. package/dist/api/design/query/index.d.ts.map +1 -0
  89. package/dist/api/design/query/spaces.d.ts +221 -0
  90. package/dist/api/design/query/spaces.d.ts.map +1 -0
  91. package/dist/api/design/selection/index.d.ts +138 -0
  92. package/dist/api/design/selection/index.d.ts.map +1 -0
  93. package/dist/api/design/shared.d.ts +38 -0
  94. package/dist/api/design/shared.d.ts.map +1 -0
  95. package/dist/api/design/transform/index.d.ts +87 -0
  96. package/dist/api/design/transform/index.d.ts.map +1 -0
  97. package/dist/api/design/update/index.d.ts +178 -0
  98. package/dist/api/design/update/index.d.ts.map +1 -0
  99. package/dist/api/design/windows/index.d.ts +189 -0
  100. package/dist/api/design/windows/index.d.ts.map +1 -0
  101. package/dist/api/entity/buildableEnvelope.d.ts +261 -0
  102. package/dist/api/entity/buildableEnvelope.d.ts.map +1 -0
  103. package/dist/api/entity/department.d.ts +0 -98
  104. package/dist/api/entity/department.d.ts.map +1 -1
  105. package/dist/api/entity/index.d.ts +9 -9
  106. package/dist/api/entity/index.d.ts.map +1 -1
  107. package/dist/api/entity/referenceLine.d.ts +49 -106
  108. package/dist/api/entity/referenceLine.d.ts.map +1 -1
  109. package/dist/api/entity/space.d.ts +482 -249
  110. package/dist/api/entity/space.d.ts.map +1 -1
  111. package/dist/api/entity/story.d.ts +49 -39
  112. package/dist/api/entity/story.d.ts.map +1 -1
  113. package/dist/api/index.d.ts +17 -12
  114. package/dist/api/index.d.ts.map +1 -1
  115. package/dist/api/presentation/aiInspiration.d.ts +440 -0
  116. package/dist/api/presentation/aiInspiration.d.ts.map +1 -0
  117. package/dist/api/presentation/diagrams.d.ts +81 -0
  118. package/dist/api/presentation/diagrams.d.ts.map +1 -0
  119. package/dist/api/presentation/import.d.ts +113 -0
  120. package/dist/api/presentation/import.d.ts.map +1 -0
  121. package/dist/api/presentation/index.d.ts +46 -0
  122. package/dist/api/presentation/index.d.ts.map +1 -0
  123. package/dist/api/presentation/sheets.d.ts +176 -0
  124. package/dist/api/presentation/sheets.d.ts.map +1 -0
  125. package/dist/api/presentation/views.d.ts +296 -0
  126. package/dist/api/presentation/views.d.ts.map +1 -0
  127. package/dist/api/program/adjacency.d.ts +155 -0
  128. package/dist/api/program/adjacency.d.ts.map +1 -0
  129. package/dist/api/program/areas.d.ts +360 -0
  130. package/dist/api/program/areas.d.ts.map +1 -0
  131. package/dist/api/program/classification.d.ts +135 -0
  132. package/dist/api/program/classification.d.ts.map +1 -0
  133. package/dist/api/program/cores.d.ts +174 -0
  134. package/dist/api/program/cores.d.ts.map +1 -0
  135. package/dist/api/program/departments.d.ts +431 -0
  136. package/dist/api/program/departments.d.ts.map +1 -0
  137. package/dist/api/program/index.d.ts +69 -0
  138. package/dist/api/program/index.d.ts.map +1 -0
  139. package/dist/api/program/layout.d.ts +63 -0
  140. package/dist/api/program/layout.d.ts.map +1 -0
  141. package/dist/api/program/metrics.d.ts +108 -0
  142. package/dist/api/program/metrics.d.ts.map +1 -0
  143. package/dist/api/program/site.d.ts +367 -0
  144. package/dist/api/program/site.d.ts.map +1 -0
  145. package/dist/api/program/spreadsheet.d.ts +2041 -0
  146. package/dist/api/program/spreadsheet.d.ts.map +1 -0
  147. package/dist/handles.d.ts +138 -0
  148. package/dist/handles.d.ts.map +1 -0
  149. package/dist/host-utils.d.ts +7 -5
  150. package/dist/host-utils.d.ts.map +1 -1
  151. package/dist/index.cjs +4001 -904
  152. package/dist/index.cjs.map +1 -1
  153. package/dist/index.d.ts +1 -0
  154. package/dist/index.d.ts.map +1 -1
  155. package/dist/index.js +3392 -870
  156. package/dist/index.js.map +1 -1
  157. package/package.json +6 -2
  158. package/scripts/generate-manifest.mjs +193 -0
  159. package/scripts/generate-manifest.test.mjs +193 -0
  160. package/src/api/core/buildings.ts +485 -0
  161. package/src/api/core/comment/index.ts +258 -0
  162. package/src/api/core/geom/create/index.ts +293 -0
  163. package/src/api/core/geom/delete/index.ts +78 -0
  164. package/src/api/core/geom/index.ts +24 -23
  165. package/src/api/core/geom/query/arc.ts +169 -0
  166. package/src/api/core/geom/query/brep.ts +444 -0
  167. package/src/api/core/geom/query/circle.ts +404 -0
  168. package/src/api/core/geom/query/contour.ts +540 -0
  169. package/src/api/core/geom/query/curve.ts +1078 -0
  170. package/src/api/core/geom/query/edge.ts +130 -0
  171. package/src/api/core/geom/query/face.ts +403 -0
  172. package/src/api/core/geom/query/halfedge.ts +210 -0
  173. package/src/api/core/geom/query/index.ts +63 -0
  174. package/src/api/core/geom/query/profile.ts +473 -0
  175. package/src/api/core/geom/query/vertex.ts +205 -0
  176. package/src/api/core/geom/update/contour.ts +315 -0
  177. package/src/api/core/geom/update/curve.ts +209 -0
  178. package/src/api/core/geom/update/index.ts +29 -0
  179. package/src/api/core/geom/update/profile.ts +377 -0
  180. package/src/api/core/groups.ts +521 -0
  181. package/src/api/core/history/index.ts +84 -0
  182. package/src/api/core/index.ts +46 -1
  183. package/src/api/core/layers.ts +333 -0
  184. package/src/api/core/math/quat.ts +112 -235
  185. package/src/api/core/math/vec3.ts +124 -159
  186. package/src/api/core/project/index.ts +418 -0
  187. package/src/api/core/tags.ts +808 -0
  188. package/src/api/core/units/index.ts +164 -0
  189. package/src/api/core/zoom/index.ts +47 -0
  190. package/src/api/design/boolean/index.ts +179 -0
  191. package/src/api/design/create/index.ts +886 -0
  192. package/src/api/design/delete/index.ts +67 -0
  193. package/src/api/design/doors/index.ts +285 -0
  194. package/src/api/design/edit/index.ts +54 -0
  195. package/src/api/design/erase/index.ts +151 -0
  196. package/src/api/design/furniture/index.ts +130 -0
  197. package/src/api/design/index.ts +162 -0
  198. package/src/api/design/lock.ts +42 -0
  199. package/src/api/design/materials/index.ts +301 -0
  200. package/src/api/design/query/geometry/index.ts +166 -0
  201. package/src/api/design/query/index.ts +937 -0
  202. package/src/api/design/query/spaces.ts +132 -0
  203. package/src/api/design/selection/index.ts +144 -0
  204. package/src/api/design/shared.ts +40 -0
  205. package/src/api/design/transform/index.ts +93 -0
  206. package/src/api/design/update/index.ts +117 -0
  207. package/src/api/design/windows/index.ts +207 -0
  208. package/src/api/entity/buildableEnvelope.ts +318 -0
  209. package/src/api/entity/department.ts +0 -113
  210. package/src/api/entity/index.ts +9 -9
  211. package/src/api/entity/referenceLine.ts +50 -38
  212. package/src/api/entity/space.ts +285 -226
  213. package/src/api/entity/story.ts +53 -42
  214. package/src/api/index.ts +17 -12
  215. package/src/api/presentation/aiInspiration.ts +362 -0
  216. package/src/api/presentation/diagrams.ts +84 -0
  217. package/src/api/presentation/import.ts +112 -0
  218. package/src/api/presentation/index.ts +48 -0
  219. package/src/api/presentation/sheets.ts +198 -0
  220. package/src/api/presentation/views.ts +303 -0
  221. package/src/api/program/adjacency.ts +164 -0
  222. package/src/api/program/areas.ts +335 -0
  223. package/src/api/program/classification.ts +138 -0
  224. package/src/api/program/cores.ts +171 -0
  225. package/src/api/program/departments.ts +465 -0
  226. package/src/api/program/index.ts +71 -0
  227. package/src/api/program/layout.ts +68 -0
  228. package/src/api/program/metrics.ts +120 -0
  229. package/src/api/program/site.ts +326 -0
  230. package/src/api/program/spreadsheet.ts +2075 -0
  231. package/src/handles.ts +148 -0
  232. package/src/host-utils.ts +10 -6
  233. package/src/index.ts +1 -0
  234. package/dist/api/core/geom/arc.d.ts +0 -81
  235. package/dist/api/core/geom/arc.d.ts.map +0 -1
  236. package/dist/api/core/geom/curve.d.ts +0 -70
  237. package/dist/api/core/geom/curve.d.ts.map +0 -1
  238. package/dist/api/core/geom/line.d.ts +0 -56
  239. package/dist/api/core/geom/line.d.ts.map +0 -1
  240. package/dist/api/core/geom/profile.d.ts +0 -121
  241. package/dist/api/core/geom/profile.d.ts.map +0 -1
  242. package/dist/api/tools/copy.d.ts +0 -59
  243. package/dist/api/tools/copy.d.ts.map +0 -1
  244. package/dist/api/tools/index.d.ts +0 -33
  245. package/dist/api/tools/index.d.ts.map +0 -1
  246. package/dist/api/tools/material.d.ts +0 -51
  247. package/dist/api/tools/material.d.ts.map +0 -1
  248. package/dist/api/tools/offset.d.ts +0 -43
  249. package/dist/api/tools/offset.d.ts.map +0 -1
  250. package/dist/api/tools/selection.d.ts +0 -48
  251. package/dist/api/tools/selection.d.ts.map +0 -1
  252. package/dist/api/tools/transform.d.ts +0 -114
  253. package/dist/api/tools/transform.d.ts.map +0 -1
  254. package/dist/api/units/index.d.ts +0 -163
  255. package/dist/api/units/index.d.ts.map +0 -1
  256. package/src/api/core/geom/arc.ts +0 -70
  257. package/src/api/core/geom/curve.ts +0 -41
  258. package/src/api/core/geom/line.ts +0 -53
  259. package/src/api/core/geom/profile.ts +0 -94
  260. package/src/api/tools/copy.ts +0 -55
  261. package/src/api/tools/index.ts +0 -39
  262. package/src/api/tools/material.ts +0 -49
  263. package/src/api/tools/offset.ts +0 -43
  264. package/src/api/tools/selection.ts +0 -51
  265. package/src/api/tools/transform.ts +0 -117
  266. package/src/api/units/index.ts +0 -163
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snaptrude/plugin-core",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -17,6 +17,7 @@
17
17
  "access": "public"
18
18
  },
19
19
  "devDependencies": {
20
+ "ts-morph": "^28.0.0",
20
21
  "tsup": "^8.5.1",
21
22
  "typescript": "^5.5.4"
22
23
  },
@@ -30,6 +31,9 @@
30
31
  "check-types": "tsc --noEmit",
31
32
  "build": "tsup --clean",
32
33
  "dev": "tsup --watch",
33
- "clean-dist": "rm -rf dist"
34
+ "clean-dist": "rm -rf dist",
35
+ "generate:manifest": "node scripts/generate-manifest.mjs",
36
+ "generate:manifest:check": "node scripts/generate-manifest.mjs --check",
37
+ "generate:manifest:all": "node scripts/generate-manifest.mjs --all"
34
38
  }
35
39
  }
@@ -0,0 +1,193 @@
1
+ // Discovery-manifest generator.
2
+ //
3
+ // The plugin API surface is a tree of abstract `Plugin*Api` classes; the wire
4
+ // method map (`PluginApiMethodMap`) is TYPE-LEVEL ONLY and cannot be enumerated
5
+ // at runtime. This script statically walks the abstract+Zod source with ts-morph
6
+ // and emits a flat, machine-readable manifest of every leaf method:
7
+ //
8
+ // { path, namespace, summary, examplePrompts[], argsType, resultType }
9
+ //
10
+ // The manifest is the substrate the discovery server (plugin-mcp-server) and the
11
+ // retrieval-accuracy eval harness key on. Authors only ever write the abstract
12
+ // class + Zod schemas + JSDoc + `@examplePrompt` lines — this regenerates the rest.
13
+ //
14
+ // Run: `pnpm --filter @snaptrude/plugin-core generate:manifest`
15
+ // add `--check` to assert the on-disk manifest is up-to-date (CI gate);
16
+ // exits non-zero without writing if regeneration would change it.
17
+ import { Project } from "ts-morph"
18
+ import { fileURLToPath } from "node:url"
19
+ import { dirname, resolve } from "node:path"
20
+ import { writeFileSync, readFileSync, existsSync } from "node:fs"
21
+
22
+ const here = dirname(fileURLToPath(import.meta.url))
23
+ const pkgRoot = resolve(here, "..")
24
+ const apiGlob = resolve(pkgRoot, "src/api/**/*.ts")
25
+ const outFile = resolve(pkgRoot, "api-manifest.json")
26
+
27
+ const ROOT_CLASS = "PluginApi"
28
+ const RETURN_WRAPPER = "PluginApiReturn"
29
+
30
+ /** First paragraph of a JSDoc description, whitespace-collapsed. */
31
+ function summaryOf(jsDoc) {
32
+ if (!jsDoc) return ""
33
+ const desc = (jsDoc.getDescription() ?? "").trim()
34
+ const firstPara = desc.split(/\n\s*\n/)[0] ?? ""
35
+ return firstPara.replace(/\s+/g, " ").trim()
36
+ }
37
+
38
+ /** All `@examplePrompt` comment strings on a method's JSDoc. */
39
+ function examplePromptsOf(jsDoc) {
40
+ if (!jsDoc) return []
41
+ return jsDoc
42
+ .getTags()
43
+ .filter((t) => t.getTagName() === "examplePrompt")
44
+ .map((t) => (t.getCommentText() ?? "").trim())
45
+ .filter(Boolean)
46
+ }
47
+
48
+ /** Strip the `PluginApiReturn<...>` wrapper to the inner result type text. */
49
+ function unwrapReturn(text) {
50
+ if (!text) return "void"
51
+ const m = text.match(new RegExp(`^${RETURN_WRAPPER}<([\\s\\S]*)>$`))
52
+ return (m ? m[1] : text).trim()
53
+ }
54
+
55
+ /**
56
+ * Statically walk the abstract `PluginApi` class tree and return one flat,
57
+ * sorted manifest entry per leaf method. Pure (no side effects) so it is unit
58
+ * testable; the CLI below adds the write + report.
59
+ */
60
+ export function buildManifest({ includeOptional = false } = {}) {
61
+ const project = new Project({ skipAddingFilesFromTsConfig: true })
62
+ project.addSourceFilesAtPaths(apiGlob)
63
+
64
+ // className -> ClassDeclaration, for every abstract Plugin*Api class.
65
+ const classes = new Map()
66
+ for (const sf of project.getSourceFiles()) {
67
+ for (const cls of sf.getClasses()) {
68
+ const name = cls.getName()
69
+ if (name && name.startsWith("Plugin") && name.endsWith("Api")) {
70
+ classes.set(name, cls)
71
+ }
72
+ }
73
+ }
74
+
75
+ const leaves = []
76
+
77
+ function walk(className, pathPrefix) {
78
+ const cls = classes.get(className)
79
+ if (!cls) return
80
+
81
+ // Leaf methods on this namespace.
82
+ for (const method of cls.getMethods()) {
83
+ const name = method.getName()
84
+ const jsDoc = method.getJsDocs().at(-1) ?? null
85
+ const param = method.getParameters()[0]
86
+ leaves.push({
87
+ path: `${pathPrefix}${name}`,
88
+ namespace: pathPrefix.replace(/\.$/, ""),
89
+ summary: summaryOf(jsDoc),
90
+ examplePrompts: examplePromptsOf(jsDoc),
91
+ argsType: param?.getTypeNode()?.getText() ?? null,
92
+ resultType: unwrapReturn(method.getReturnTypeNode()?.getText()),
93
+ })
94
+ }
95
+
96
+ // Sub-namespaces are abstract properties typed as another Plugin*Api class.
97
+ //
98
+ // Author-ahead discipline: a member declared optional (`?`) is authored
99
+ // BEFORE the host implements it — present in the type tree (so plugins and
100
+ // codegen see the shape) but kept OUT of the discovery manifest until it is
101
+ // promoted to a required `abstract` member in the wave the host lands it.
102
+ // The default (discovery) build skips optional members; the authored-surface
103
+ // build (`includeOptional`, used by the retrieval eval) includes them — both
104
+ // the optional sub-namespaces and the optional function-property leaves.
105
+ for (const prop of cls.getProperties()) {
106
+ const optional = prop.hasQuestionToken()
107
+ if (optional && !includeOptional) continue
108
+ const typeNode = prop.getTypeNode()
109
+ const childType = typeNode?.getText()
110
+ if (childType && classes.has(childType)) {
111
+ walk(childType, `${pathPrefix}${prop.getName()}.`)
112
+ } else if (
113
+ includeOptional &&
114
+ typeNode &&
115
+ typeNode.getKindName() === "FunctionType"
116
+ ) {
117
+ // An optional author-ahead leaf, written as a function-property.
118
+ const jsDoc = prop.getJsDocs().at(-1) ?? null
119
+ const param = typeNode.getParameters()[0]
120
+ leaves.push({
121
+ path: `${pathPrefix}${prop.getName()}`,
122
+ namespace: pathPrefix.replace(/\.$/, ""),
123
+ summary: summaryOf(jsDoc),
124
+ examplePrompts: examplePromptsOf(jsDoc),
125
+ argsType: param?.getTypeNode()?.getText() ?? null,
126
+ resultType: unwrapReturn(typeNode.getReturnTypeNode()?.getText()),
127
+ })
128
+ }
129
+ }
130
+ }
131
+
132
+ walk(ROOT_CLASS, "")
133
+ leaves.sort((a, b) => a.path.localeCompare(b.path))
134
+ return leaves
135
+ }
136
+
137
+ // --- CLI: write + report (skipped when imported, e.g. by tests) ------------
138
+ if (
139
+ process.argv[1] &&
140
+ resolve(process.argv[1]) === fileURLToPath(import.meta.url)
141
+ ) {
142
+ // `--all` builds the AUTHORED-surface manifest (includes optional author-ahead
143
+ // members) to a separate file, for the retrieval eval. Default builds the
144
+ // discovery manifest (required/host-landed members only).
145
+ const all = process.argv.includes("--all")
146
+ const check = process.argv.includes("--check")
147
+ const target = all ? resolve(pkgRoot, "api-manifest.full.json") : outFile
148
+ const leaves = buildManifest({ includeOptional: all })
149
+ const json = JSON.stringify(leaves, null, 2) + "\n"
150
+
151
+ if (check) {
152
+ // Determinism / staleness gate: regenerate and compare, never write.
153
+ const current = existsSync(target) ? readFileSync(target, "utf8") : ""
154
+ if (current !== json) {
155
+ console.error(
156
+ `${target} is STALE or non-deterministic — run \`generate:manifest${all ? " --all" : ""}\` and commit the result.`,
157
+ )
158
+ process.exit(1)
159
+ }
160
+ console.log(
161
+ `manifest up-to-date & deterministic (${leaves.length} methods)`,
162
+ )
163
+ process.exit(0)
164
+ }
165
+
166
+ writeFileSync(target, json)
167
+
168
+ const missingPrompts = leaves.filter((l) => l.examplePrompts.length === 0)
169
+ console.log(
170
+ `manifest${all ? " (authored surface)" : ""}: ${leaves.length} methods -> ${target}`,
171
+ )
172
+ console.log(
173
+ `coverage: ${leaves.length - missingPrompts.length}/${leaves.length} methods have @examplePrompt lines`,
174
+ )
175
+ if (missingPrompts.length) {
176
+ console.log(
177
+ ` (no @examplePrompt yet: ${missingPrompts.map((l) => l.path).join(", ")})`,
178
+ )
179
+ }
180
+ const slice = [
181
+ "program.departments.list",
182
+ "program.departments.get",
183
+ "program.metrics.get",
184
+ "presentation.views.list",
185
+ ]
186
+ console.log("slice methods present:")
187
+ for (const p of slice) {
188
+ const hit = leaves.find((l) => l.path === p)
189
+ console.log(
190
+ ` ${hit ? "OK " : "MISS"} ${p}${hit ? ` (${hit.examplePrompts.length} prompts)` : ""}`,
191
+ )
192
+ }
193
+ }
@@ -0,0 +1,193 @@
1
+ // Unit tests for the discovery-manifest generator (pure codegen logic).
2
+ // Run: `node --test scripts/generate-manifest.test.mjs` (from packages/plugin-core)
3
+ import { test } from "node:test"
4
+ import assert from "node:assert/strict"
5
+ import { buildManifest } from "./generate-manifest.mjs"
6
+
7
+ const manifest = buildManifest()
8
+ const byPath = new Map(manifest.map((m) => [m.path, m]))
9
+
10
+ test("every entry has a dotted path and a namespace", () => {
11
+ for (const m of manifest) {
12
+ assert.match(m.path, /^[a-z][a-zA-Z0-9.]*$/, `bad path: ${m.path}`)
13
+ assert.equal(typeof m.namespace, "string")
14
+ assert.ok(
15
+ Array.isArray(m.examplePrompts),
16
+ `${m.path} examplePrompts not array`,
17
+ )
18
+ }
19
+ })
20
+
21
+ test("output is sorted and unique by path", () => {
22
+ const paths = manifest.map((m) => m.path)
23
+ assert.deepEqual(
24
+ paths,
25
+ [...paths].sort((a, b) => a.localeCompare(b)),
26
+ "not sorted",
27
+ )
28
+ assert.equal(new Set(paths).size, paths.length, "duplicate paths")
29
+ })
30
+
31
+ test("all 4 Phase-1 slice methods are present with intent + prompts", () => {
32
+ const slice = [
33
+ "program.departments.list",
34
+ "program.departments.get",
35
+ "program.metrics.get",
36
+ "presentation.views.list",
37
+ ]
38
+ for (const p of slice) {
39
+ const m = byPath.get(p)
40
+ assert.ok(m, `missing slice method: ${p}`)
41
+ assert.ok(m.summary.length > 0, `${p} has no intent summary`)
42
+ assert.ok(m.examplePrompts.length >= 3, `${p} has < 3 example prompts`)
43
+ assert.ok(
44
+ m.resultType && m.resultType !== "void",
45
+ `${p} has no result type`,
46
+ )
47
+ }
48
+ })
49
+
50
+ test("departments.get carries its args type; list takes no args", () => {
51
+ assert.equal(
52
+ byPath.get("program.departments.get").argsType,
53
+ "PluginProgramDepartmentsGetArgs",
54
+ )
55
+ assert.equal(byPath.get("program.departments.list").argsType, null)
56
+ })
57
+
58
+ test("return-type wrapper PluginApiReturn<...> is unwrapped", () => {
59
+ for (const m of manifest) {
60
+ assert.ok(
61
+ !/^PluginApiReturn</.test(m.resultType ?? ""),
62
+ `${m.path} not unwrapped`,
63
+ )
64
+ }
65
+ })
66
+
67
+ test("author-ahead (optional) members are kept OUT of the manifest", () => {
68
+ // Optional sub-namespaces (`aiInspiration?`) and optional leaf methods
69
+ // (`departments.delete?`, `cores.create?`) are authored ahead of the host and
70
+ // must not appear in the discovery manifest until promoted to required
71
+ // `abstract` members. (See the discipline note in generate-manifest.mjs.)
72
+ const authoredAhead = [
73
+ "presentation.aiInspiration.listModels",
74
+ "program.departments.delete",
75
+ "program.cores.create",
76
+ ]
77
+ for (const p of authoredAhead) {
78
+ assert.ok(
79
+ !byPath.has(p),
80
+ `optional author-ahead member leaked into manifest: ${p}`,
81
+ )
82
+ }
83
+ })
84
+
85
+ test("promoted methods are present in the manifest", () => {
86
+ // Methods whose react host bodies have landed and been verified, flipped from
87
+ // optional author-ahead to required `abstract`.
88
+ const promoted = [
89
+ "program.departments.create",
90
+ "program.departments.setTargetArea",
91
+ "program.site.get",
92
+ "program.site.getContext",
93
+ "presentation.import.image",
94
+ "presentation.import.pdf",
95
+ "presentation.sheets.list",
96
+ "presentation.sheets.place",
97
+ "presentation.diagrams.place",
98
+ // 2026-07-02 promotions — react hosts landed and verified:
99
+ "program.spreadsheet.render",
100
+ "program.adjacency.getMatrix",
101
+ "program.adjacency.compute",
102
+ "program.spreadsheet.getTakeoff",
103
+ "program.spreadsheet.runScript",
104
+ "presentation.views.get",
105
+ "presentation.views.getActive",
106
+ "presentation.views.capture",
107
+ "presentation.views.setActive",
108
+ "presentation.views.create",
109
+ "core.layers.setActive",
110
+ "core.layers.update",
111
+ "program.areas.update",
112
+ ]
113
+ for (const p of promoted) {
114
+ assert.ok(
115
+ byPath.has(p),
116
+ `expected promoted method missing from manifest: ${p}`,
117
+ )
118
+ }
119
+ })
120
+
121
+ test("v2 family reads (all 5 families) are present with intent + prompts", () => {
122
+ // All 22 reads of the five landed families. Every sub-api mount is now required
123
+ // `abstract` (the react hosts have landed), so each read is in the discovery
124
+ // manifest with a summary, >= 3 example prompts, and a result type.
125
+ const reads = [
126
+ "core.groups.list",
127
+ "core.groups.get",
128
+ "core.groups.getForComponent",
129
+ "core.groups.listMembers",
130
+ "core.groups.isLocked",
131
+ "core.groups.getBounds",
132
+ "core.buildings.list",
133
+ "core.buildings.get",
134
+ "core.buildings.listStoreys",
135
+ "core.buildings.getActive",
136
+ "core.layers.list",
137
+ "core.layers.get",
138
+ "core.layers.getActive",
139
+ "core.tags.listCategories",
140
+ "core.tags.getCategory",
141
+ "core.tags.list",
142
+ "core.tags.get",
143
+ "core.tags.getTagsForComponent",
144
+ "core.tags.listComponents",
145
+ "program.areas.get",
146
+ "program.areas.list",
147
+ "program.areas.listMembers",
148
+ ]
149
+ for (const p of reads) {
150
+ const m = byPath.get(p)
151
+ assert.ok(m, `missing v2 family read: ${p}`)
152
+ assert.ok(m.summary.length > 0, `${p} has no intent summary`)
153
+ assert.ok(m.examplePrompts.length >= 3, `${p} has < 3 example prompts`)
154
+ assert.ok(
155
+ m.resultType && m.resultType !== "void",
156
+ `${p} has no result type`,
157
+ )
158
+ }
159
+ })
160
+
161
+ test("v2 family writes are IN the discovery manifest (hosts landed, promoted)", () => {
162
+ // 2026-07-02: every v2 family write's react host body has landed, so the
163
+ // contract members were promoted from optional `foo?: (args) => ...`
164
+ // fn-properties to required `abstract` methods — they now appear in the
165
+ // discovery build.
166
+ const promotedWrites = [
167
+ "core.groups.create",
168
+ "core.groups.update",
169
+ "core.groups.delete",
170
+ "core.buildings.setActive",
171
+ "core.buildings.create",
172
+ "core.buildings.update",
173
+ "core.buildings.copy",
174
+ "core.buildings.delete",
175
+ "core.layers.setActive",
176
+ "core.layers.update",
177
+ "core.tags.createCategory",
178
+ "core.tags.updateCategory",
179
+ "core.tags.deleteCategory",
180
+ "core.tags.create",
181
+ "core.tags.update",
182
+ "core.tags.delete",
183
+ "core.tags.assign",
184
+ "core.tags.unassign",
185
+ "program.areas.update",
186
+ ]
187
+ for (const p of promotedWrites) {
188
+ assert.ok(
189
+ byPath.has(p),
190
+ `promoted v2 family write missing from manifest: ${p}`,
191
+ )
192
+ }
193
+ })