aigpu 0.3.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.
Files changed (491) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +85 -0
  3. package/bin/aigpu.js +15 -0
  4. package/client.d.ts +15 -0
  5. package/dist/agent-tools.d.ts +61 -0
  6. package/dist/agent-tools.d.ts.map +1 -0
  7. package/dist/agent-tools.js +107 -0
  8. package/dist/agent-tools.js.map +1 -0
  9. package/dist/agent.d.ts +56 -0
  10. package/dist/agent.d.ts.map +1 -0
  11. package/dist/agent.js +243 -0
  12. package/dist/agent.js.map +1 -0
  13. package/dist/api-types.d.ts +56 -0
  14. package/dist/api-types.d.ts.map +1 -0
  15. package/dist/api-types.js +2 -0
  16. package/dist/api-types.js.map +1 -0
  17. package/dist/bind-cache.d.ts +19 -0
  18. package/dist/bind-cache.d.ts.map +1 -0
  19. package/dist/bind-cache.js +43 -0
  20. package/dist/bind-cache.js.map +1 -0
  21. package/dist/bundle.d.ts +30 -0
  22. package/dist/bundle.d.ts.map +1 -0
  23. package/dist/bundle.js +127 -0
  24. package/dist/bundle.js.map +1 -0
  25. package/dist/claim-validation-encode.d.ts +14 -0
  26. package/dist/claim-validation-encode.d.ts.map +1 -0
  27. package/dist/claim-validation-encode.js +28 -0
  28. package/dist/claim-validation-encode.js.map +1 -0
  29. package/dist/claim-validation.d.ts +73 -0
  30. package/dist/claim-validation.d.ts.map +1 -0
  31. package/dist/claim-validation.js +135 -0
  32. package/dist/claim-validation.js.map +1 -0
  33. package/dist/cli/bin/aigpu.js +101 -0
  34. package/dist/cli/lib/check/run.js +153 -0
  35. package/dist/cli/lib/docs/commands/cat.js +12 -0
  36. package/dist/cli/lib/docs/commands/find.js +180 -0
  37. package/dist/cli/lib/docs/commands/grep.js +49 -0
  38. package/dist/cli/lib/docs/commands/ls.js +41 -0
  39. package/dist/cli/lib/docs/commands/path.js +12 -0
  40. package/dist/cli/lib/docs/commands/resolve.js +41 -0
  41. package/dist/cli/lib/docs/commands/shared.js +13 -0
  42. package/dist/cli/lib/docs/commands/symbols.js +25 -0
  43. package/dist/cli/lib/docs/errors.js +8 -0
  44. package/dist/cli/lib/docs/generate/check-drift.js +61 -0
  45. package/dist/cli/lib/docs/generate/cli.js +12 -0
  46. package/dist/cli/lib/docs/generate/generate.js +113 -0
  47. package/dist/cli/lib/docs/generate/manifest.js +218 -0
  48. package/dist/cli/lib/docs/generate/skill.js +150 -0
  49. package/dist/cli/lib/docs/help.js +21 -0
  50. package/dist/cli/lib/docs/index.js +62 -0
  51. package/dist/cli/lib/docs/model.js +7 -0
  52. package/dist/cli/lib/docs/run.js +24 -0
  53. package/dist/cli/lib/docs/service.js +119 -0
  54. package/dist/cli/lib/doctor/run.js +236 -0
  55. package/dist/cli/lib/examples/errors.js +13 -0
  56. package/dist/cli/lib/examples/hashing.js +9 -0
  57. package/dist/cli/lib/examples/help.js +13 -0
  58. package/dist/cli/lib/examples/local-source.js +142 -0
  59. package/dist/cli/lib/examples/paths.js +12 -0
  60. package/dist/cli/lib/examples/pull.js +58 -0
  61. package/dist/cli/lib/examples/run.js +71 -0
  62. package/dist/cli/lib/examples/search.js +6 -0
  63. package/dist/cli/lib/examples/service.js +118 -0
  64. package/dist/cli/lib/generated/docs-manifest.generated.js +4758 -0
  65. package/dist/cli/lib/install-dawn/run.js +24 -0
  66. package/dist/cli/lib/install-software-renderer/run.js +17 -0
  67. package/dist/cli/lib/mcp/http.js +93 -0
  68. package/dist/cli/lib/mcp/server.js +258 -0
  69. package/dist/cli/lib/mcp/stdio.js +34 -0
  70. package/dist/cli/lib/snapshot/png.js +62 -0
  71. package/dist/cli/lib/snapshot/render.js +22 -0
  72. package/dist/cli/lib/snapshot/run.js +79 -0
  73. package/dist/cli/lib/snapshot/shaders.js +11 -0
  74. package/dist/cli/package.json +4 -0
  75. package/dist/client.d.ts +12 -0
  76. package/dist/client.d.ts.map +1 -0
  77. package/dist/client.js +2 -0
  78. package/dist/client.js.map +1 -0
  79. package/dist/clock.d.ts +26 -0
  80. package/dist/clock.d.ts.map +1 -0
  81. package/dist/clock.js +50 -0
  82. package/dist/clock.js.map +1 -0
  83. package/dist/compute.d.ts +41 -0
  84. package/dist/compute.d.ts.map +1 -0
  85. package/dist/compute.js +132 -0
  86. package/dist/compute.js.map +1 -0
  87. package/dist/core/render-bundle.d.ts +30 -0
  88. package/dist/core/render-bundle.d.ts.map +1 -0
  89. package/dist/core/render-bundle.js +39 -0
  90. package/dist/core/render-bundle.js.map +1 -0
  91. package/dist/core/storage-buffer.d.ts +81 -0
  92. package/dist/core/storage-buffer.d.ts.map +1 -0
  93. package/dist/core/storage-buffer.js +91 -0
  94. package/dist/core/storage-buffer.js.map +1 -0
  95. package/dist/core/structured-uniform.d.ts +33 -0
  96. package/dist/core/structured-uniform.d.ts.map +1 -0
  97. package/dist/core/structured-uniform.js +110 -0
  98. package/dist/core/structured-uniform.js.map +1 -0
  99. package/dist/core/uniform-pool-internals.d.ts +12 -0
  100. package/dist/core/uniform-pool-internals.d.ts.map +1 -0
  101. package/dist/core/uniform-pool-internals.js +24 -0
  102. package/dist/core/uniform-pool-internals.js.map +1 -0
  103. package/dist/core/uniform-pool-types.d.ts +22 -0
  104. package/dist/core/uniform-pool-types.d.ts.map +1 -0
  105. package/dist/core/uniform-pool-types.js +2 -0
  106. package/dist/core/uniform-pool-types.js.map +1 -0
  107. package/dist/core/uniform-pool.d.ts +22 -0
  108. package/dist/core/uniform-pool.d.ts.map +1 -0
  109. package/dist/core/uniform-pool.js +128 -0
  110. package/dist/core/uniform-pool.js.map +1 -0
  111. package/dist/core/uniform.d.ts +55 -0
  112. package/dist/core/uniform.d.ts.map +1 -0
  113. package/dist/core/uniform.js +64 -0
  114. package/dist/core/uniform.js.map +1 -0
  115. package/dist/core/wgsl-alignment.d.ts +24 -0
  116. package/dist/core/wgsl-alignment.d.ts.map +1 -0
  117. package/dist/core/wgsl-alignment.js +81 -0
  118. package/dist/core/wgsl-alignment.js.map +1 -0
  119. package/dist/core.d.ts +13 -0
  120. package/dist/core.d.ts.map +1 -0
  121. package/dist/core.js +7 -0
  122. package/dist/core.js.map +1 -0
  123. package/dist/dom.d.ts +37 -0
  124. package/dist/dom.d.ts.map +1 -0
  125. package/dist/dom.js +81 -0
  126. package/dist/dom.js.map +1 -0
  127. package/dist/draw-protocols.d.ts +36 -0
  128. package/dist/draw-protocols.d.ts.map +1 -0
  129. package/dist/draw-protocols.js +10 -0
  130. package/dist/draw-protocols.js.map +1 -0
  131. package/dist/draw.d.ts +248 -0
  132. package/dist/draw.d.ts.map +1 -0
  133. package/dist/draw.js +890 -0
  134. package/dist/draw.js.map +1 -0
  135. package/dist/effect.d.ts +53 -0
  136. package/dist/effect.d.ts.map +1 -0
  137. package/dist/effect.js +75 -0
  138. package/dist/effect.js.map +1 -0
  139. package/dist/entry-metadata.d.ts +16 -0
  140. package/dist/entry-metadata.d.ts.map +1 -0
  141. package/dist/entry-metadata.js +27 -0
  142. package/dist/entry-metadata.js.map +1 -0
  143. package/dist/errors.d.ts +96 -0
  144. package/dist/errors.d.ts.map +1 -0
  145. package/dist/errors.js +616 -0
  146. package/dist/errors.js.map +1 -0
  147. package/dist/frame-protocols.d.ts +107 -0
  148. package/dist/frame-protocols.d.ts.map +1 -0
  149. package/dist/frame-protocols.js +20 -0
  150. package/dist/frame-protocols.js.map +1 -0
  151. package/dist/frame-state.d.ts +32 -0
  152. package/dist/frame-state.d.ts.map +1 -0
  153. package/dist/frame-state.js +62 -0
  154. package/dist/frame-state.js.map +1 -0
  155. package/dist/frame.d.ts +127 -0
  156. package/dist/frame.d.ts.map +1 -0
  157. package/dist/frame.js +645 -0
  158. package/dist/frame.js.map +1 -0
  159. package/dist/group-claim.d.ts +9 -0
  160. package/dist/group-claim.d.ts.map +1 -0
  161. package/dist/group-claim.js +7 -0
  162. package/dist/group-claim.js.map +1 -0
  163. package/dist/index.d.ts +41 -0
  164. package/dist/index.d.ts.map +1 -0
  165. package/dist/index.js +27 -0
  166. package/dist/index.js.map +1 -0
  167. package/dist/indirect.d.ts +39 -0
  168. package/dist/indirect.d.ts.map +1 -0
  169. package/dist/indirect.js +61 -0
  170. package/dist/indirect.js.map +1 -0
  171. package/dist/init-from-device.d.ts +11 -0
  172. package/dist/init-from-device.d.ts.map +1 -0
  173. package/dist/init-from-device.js +56 -0
  174. package/dist/init-from-device.js.map +1 -0
  175. package/dist/init.d.ts +12 -0
  176. package/dist/init.d.ts.map +1 -0
  177. package/dist/init.js +7 -0
  178. package/dist/init.js.map +1 -0
  179. package/dist/kernel.d.ts +104 -0
  180. package/dist/kernel.d.ts.map +1 -0
  181. package/dist/kernel.js +151 -0
  182. package/dist/kernel.js.map +1 -0
  183. package/dist/lifecycle.d.ts +10 -0
  184. package/dist/lifecycle.d.ts.map +1 -0
  185. package/dist/lifecycle.js +21 -0
  186. package/dist/lifecycle.js.map +1 -0
  187. package/dist/live-kernel.d.ts +48 -0
  188. package/dist/live-kernel.d.ts.map +1 -0
  189. package/dist/live-kernel.js +67 -0
  190. package/dist/live-kernel.js.map +1 -0
  191. package/dist/mock.d.ts +42 -0
  192. package/dist/mock.d.ts.map +1 -0
  193. package/dist/mock.js +29 -0
  194. package/dist/mock.js.map +1 -0
  195. package/dist/node.d.ts +48 -0
  196. package/dist/node.d.ts.map +1 -0
  197. package/dist/node.js +36 -0
  198. package/dist/node.js.map +1 -0
  199. package/dist/ping-pong.d.ts +19 -0
  200. package/dist/ping-pong.d.ts.map +1 -0
  201. package/dist/ping-pong.js +67 -0
  202. package/dist/ping-pong.js.map +1 -0
  203. package/dist/pipeline-store.d.ts +89 -0
  204. package/dist/pipeline-store.d.ts.map +1 -0
  205. package/dist/pipeline-store.js +366 -0
  206. package/dist/pipeline-store.js.map +1 -0
  207. package/dist/query-ring.d.ts +91 -0
  208. package/dist/query-ring.d.ts.map +1 -0
  209. package/dist/query-ring.js +178 -0
  210. package/dist/query-ring.js.map +1 -0
  211. package/dist/render-service.d.ts +23 -0
  212. package/dist/render-service.d.ts.map +1 -0
  213. package/dist/render-service.js +37 -0
  214. package/dist/render-service.js.map +1 -0
  215. package/dist/sampler.d.ts +19 -0
  216. package/dist/sampler.d.ts.map +1 -0
  217. package/dist/sampler.js +46 -0
  218. package/dist/sampler.js.map +1 -0
  219. package/dist/scene/camera.d.ts +91 -0
  220. package/dist/scene/camera.d.ts.map +1 -0
  221. package/dist/scene/camera.js +221 -0
  222. package/dist/scene/camera.js.map +1 -0
  223. package/dist/scene/geometries.d.ts +26 -0
  224. package/dist/scene/geometries.d.ts.map +1 -0
  225. package/dist/scene/geometries.js +26 -0
  226. package/dist/scene/geometries.js.map +1 -0
  227. package/dist/scene/geometry-descriptor.d.ts +120 -0
  228. package/dist/scene/geometry-descriptor.d.ts.map +1 -0
  229. package/dist/scene/geometry-descriptor.js +378 -0
  230. package/dist/scene/geometry-descriptor.js.map +1 -0
  231. package/dist/scene/geometry-recipe.d.ts +41 -0
  232. package/dist/scene/geometry-recipe.d.ts.map +1 -0
  233. package/dist/scene/geometry-recipe.js +40 -0
  234. package/dist/scene/geometry-recipe.js.map +1 -0
  235. package/dist/scene/geometry-src/camera-math.d.ts +6 -0
  236. package/dist/scene/geometry-src/camera-math.d.ts.map +1 -0
  237. package/dist/scene/geometry-src/camera-math.js +47 -0
  238. package/dist/scene/geometry-src/camera-math.js.map +1 -0
  239. package/dist/scene/geometry-src/camera.d.ts +10 -0
  240. package/dist/scene/geometry-src/camera.d.ts.map +1 -0
  241. package/dist/scene/geometry-src/camera.js +2 -0
  242. package/dist/scene/geometry-src/camera.js.map +1 -0
  243. package/dist/scene/geometry-src/capsule-data.d.ts +10 -0
  244. package/dist/scene/geometry-src/capsule-data.d.ts.map +1 -0
  245. package/dist/scene/geometry-src/capsule-data.js +61 -0
  246. package/dist/scene/geometry-src/capsule-data.js.map +1 -0
  247. package/dist/scene/geometry-src/cone-data.d.ts +13 -0
  248. package/dist/scene/geometry-src/cone-data.d.ts.map +1 -0
  249. package/dist/scene/geometry-src/cone-data.js +52 -0
  250. package/dist/scene/geometry-src/cone-data.js.map +1 -0
  251. package/dist/scene/geometry-src/cylinder-data.d.ts +14 -0
  252. package/dist/scene/geometry-src/cylinder-data.d.ts.map +1 -0
  253. package/dist/scene/geometry-src/cylinder-data.js +58 -0
  254. package/dist/scene/geometry-src/cylinder-data.js.map +1 -0
  255. package/dist/scene/geometry-src/deg-to-rad.d.ts +2 -0
  256. package/dist/scene/geometry-src/deg-to-rad.d.ts.map +1 -0
  257. package/dist/scene/geometry-src/deg-to-rad.js +4 -0
  258. package/dist/scene/geometry-src/deg-to-rad.js.map +1 -0
  259. package/dist/scene/geometry-src/disk-data.d.ts +12 -0
  260. package/dist/scene/geometry-src/disk-data.d.ts.map +1 -0
  261. package/dist/scene/geometry-src/disk-data.js +21 -0
  262. package/dist/scene/geometry-src/disk-data.js.map +1 -0
  263. package/dist/scene/geometry-src/errors.d.ts +3 -0
  264. package/dist/scene/geometry-src/errors.d.ts.map +1 -0
  265. package/dist/scene/geometry-src/errors.js +5 -0
  266. package/dist/scene/geometry-src/errors.js.map +1 -0
  267. package/dist/scene/geometry-src/icosphere-data.d.ts +8 -0
  268. package/dist/scene/geometry-src/icosphere-data.d.ts.map +1 -0
  269. package/dist/scene/geometry-src/icosphere-data.js +58 -0
  270. package/dist/scene/geometry-src/icosphere-data.js.map +1 -0
  271. package/dist/scene/geometry-src/index.d.ts +36 -0
  272. package/dist/scene/geometry-src/index.d.ts.map +1 -0
  273. package/dist/scene/geometry-src/index.js +21 -0
  274. package/dist/scene/geometry-src/index.js.map +1 -0
  275. package/dist/scene/geometry-src/mesh-box.d.ts +8 -0
  276. package/dist/scene/geometry-src/mesh-box.d.ts.map +1 -0
  277. package/dist/scene/geometry-src/mesh-box.js +57 -0
  278. package/dist/scene/geometry-src/mesh-box.js.map +1 -0
  279. package/dist/scene/geometry-src/mesh-cache.d.ts +4 -0
  280. package/dist/scene/geometry-src/mesh-cache.d.ts.map +1 -0
  281. package/dist/scene/geometry-src/mesh-cache.js +14 -0
  282. package/dist/scene/geometry-src/mesh-cache.js.map +1 -0
  283. package/dist/scene/geometry-src/mesh-capsule.d.ts +14 -0
  284. package/dist/scene/geometry-src/mesh-capsule.d.ts.map +1 -0
  285. package/dist/scene/geometry-src/mesh-capsule.js +52 -0
  286. package/dist/scene/geometry-src/mesh-capsule.js.map +1 -0
  287. package/dist/scene/geometry-src/mesh-cone.d.ts +16 -0
  288. package/dist/scene/geometry-src/mesh-cone.d.ts.map +1 -0
  289. package/dist/scene/geometry-src/mesh-cone.js +54 -0
  290. package/dist/scene/geometry-src/mesh-cone.js.map +1 -0
  291. package/dist/scene/geometry-src/mesh-cylinder.d.ts +18 -0
  292. package/dist/scene/geometry-src/mesh-cylinder.d.ts.map +1 -0
  293. package/dist/scene/geometry-src/mesh-cylinder.js +67 -0
  294. package/dist/scene/geometry-src/mesh-cylinder.js.map +1 -0
  295. package/dist/scene/geometry-src/mesh-disk.d.ts +11 -0
  296. package/dist/scene/geometry-src/mesh-disk.d.ts.map +1 -0
  297. package/dist/scene/geometry-src/mesh-disk.js +45 -0
  298. package/dist/scene/geometry-src/mesh-disk.js.map +1 -0
  299. package/dist/scene/geometry-src/mesh-dodecahedron.d.ts +4 -0
  300. package/dist/scene/geometry-src/mesh-dodecahedron.d.ts.map +1 -0
  301. package/dist/scene/geometry-src/mesh-dodecahedron.js +10 -0
  302. package/dist/scene/geometry-src/mesh-dodecahedron.js.map +1 -0
  303. package/dist/scene/geometry-src/mesh-fullscreen-quad.d.ts +7 -0
  304. package/dist/scene/geometry-src/mesh-fullscreen-quad.d.ts.map +1 -0
  305. package/dist/scene/geometry-src/mesh-fullscreen-quad.js +39 -0
  306. package/dist/scene/geometry-src/mesh-fullscreen-quad.js.map +1 -0
  307. package/dist/scene/geometry-src/mesh-icosahedron.d.ts +4 -0
  308. package/dist/scene/geometry-src/mesh-icosahedron.d.ts.map +1 -0
  309. package/dist/scene/geometry-src/mesh-icosahedron.js +10 -0
  310. package/dist/scene/geometry-src/mesh-icosahedron.js.map +1 -0
  311. package/dist/scene/geometry-src/mesh-icosphere.d.ts +11 -0
  312. package/dist/scene/geometry-src/mesh-icosphere.d.ts.map +1 -0
  313. package/dist/scene/geometry-src/mesh-icosphere.js +47 -0
  314. package/dist/scene/geometry-src/mesh-icosphere.js.map +1 -0
  315. package/dist/scene/geometry-src/mesh-octahedron.d.ts +4 -0
  316. package/dist/scene/geometry-src/mesh-octahedron.d.ts.map +1 -0
  317. package/dist/scene/geometry-src/mesh-octahedron.js +10 -0
  318. package/dist/scene/geometry-src/mesh-octahedron.js.map +1 -0
  319. package/dist/scene/geometry-src/mesh-plane.d.ts +13 -0
  320. package/dist/scene/geometry-src/mesh-plane.d.ts.map +1 -0
  321. package/dist/scene/geometry-src/mesh-plane.js +51 -0
  322. package/dist/scene/geometry-src/mesh-plane.js.map +1 -0
  323. package/dist/scene/geometry-src/mesh-ring.d.ts +12 -0
  324. package/dist/scene/geometry-src/mesh-ring.d.ts.map +1 -0
  325. package/dist/scene/geometry-src/mesh-ring.js +47 -0
  326. package/dist/scene/geometry-src/mesh-ring.js.map +1 -0
  327. package/dist/scene/geometry-src/mesh-sphere.d.ts +10 -0
  328. package/dist/scene/geometry-src/mesh-sphere.d.ts.map +1 -0
  329. package/dist/scene/geometry-src/mesh-sphere.js +51 -0
  330. package/dist/scene/geometry-src/mesh-sphere.js.map +1 -0
  331. package/dist/scene/geometry-src/mesh-tetrahedron.d.ts +5 -0
  332. package/dist/scene/geometry-src/mesh-tetrahedron.d.ts.map +1 -0
  333. package/dist/scene/geometry-src/mesh-tetrahedron.js +10 -0
  334. package/dist/scene/geometry-src/mesh-tetrahedron.js.map +1 -0
  335. package/dist/scene/geometry-src/mesh-torus.d.ts +17 -0
  336. package/dist/scene/geometry-src/mesh-torus.d.ts.map +1 -0
  337. package/dist/scene/geometry-src/mesh-torus.js +56 -0
  338. package/dist/scene/geometry-src/mesh-torus.js.map +1 -0
  339. package/dist/scene/geometry-src/mesh-types.d.ts +38 -0
  340. package/dist/scene/geometry-src/mesh-types.d.ts.map +1 -0
  341. package/dist/scene/geometry-src/mesh-types.js +2 -0
  342. package/dist/scene/geometry-src/mesh-types.js.map +1 -0
  343. package/dist/scene/geometry-src/mesh.d.ts +61 -0
  344. package/dist/scene/geometry-src/mesh.d.ts.map +1 -0
  345. package/dist/scene/geometry-src/mesh.js +49 -0
  346. package/dist/scene/geometry-src/mesh.js.map +1 -0
  347. package/dist/scene/geometry-src/orthographic-camera.d.ts +14 -0
  348. package/dist/scene/geometry-src/orthographic-camera.d.ts.map +1 -0
  349. package/dist/scene/geometry-src/orthographic-camera.js +9 -0
  350. package/dist/scene/geometry-src/orthographic-camera.js.map +1 -0
  351. package/dist/scene/geometry-src/perspective-camera.d.ts +12 -0
  352. package/dist/scene/geometry-src/perspective-camera.d.ts.map +1 -0
  353. package/dist/scene/geometry-src/perspective-camera.js +9 -0
  354. package/dist/scene/geometry-src/perspective-camera.js.map +1 -0
  355. package/dist/scene/geometry-src/plane-data.d.ts +12 -0
  356. package/dist/scene/geometry-src/plane-data.d.ts.map +1 -0
  357. package/dist/scene/geometry-src/plane-data.js +25 -0
  358. package/dist/scene/geometry-src/plane-data.js.map +1 -0
  359. package/dist/scene/geometry-src/polyhedron-data.d.ts +7 -0
  360. package/dist/scene/geometry-src/polyhedron-data.d.ts.map +1 -0
  361. package/dist/scene/geometry-src/polyhedron-data.js +42 -0
  362. package/dist/scene/geometry-src/polyhedron-data.js.map +1 -0
  363. package/dist/scene/geometry-src/polyhedron-mesh.d.ts +10 -0
  364. package/dist/scene/geometry-src/polyhedron-mesh.d.ts.map +1 -0
  365. package/dist/scene/geometry-src/polyhedron-mesh.js +37 -0
  366. package/dist/scene/geometry-src/polyhedron-mesh.js.map +1 -0
  367. package/dist/scene/geometry-src/polyhedron-seeds.d.ts +6 -0
  368. package/dist/scene/geometry-src/polyhedron-seeds.d.ts.map +1 -0
  369. package/dist/scene/geometry-src/polyhedron-seeds.js +51 -0
  370. package/dist/scene/geometry-src/polyhedron-seeds.js.map +1 -0
  371. package/dist/scene/geometry-src/primitive-data-utils.d.ts +9 -0
  372. package/dist/scene/geometry-src/primitive-data-utils.d.ts.map +1 -0
  373. package/dist/scene/geometry-src/primitive-data-utils.js +36 -0
  374. package/dist/scene/geometry-src/primitive-data-utils.js.map +1 -0
  375. package/dist/scene/geometry-src/ring-data.d.ts +13 -0
  376. package/dist/scene/geometry-src/ring-data.d.ts.map +1 -0
  377. package/dist/scene/geometry-src/ring-data.js +24 -0
  378. package/dist/scene/geometry-src/ring-data.js.map +1 -0
  379. package/dist/scene/geometry-src/sphere-data.d.ts +11 -0
  380. package/dist/scene/geometry-src/sphere-data.d.ts.map +1 -0
  381. package/dist/scene/geometry-src/sphere-data.js +31 -0
  382. package/dist/scene/geometry-src/sphere-data.js.map +1 -0
  383. package/dist/scene/geometry-src/srgb.d.ts +5 -0
  384. package/dist/scene/geometry-src/srgb.d.ts.map +1 -0
  385. package/dist/scene/geometry-src/srgb.js +23 -0
  386. package/dist/scene/geometry-src/srgb.js.map +1 -0
  387. package/dist/scene/geometry-src/torus-data.d.ts +11 -0
  388. package/dist/scene/geometry-src/torus-data.d.ts.map +1 -0
  389. package/dist/scene/geometry-src/torus-data.js +38 -0
  390. package/dist/scene/geometry-src/torus-data.js.map +1 -0
  391. package/dist/scene/geometry-src/vertex-layout.d.ts +2 -0
  392. package/dist/scene/geometry-src/vertex-layout.d.ts.map +1 -0
  393. package/dist/scene/geometry-src/vertex-layout.js +2 -0
  394. package/dist/scene/geometry-src/vertex-layout.js.map +1 -0
  395. package/dist/scene/geometry.d.ts +70 -0
  396. package/dist/scene/geometry.d.ts.map +1 -0
  397. package/dist/scene/geometry.js +71 -0
  398. package/dist/scene/geometry.js.map +1 -0
  399. package/dist/scene/orbit.d.ts +9 -0
  400. package/dist/scene/orbit.d.ts.map +1 -0
  401. package/dist/scene/orbit.js +15 -0
  402. package/dist/scene/orbit.js.map +1 -0
  403. package/dist/scene/tree/errors.d.ts +4 -0
  404. package/dist/scene/tree/errors.d.ts.map +1 -0
  405. package/dist/scene/tree/errors.js +19 -0
  406. package/dist/scene/tree/errors.js.map +1 -0
  407. package/dist/scene/tree/light.d.ts +42 -0
  408. package/dist/scene/tree/light.d.ts.map +1 -0
  409. package/dist/scene/tree/light.js +102 -0
  410. package/dist/scene/tree/light.js.map +1 -0
  411. package/dist/scene/tree/material.d.ts +79 -0
  412. package/dist/scene/tree/material.d.ts.map +1 -0
  413. package/dist/scene/tree/material.js +117 -0
  414. package/dist/scene/tree/material.js.map +1 -0
  415. package/dist/scene/tree/math.d.ts +26 -0
  416. package/dist/scene/tree/math.d.ts.map +1 -0
  417. package/dist/scene/tree/math.js +217 -0
  418. package/dist/scene/tree/math.js.map +1 -0
  419. package/dist/scene/tree/mesh-node.d.ts +17 -0
  420. package/dist/scene/tree/mesh-node.d.ts.map +1 -0
  421. package/dist/scene/tree/mesh-node.js +24 -0
  422. package/dist/scene/tree/mesh-node.js.map +1 -0
  423. package/dist/scene/tree/node.d.ts +70 -0
  424. package/dist/scene/tree/node.d.ts.map +1 -0
  425. package/dist/scene/tree/node.js +220 -0
  426. package/dist/scene/tree/node.js.map +1 -0
  427. package/dist/scene/tree/orbit-controls.d.ts +69 -0
  428. package/dist/scene/tree/orbit-controls.d.ts.map +1 -0
  429. package/dist/scene/tree/orbit-controls.js +226 -0
  430. package/dist/scene/tree/orbit-controls.js.map +1 -0
  431. package/dist/scene.d.ts +21 -0
  432. package/dist/scene.d.ts.map +1 -0
  433. package/dist/scene.js +11 -0
  434. package/dist/scene.js.map +1 -0
  435. package/dist/set-core.d.ts +50 -0
  436. package/dist/set-core.d.ts.map +1 -0
  437. package/dist/set-core.js +268 -0
  438. package/dist/set-core.js.map +1 -0
  439. package/dist/set-layouts.d.ts +20 -0
  440. package/dist/set-layouts.d.ts.map +1 -0
  441. package/dist/set-layouts.js +103 -0
  442. package/dist/set-layouts.js.map +1 -0
  443. package/dist/set-packing.d.ts +4 -0
  444. package/dist/set-packing.d.ts.map +1 -0
  445. package/dist/set-packing.js +82 -0
  446. package/dist/set-packing.js.map +1 -0
  447. package/dist/set-resources.d.ts +20 -0
  448. package/dist/set-resources.d.ts.map +1 -0
  449. package/dist/set-resources.js +140 -0
  450. package/dist/set-resources.js.map +1 -0
  451. package/dist/shader-source.d.ts +4 -0
  452. package/dist/shader-source.d.ts.map +1 -0
  453. package/dist/shader-source.js +21 -0
  454. package/dist/shader-source.js.map +1 -0
  455. package/dist/storage.d.ts +38 -0
  456. package/dist/storage.d.ts.map +1 -0
  457. package/dist/storage.js +76 -0
  458. package/dist/storage.js.map +1 -0
  459. package/dist/surface.d.ts +89 -0
  460. package/dist/surface.d.ts.map +1 -0
  461. package/dist/surface.js +243 -0
  462. package/dist/surface.js.map +1 -0
  463. package/dist/target-offscreen.d.ts +41 -0
  464. package/dist/target-offscreen.d.ts.map +1 -0
  465. package/dist/target-offscreen.js +115 -0
  466. package/dist/target-offscreen.js.map +1 -0
  467. package/dist/target-utils.d.ts +37 -0
  468. package/dist/target-utils.d.ts.map +1 -0
  469. package/dist/target-utils.js +103 -0
  470. package/dist/target-utils.js.map +1 -0
  471. package/dist/target.d.ts +65 -0
  472. package/dist/target.d.ts.map +1 -0
  473. package/dist/target.js +2 -0
  474. package/dist/target.js.map +1 -0
  475. package/dist/timer.d.ts +78 -0
  476. package/dist/timer.d.ts.map +1 -0
  477. package/dist/timer.js +261 -0
  478. package/dist/timer.js.map +1 -0
  479. package/dist/uniforms-layout.d.ts +8 -0
  480. package/dist/uniforms-layout.d.ts.map +1 -0
  481. package/dist/uniforms-layout.js +84 -0
  482. package/dist/uniforms-layout.js.map +1 -0
  483. package/dist/uniforms.d.ts +43 -0
  484. package/dist/uniforms.d.ts.map +1 -0
  485. package/dist/uniforms.js +176 -0
  486. package/dist/uniforms.js.map +1 -0
  487. package/dist/visibility.d.ts +118 -0
  488. package/dist/visibility.d.ts.map +1 -0
  489. package/dist/visibility.js +290 -0
  490. package/dist/visibility.js.map +1 -0
  491. package/package.json +131 -0
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync, realpathSync } from "node:fs";
3
+ import { dirname, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { runCheck } from "../lib/check/run.js";
6
+ import { runDocs } from "../lib/docs/run.js";
7
+ import { runDoctor } from "../lib/doctor/run.js";
8
+ import { runInstallDawn } from "../lib/install-dawn/run.js";
9
+ import { runInstallSoftwareRenderer } from "../lib/install-software-renderer/run.js";
10
+ import { runSnapshotCommand } from "../lib/snapshot/run.js";
11
+ import { runExamples } from "../lib/examples/run.js";
12
+
13
+ const here = dirname(fileURLToPath(import.meta.url));
14
+ const packageJson = JSON.parse(readFileSync(resolve(here, "../package.json"), "utf8"));
15
+
16
+ // In-repo, `../package.json` is packages/aigpu-cli/package.json (`@aigpu/cli`): private, never published,
17
+ // versioned independently of the public `aigpu` package and known to drift from it (see
18
+ // CONTRIBUTING.md). Reporting that version made every in-repo `aigpu examples ...` call fail the
19
+ // server handshake with AIGPU-EXAMPLES-CLI-TOO-OLD, so resolve the public version from the sibling
20
+ // `aigpu-api` package instead -- same try/catch-degrade pattern as computeStamp() in
21
+ // lib/docs/generate/generate.js.
22
+ //
23
+ // In the published tarball, `../package.json` is the synthetic `{type,version}` stamp written by
24
+ // packages/aigpu-api/scripts/copy-cli.mjs, which has no `name` field, so this branch is dead code
25
+ // there and the published version keeps coming from the stamp (guarded by a unit test).
26
+ export function resolveVersion(dir, pkg) {
27
+ if (pkg.name === "@aigpu/cli") {
28
+ try {
29
+ const apiPackageJson = JSON.parse(readFileSync(resolve(dir, "../../aigpu-api/package.json"), "utf8"));
30
+ return apiPackageJson.version;
31
+ } catch {
32
+ // Incomplete checkout (sparse clone, deleted sibling): degrade to our own version, never crash.
33
+ return pkg.version;
34
+ }
35
+ }
36
+ return pkg.version;
37
+ }
38
+
39
+ const VERSION = resolveVersion(here, packageJson);
40
+
41
+ const help = `aigpu ${VERSION}
42
+
43
+ TypeScript library for WebGPU: typed shader imports, a tiny gpu-first API, and
44
+ the same code running in the browser, headless Node, and your test suite.
45
+
46
+ ## Read the docs
47
+ npx aigpu docs cat getting-started.md The guide for using the current API correctly
48
+ npx aigpu docs find "<topic | symbol | AIGPU-error-code>"
49
+ npx aigpu docs cat <path>
50
+
51
+ ## Validate shader code
52
+ npx aigpu check <file.wgsl> Validate and reflect a WGSL file as JSON
53
+ npx aigpu check <file.wgsl> --require-validation
54
+ Fail instead of skipping when no WebGPU device is available
55
+
56
+ ## Working examples
57
+ npx aigpu examples search "<topic>"
58
+ npx aigpu examples pull <slug> --out <dir>
59
+
60
+ ## Agent tools (MCP)
61
+ npx aigpu mcp Serve docs and examples over stdio
62
+
63
+ ## Node rendering environment
64
+ npx aigpu doctor
65
+ `;
66
+
67
+ const comingSoon = (command) => `aigpu ${command} is coming soon.
68
+
69
+ This package currently ships docs lookup first. Use aigpu, aigpu/node, aigpu/mock,
70
+ aigpu/scene, and the documented slim tooling subpaths. Run \`aigpu --help\` for details.
71
+ `;
72
+
73
+ export function runCli(args) {
74
+ const [command, ...rest] = args;
75
+ if (command === undefined || command === "--help" || command === "-h") return { code: 0, stdout: help };
76
+ if (command === "--version" || command === "-v") return { code: 0, stdout: `${VERSION}\n` };
77
+ if (command === "check") return runCheck(rest);
78
+ if (command === "docs") return runDocs(rest);
79
+ if (command === "examples") return runExamples(rest, { version: VERSION });
80
+ if (command === "mcp") {
81
+ return import("../lib/mcp/stdio.js").then(({ runMcpStdio }) => runMcpStdio(rest, { version: VERSION }));
82
+ }
83
+ if (command === "snapshot") return runSnapshotCommand({ args: rest });
84
+ if (command === "install-dawn") return runInstallDawn(rest);
85
+ if (command === "install-software-renderer") return runInstallSoftwareRenderer(rest);
86
+ if (command === "doctor") return runDoctor(rest);
87
+ if (command === "wgsl") return { code: 1, stderr: comingSoon(command) };
88
+ return { code: 2, stderr: `Unknown command: ${command}\n\n${help}` };
89
+ }
90
+
91
+ if (isMain()) {
92
+ const result = await Promise.resolve(runCli(process.argv.slice(2)));
93
+ if (result.stdout) process.stdout.write(result.stdout);
94
+ if (result.stderr) process.stderr.write(result.stderr);
95
+ process.exitCode = result.code;
96
+ }
97
+
98
+ function isMain() {
99
+ if (!process.argv[1]) return false;
100
+ return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
101
+ }
@@ -0,0 +1,153 @@
1
+ import { existsSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+
4
+ /**
5
+ * Runs WGSL reflection/validation for a single entry module and dumps JSON.
6
+ */
7
+ export async function runCheck(args) {
8
+ const requireValidation = args.includes("--require-validation");
9
+ const [entry] = args.filter((arg) => arg !== "--require-validation");
10
+ if (!entry || entry === "--help" || entry === "-h") {
11
+ return { code: 1, stderr: "Usage: aigpu check <file.wgsl> [--require-validation]\n" };
12
+ }
13
+
14
+ const absEntry = resolveEntry(entry);
15
+ try {
16
+ const { resolveShader } = await loadWgslRuntime();
17
+ const options = { entry: absEntry, rootDir: dirname(absEntry) };
18
+ let result;
19
+ let validationError;
20
+ try {
21
+ // Without the flag no `validate` option is passed at all, so the process-wide default
22
+ // ("auto", or AIGPU_VALIDATE when set) applies untouched.
23
+ result = await resolveShader({ ...options, ...(requireValidation ? { validate: "require" } : {}) });
24
+ } catch (error) {
25
+ if (!isValidationFailure(error)) throw error;
26
+ // A failing device check must not cost the caller the whole document: re-resolve with
27
+ // validation off so `check` still prints diagnostics + reflection + wgsl, and report the
28
+ // failure inside `validation` instead. Keeps the JSON contract identical whether or not the
29
+ // machine running `check` happens to have a WebGPU device. Exit code stays 1.
30
+ validationError = error;
31
+ try {
32
+ result = await resolveShader({ ...options, validate: "off" });
33
+ } catch {
34
+ // The retry failed for some unrelated reason; the validation failure is the useful one.
35
+ throw error;
36
+ }
37
+ }
38
+ const diagnostics = (result.diagnostics ?? []).map(serializeDiagnostic);
39
+ const payload = {
40
+ schemaVersion: 1,
41
+ entry: absEntry,
42
+ deps: result.deps,
43
+ diagnostics,
44
+ validation: validationError ? failedValidation(requireValidation, validationError) : result.validation,
45
+ reflection: result.reflection,
46
+ wgsl: result.wgsl,
47
+ };
48
+ const failed = Boolean(validationError) || diagnostics.some((diagnostic) => diagnostic.severity === "error");
49
+ return { code: failed ? 1 : 0, stdout: `${JSON.stringify(payload, null, 2)}\n` };
50
+ } catch (error) {
51
+ return { code: 1, stderr: `${formatError(error)}\n` };
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Failures raised *by validation* — an invalid shader, or (in `"require"` mode) a device that could
57
+ * not be acquired. Everything else (resolution, reserved paths, an invalid `AIGPU_VALIDATE`) is a
58
+ * hard error: re-resolving with validation off would hide it rather than describe it.
59
+ */
60
+ const validationFailureCodes = new Set(["AIGPU-WGSL-NAGA-UNKNOWN", "AIGPU-WGSL-VALIDATE-NO-DEVICE", "AIGPU-WGSL-VALIDATE-ADAPTER-MISSING"]);
61
+
62
+ function isValidationFailure(error) {
63
+ return Boolean(error && typeof error === "object" && validationFailureCodes.has(error.code));
64
+ }
65
+
66
+ function failedValidation(requireValidation, error) {
67
+ // `--require-validation` always wins over AIGPU_VALIDATE, matching resolveShader's precedence.
68
+ const mode = requireValidation ? "require" : process.env.AIGPU_VALIDATE || "auto";
69
+ return { mode, attempted: true, ok: false, error: serializeDiagnostic(error) };
70
+ }
71
+
72
+ /**
73
+ * Resolves package-filter invocations back to the workspace root when possible.
74
+ * Outside a pnpm workspace this intentionally falls back to cwd-relative paths.
75
+ */
76
+ function resolveEntry(entry) {
77
+ const fromCwd = resolve(process.cwd(), entry);
78
+ if (existsSync(fromCwd)) return fromCwd;
79
+ const workspaceRoot = findWorkspaceRoot(process.cwd());
80
+ if (!workspaceRoot) return fromCwd;
81
+ const fromWorkspace = resolve(workspaceRoot, entry);
82
+ return existsSync(fromWorkspace) ? fromWorkspace : fromCwd;
83
+ }
84
+
85
+ async function loadWgslRuntime() {
86
+ try {
87
+ return await import("@aigpu/wgsl/runtime");
88
+ } catch (error) {
89
+ if (isMissingWgslRuntime(error)) {
90
+ throw new Error("`aigpu check` requires @aigpu/wgsl to be installed. Install it next to @aigpu/cli, for example: pnpm add -D @aigpu/wgsl");
91
+ }
92
+ throw error;
93
+ }
94
+ }
95
+
96
+ function isMissingWgslRuntime(error) {
97
+ return Boolean(
98
+ error &&
99
+ typeof error === "object" &&
100
+ error.code === "ERR_MODULE_NOT_FOUND" &&
101
+ String(error.message ?? "").includes("@aigpu/wgsl"),
102
+ );
103
+ }
104
+
105
+ function findWorkspaceRoot(startDir) {
106
+ for (let dir = startDir;; dir = dirname(dir)) {
107
+ if (existsSync(resolve(dir, "pnpm-workspace.yaml"))) return dir;
108
+ if (dirname(dir) === dir) return undefined;
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Diagnostics are `Error` instances, whose `message` is not enumerable and would
114
+ * otherwise vanish from the JSON payload.
115
+ */
116
+ function serializeDiagnostic(diagnostic) {
117
+ if (!diagnostic || typeof diagnostic !== "object") return diagnostic;
118
+ const payload = {
119
+ code: diagnostic.code ?? "AIGPU-CHECK-UNKNOWN",
120
+ message: diagnostic.message ?? String(diagnostic),
121
+ severity: diagnostic.severity ?? "error",
122
+ line: diagnostic.line ?? null,
123
+ column: diagnostic.column ?? null,
124
+ };
125
+ if (diagnostic.range) payload.range = diagnostic.range;
126
+ if (diagnostic.metadata) payload.metadata = diagnostic.metadata;
127
+ if (diagnostic.relatedDiagnostics) payload.relatedDiagnostics = diagnostic.relatedDiagnostics;
128
+ if (diagnostic.fix) payload.fix = diagnostic.fix;
129
+ if (diagnostic.where) payload.where = diagnostic.where;
130
+ return payload;
131
+ }
132
+
133
+ function formatError(error) {
134
+ if (error && typeof error === "object") {
135
+ const payload = {
136
+ code: error.code ?? "AIGPU-CHECK-UNKNOWN",
137
+ message: error.message ?? String(error),
138
+ severity: error.severity ?? "error",
139
+ line: error.line ?? null,
140
+ column: error.column ?? null,
141
+ metadata: error.metadata,
142
+ relatedDiagnostics: error.relatedDiagnostics,
143
+ };
144
+ if (error.range) payload.range = error.range;
145
+ if (error.fix) payload.fix = error.fix;
146
+ if (error.where) payload.where = error.where;
147
+ if (error.stack && process.env.AIGPU_CHECK_STACK === "1") {
148
+ payload.stack = error.stack;
149
+ }
150
+ return JSON.stringify(payload, null, 2);
151
+ }
152
+ return String(error ?? "Unknown error");
153
+ }
@@ -0,0 +1,12 @@
1
+ import { resolveDocsTarget } from "./resolve.js";
2
+ import { ambiguous, fail, ok } from "./shared.js";
3
+
4
+ export function catCommand(index, args) {
5
+ if (args.includes("--help") || args.includes("-h")) return ok("Usage: aigpu docs cat <path|symbol>");
6
+ if (args.length !== 1) return fail("Usage: aigpu docs cat <path|symbol>");
7
+ const target = args[0];
8
+ const { resolved, lookup } = resolveDocsTarget(index, target);
9
+ if (!resolved) return fail(`${lookup === "path" ? "Path" : "Symbol"} not found: ${target}`);
10
+ if (Array.isArray(resolved)) return ambiguous(target, resolved);
11
+ return ok(resolved.content.trimEnd());
12
+ }
@@ -0,0 +1,180 @@
1
+ import { packageRank, uniqueByPath } from "../index.js";
2
+ import { fail, ok } from "./shared.js";
3
+
4
+ // Agents type prose, not identifiers: the dogfood experiment searched "wgsl import", "typescript
5
+ // wgsl", "modern bundlers", "declare module". A single-substring match over symbol+path answered none of
6
+ // them, so find works in three widening steps: every whitespace token must match (1) the route
7
+ // text — symbol, title and the doc's declared keywords, (2) the doc paths, and only when both come
8
+ // back empty (3) the doc body, which is what makes error codes and prose phrases findable.
9
+ //
10
+ // Both tiers share one cap: "gpu" is a substring of "aigpu", so route text matched 134 lines and
11
+ // buried the exact `Gpu` match around line 100. Ranking by match quality is what makes the cap
12
+ // safe — capping alphabetical output would truncate the exact match away entirely.
13
+ const HIT_LIMIT = 20;
14
+
15
+ export function findCommand(index, args) {
16
+ if (args.includes("--help") || args.includes("-h")) return ok("Usage: aigpu docs find <query>");
17
+ if (args.length !== 1) return fail("Usage: aigpu docs find <query>");
18
+ const found = findDocs(index, args[0]);
19
+ if (found.results.length === 0) return fail(`No docs found for: ${args[0]}`);
20
+ return ok(withNotice(found.results.map(formatFindResult), found.hiddenCount));
21
+ }
22
+
23
+ export function findDocs(index, query) {
24
+ const tokens = query.toLowerCase().split(/\s+/u).filter(Boolean);
25
+ if (tokens.length === 0) return { results: [], truncated: false, hiddenCount: 0 };
26
+ const phrase = tokens.join(" ");
27
+
28
+ const matchesAll = (haystack) => tokens.every((token) => haystack.includes(token));
29
+ const symbolHits = index.records
30
+ .filter((record) => matchesAll(symbolText(record)))
31
+ .map((record) => ({
32
+ type: "symbol",
33
+ record,
34
+ line: `${record.symbol}\t${record.package}\t${record.virtualPath}`,
35
+ }));
36
+ const pathHits = uniqueByPath(index.records)
37
+ .filter((record) => matchesAll(pathText(record)))
38
+ .map((record) => ({ type: "path", record, line: pathLine(record) }));
39
+
40
+ // Dedupe by line text, first hit wins — the same uniqueness the previous `new Set([...])` gave.
41
+ const routeHitMap = new Map();
42
+ for (const hit of [...symbolHits, ...pathHits]) if (!routeHitMap.has(hit.line)) routeHitMap.set(hit.line, hit);
43
+
44
+ // INVARIANT (do not move this check): the routing gate is evaluated on the full, UNRANKED,
45
+ // UNCAPPED, UNFILTERED hit set. Ranking and capping happen only inside this branch and never
46
+ // remove a hit from consideration, they only reorder it or hide it behind the truncation notice.
47
+ // If ranking ever filtered hits, a query whose only hits were dropped would silently fall
48
+ // through to the body-search fallback (#258) — a routing-policy change, not a ranking fix.
49
+ if (routeHitMap.size > 0) {
50
+ const hits = [...routeHitMap.values()];
51
+ const ranked = rankRouteHits(hits, tokens, phrase);
52
+ const hiddenCount = Math.max(hits.length - HIT_LIMIT, 0);
53
+ return {
54
+ results: ranked.slice(0, HIT_LIMIT).map(resultFromHit),
55
+ truncated: hiddenCount > 0,
56
+ hiddenCount,
57
+ };
58
+ }
59
+
60
+ const contentHits = uniqueByPath(index.records)
61
+ .filter((record) => matchesAll(record.content.toLowerCase()))
62
+ .map((record) => ({ type: "path", record, line: pathLine(record) }))
63
+ .sort((left, right) => compareBytes(left.line, right.line));
64
+ const hiddenCount = Math.max(contentHits.length - HIT_LIMIT, 0);
65
+ return {
66
+ results: contentHits.slice(0, HIT_LIMIT).map(resultFromHit),
67
+ truncated: hiddenCount > 0,
68
+ hiddenCount,
69
+ };
70
+ }
71
+
72
+ function symbolText(record) {
73
+ return `${record.symbol}\n${record.topicTitle ?? ""}\n${keywordText(record)}`.toLowerCase();
74
+ }
75
+
76
+ function pathText(record) {
77
+ return `${record.virtualPath}\n${record.repoPath}\n${keywordText(record)}`.toLowerCase();
78
+ }
79
+
80
+ function keywordText(record) {
81
+ return (record.keywords ?? []).join("\n");
82
+ }
83
+
84
+ function pathLine(record) {
85
+ return `${record.virtualPath}\t${record.repoPath}`;
86
+ }
87
+
88
+ function resultFromHit(hit) {
89
+ if (hit.type === "symbol") {
90
+ return {
91
+ kind: "symbol",
92
+ symbol: hit.record.symbol,
93
+ package: hit.record.package,
94
+ virtualPath: hit.record.virtualPath,
95
+ };
96
+ }
97
+ return { kind: "path", virtualPath: hit.record.virtualPath, repoPath: hit.record.repoPath };
98
+ }
99
+
100
+ function formatFindResult(result) {
101
+ return result.kind === "symbol"
102
+ ? `${result.symbol}\t${result.package}\t${result.virtualPath}`
103
+ : `${result.virtualPath}\t${result.repoPath}`;
104
+ }
105
+
106
+ // Order (never filter) the route hits so the best match is the line an agent reads first. Ties break
107
+ // on the shared package curation ladder, then page lines before their symbol lines, then a
108
+ // byte-stable line compare — never localeCompare, whose ICU tables make output Node-build dependent.
109
+ function rankRouteHits(hits, tokens, phrase) {
110
+ return hits
111
+ .map((hit) => ({ ...hit, tier: tierOf(hit, tokens, phrase) }))
112
+ .sort((left, right) =>
113
+ left.tier - right.tier ||
114
+ packageRank(left.record.package) - packageRank(right.record.package) ||
115
+ typeOrder(left) - typeOrder(right) ||
116
+ compareBytes(left.line, right.line));
117
+ }
118
+
119
+ function typeOrder(hit) {
120
+ return hit.type === "path" ? 0 : 1;
121
+ }
122
+
123
+ function compareBytes(left, right) {
124
+ return left < right ? -1 : left > right ? 1 : 0;
125
+ }
126
+
127
+ // Tiers 1-6 from the design: exact symbol, exact page identity, word-boundary in name text,
128
+ // word-boundary in path, substring in name text, substring in path only. Tiers 5/6 need no
129
+ // substring re-check: a symbol hit only exists because it passed matchesAll(symbolText(record)),
130
+ // and a path hit only because it passed matchesAll(pathText(record)).
131
+ function tierOf(hit, tokens, phrase) {
132
+ if (hit.type === "symbol" && hit.record.symbol.toLowerCase() === phrase) return 1;
133
+ if (isExactPageIdentity(hit.record, phrase)) return 2;
134
+ if (everyTokenWordMatches(tokens, nameWords(hit.record))) return 3;
135
+ if (everyTokenWordMatches(tokens, pathWords(hit.record))) return 4;
136
+ return hit.type === "symbol" ? 5 : 6;
137
+ }
138
+
139
+ function isExactPageIdentity(record, phrase) {
140
+ if ((record.keywords ?? []).some((keyword) => keyword.toLowerCase() === phrase)) return true;
141
+ if ((record.topicTitle ?? "").toLowerCase() === phrase) return true;
142
+ if ((record.topic ?? "").toLowerCase() === phrase) return true;
143
+ return pageBasename(record.virtualPath) === phrase;
144
+ }
145
+
146
+ function pageBasename(virtualPath) {
147
+ const segment = (virtualPath ?? "").split("/").pop() ?? "";
148
+ return segment.replace(/\.docs\.md$/u, "").toLowerCase();
149
+ }
150
+
151
+ // "whole word or word-prefix" is one startsWith check: a word trivially starts with itself.
152
+ function everyTokenWordMatches(tokens, words) {
153
+ return tokens.every((token) => words.some((word) => word.startsWith(token)));
154
+ }
155
+
156
+ function nameWords(record) {
157
+ return words(`${record.symbol} ${record.topicTitle ?? ""} ${(record.keywords ?? []).join(" ")}`);
158
+ }
159
+
160
+ function pathWords(record) {
161
+ return words(`${record.virtualPath} ${record.repoPath}`);
162
+ }
163
+
164
+ // Split on non-alphanumerics, then on camelCase boundaries, so "WebGPU" yields ["web", "gpu"] and
165
+ // "createNodeAdapter" yields ["create", "node", "adapter"].
166
+ function words(text) {
167
+ return (text ?? "")
168
+ .split(/[^a-zA-Z0-9]+/u)
169
+ .filter(Boolean)
170
+ .flatMap((chunk) => chunk.match(/[A-Z]+(?=[A-Z][a-z])|[A-Z]?[a-z]+|[A-Z]+|[0-9]+/gu) ?? [chunk])
171
+ .map((word) => word.toLowerCase());
172
+ }
173
+
174
+ // Truncation is never silent: an agent must be able to tell 20-of-20 from 20-of-200. Stdout, exit 0,
175
+ // and deliberately free of tabs so the notice can never be parsed as one of the result lines.
176
+ function withNotice(lines, hiddenCount) {
177
+ if (hiddenCount <= 0) return lines;
178
+ const plural = hiddenCount === 1 ? "" : "es";
179
+ return [...lines, `... and ${hiddenCount} more match${plural}; showing the ${HIT_LIMIT} best. Add another word to narrow.`];
180
+ }
@@ -0,0 +1,49 @@
1
+ import { uniqueByPath } from "../index.js";
2
+ import { fail, ok } from "./shared.js";
3
+
4
+ export function grepCommand(index, args) {
5
+ if (args.includes("--help") || args.includes("-h")) return ok("Usage: aigpu docs grep [-i] [--package <pkg>] <pattern>");
6
+ const parsed = parseArgs(args);
7
+ if (typeof parsed === "string") return fail(parsed);
8
+ const matches = grepDocs(index, parsed);
9
+ return matches.length > 0 ? ok(matches.map(formatGrepMatch)) : fail(`No matches for: ${parsed.pattern}`);
10
+ }
11
+
12
+ export function grepDocs(index, { pattern, ignoreCase = false, packageName }) {
13
+ const needle = ignoreCase ? pattern.toLowerCase() : pattern;
14
+ const matches = [];
15
+ for (const record of uniqueByPath(index.records)) {
16
+ if (packageName && !matchesPackage(record.package, packageName)) continue;
17
+ record.content.split("\n").forEach((line, lineIndex) => {
18
+ const haystack = ignoreCase ? line.toLowerCase() : line;
19
+ if (haystack.includes(needle)) matches.push({ virtualPath: record.virtualPath, line: lineIndex + 1, text: line });
20
+ });
21
+ }
22
+ return matches.sort((left, right) => compareBytes(formatGrepMatch(left), formatGrepMatch(right)));
23
+ }
24
+
25
+ function formatGrepMatch(match) {
26
+ return `${match.virtualPath}:${match.line}:${match.text}`;
27
+ }
28
+
29
+ function compareBytes(left, right) {
30
+ return left < right ? -1 : left > right ? 1 : 0;
31
+ }
32
+
33
+ function parseArgs(args) {
34
+ let ignoreCase = false;
35
+ let packageName;
36
+ const rest = [];
37
+ for (let index = 0; index < args.length; index += 1) {
38
+ if (args[index] === "-i") ignoreCase = true;
39
+ else if (args[index] === "--package") packageName = args[++index];
40
+ else rest.push(args[index]);
41
+ }
42
+ if (args.includes("--package") && !packageName) return "Missing value for --package";
43
+ if (rest.length !== 1) return "Usage: aigpu docs grep [-i] [--package <pkg>] <pattern>";
44
+ return { ignoreCase, packageName, pattern: rest[0] };
45
+ }
46
+
47
+ function matchesPackage(recordPackage, filter) {
48
+ return recordPackage === filter || recordPackage.startsWith(`${filter}/`);
49
+ }
@@ -0,0 +1,41 @@
1
+ import { normalizePath } from "../index.js";
2
+ import { fail, ok } from "./shared.js";
3
+
4
+ const ROOT_TIP = "Tip: start with \"aigpu docs cat getting-started.md\"; /guides holds concept guides; @aigpu/render/* is low-level tooling.";
5
+
6
+ export function lsCommand(index, args) {
7
+ if (args.includes("--help") || args.includes("-h")) return ok("Usage: aigpu docs ls [path]");
8
+ if (args.length > 1) return fail("Usage: aigpu docs ls [path]");
9
+ const path = normalizePath(args[0] ?? "/");
10
+ const entries = listDocs(index, path);
11
+ if (!entries) return fail(`Path not found: ${path}`);
12
+ return ok(path === "/" ? [...entries, ROOT_TIP] : entries);
13
+ }
14
+
15
+ export function listDocs(index, path = "/") {
16
+ path = normalizePath(path);
17
+ if (path === "/") return index.packages.map((pkg) => `/${pkg}`);
18
+ if (path === "/guides") {
19
+ const guides = index.records.filter((record) => record.kind === "guide").sort(compareGuide);
20
+ return guides.map((record) => record.virtualPath.slice(path.length + 1));
21
+ }
22
+
23
+ const children = new Set();
24
+ for (const record of index.records) {
25
+ if (record.virtualPath === path) return [record.virtualPath];
26
+ if (!record.virtualPath.startsWith(`${path}/`)) continue;
27
+ const rest = record.virtualPath.slice(path.length + 1);
28
+ children.add(rest.includes("/") ? rest.slice(0, rest.indexOf("/")) : rest);
29
+ }
30
+ return children.size > 0 ? [...children].sort() : undefined;
31
+ }
32
+
33
+ function compareGuide(left, right) {
34
+ if (left.symbol === "getting-started") return -1;
35
+ if (right.symbol === "getting-started") return 1;
36
+ const leftOrdered = typeof left.order === "number";
37
+ const rightOrdered = typeof right.order === "number";
38
+ if (leftOrdered && rightOrdered) return left.order - right.order || left.virtualPath.localeCompare(right.virtualPath);
39
+ if (leftOrdered !== rightOrdered) return leftOrdered ? -1 : 1;
40
+ return left.virtualPath.localeCompare(right.virtualPath);
41
+ }
@@ -0,0 +1,12 @@
1
+ import { resolveDocsTarget } from "./resolve.js";
2
+ import { ambiguous, fail, ok } from "./shared.js";
3
+
4
+ export function pathCommand(index, args) {
5
+ if (args.includes("--help") || args.includes("-h")) return ok("Usage: aigpu docs path <symbol|path>");
6
+ if (args.length !== 1) return fail("Usage: aigpu docs path <symbol|path>");
7
+ const target = args[0];
8
+ const { resolved, lookup } = resolveDocsTarget(index, target);
9
+ if (!resolved) return fail(`${lookup === "path" ? "Path" : "Symbol"} not found: ${target}`);
10
+ if (Array.isArray(resolved)) return ambiguous(target, resolved);
11
+ return ok(resolved.virtualPath);
12
+ }
@@ -0,0 +1,41 @@
1
+ import { resolvePath, resolveSymbol } from "../index.js";
2
+
3
+ export function resolveDocsTarget(index, target) {
4
+ for (const path of candidatePaths(target)) {
5
+ const record = resolvePath(index, path)[0];
6
+ if (record) return { resolved: record };
7
+ }
8
+
9
+ for (const symbol of candidateSymbols(target)) {
10
+ const resolved = resolveSymbol(index, symbol);
11
+ if (resolved) return { resolved };
12
+ }
13
+
14
+ return { resolved: undefined, lookup: target.startsWith("/") || target.startsWith("guides/") ? "path" : "symbol" };
15
+ }
16
+
17
+ function candidatePaths(target) {
18
+ const paths = [];
19
+ if (target.startsWith("/")) paths.push(target);
20
+ if (target.startsWith("guides/")) paths.push(`/${target}`);
21
+
22
+ for (const path of [...paths]) {
23
+ if (path.startsWith("/guides/") && path.endsWith(".md") && !path.endsWith(".docs.md")) {
24
+ paths.push(path.replace(/\.md$/u, ".docs.md"));
25
+ }
26
+ }
27
+
28
+ return unique(paths);
29
+ }
30
+
31
+ function candidateSymbols(target) {
32
+ const symbols = [target];
33
+ const file = target.split("/").at(-1) ?? target;
34
+ if (file.endsWith(".docs.md")) symbols.push(file.slice(0, -".docs.md".length));
35
+ if (file.endsWith(".md")) symbols.push(file.slice(0, -".md".length));
36
+ return unique(symbols);
37
+ }
38
+
39
+ function unique(values) {
40
+ return [...new Set(values)];
41
+ }
@@ -0,0 +1,13 @@
1
+ export function ok(lines = "") {
2
+ const stdout = Array.isArray(lines) ? lines.join("\n") : lines;
3
+ return { code: 0, stdout: stdout.length > 0 ? `${stdout}\n` : "" };
4
+ }
5
+
6
+ export function fail(message) {
7
+ return { code: 1, stderr: `${message}\n` };
8
+ }
9
+
10
+ export function ambiguous(symbol, records) {
11
+ const candidates = records.map((record) => `${record.symbol}\t${record.package}\t${record.virtualPath}`);
12
+ return fail(`Ambiguous symbol: ${symbol}\nCandidates:\n${candidates.join("\n")}`);
13
+ }
@@ -0,0 +1,25 @@
1
+ import { ok } from "./shared.js";
2
+
3
+ export function symbolsCommand(index, args) {
4
+ if (args.includes("--help") || args.includes("-h")) return ok("Usage: aigpu docs symbols");
5
+ if (args.length !== 0) return { code: 1, stderr: "Usage: aigpu docs symbols\n" };
6
+ return ok(listDocSymbols(index).map(formatSymbol));
7
+ }
8
+
9
+ export function listDocSymbols(index) {
10
+ const symbols = new Map();
11
+ for (const record of index.records) {
12
+ const symbol = { symbol: record.symbol, package: record.package, virtualPath: record.virtualPath };
13
+ const line = formatSymbol(symbol);
14
+ if (!symbols.has(line)) symbols.set(line, symbol);
15
+ }
16
+ return [...symbols.values()].sort((left, right) => compareBytes(formatSymbol(left), formatSymbol(right)));
17
+ }
18
+
19
+ function formatSymbol(symbol) {
20
+ return `${symbol.symbol}\t${symbol.package}\t${symbol.virtualPath}`;
21
+ }
22
+
23
+ function compareBytes(left, right) {
24
+ return left < right ? -1 : left > right ? 1 : 0;
25
+ }
@@ -0,0 +1,8 @@
1
+ export class DocsError extends Error {
2
+ constructor(code, message, details = {}) {
3
+ super(message);
4
+ this.name = "DocsError";
5
+ this.code = code;
6
+ Object.assign(this, details);
7
+ }
8
+ }