agentscape3d-engine 0.0.0-stage → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (396) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/cli.mjs +53 -0
  4. package/dist/AssetCompiler-A99wKf7H.js +2424 -0
  5. package/dist/AssetCompiler-A99wKf7H.js.map +1 -0
  6. package/dist/AssetInputContracts-uKYeQu-X.js +245 -0
  7. package/dist/AssetInputContracts-uKYeQu-X.js.map +1 -0
  8. package/dist/AssetRecipe-DCaLLXvG.js +67 -0
  9. package/dist/AssetRecipe-DCaLLXvG.js.map +1 -0
  10. package/dist/BrowserCodeWorker.js +53850 -0
  11. package/dist/BrowserCodeWorker.js.map +1 -0
  12. package/dist/KinematicHypothesisScreen-4v7GBwdv.js +241 -0
  13. package/dist/KinematicHypothesisScreen-4v7GBwdv.js.map +1 -0
  14. package/dist/SceneSerializer-CLCzQjL_.js +350 -0
  15. package/dist/SceneSerializer-CLCzQjL_.js.map +1 -0
  16. package/dist/StylePack-CD_BC-Mv.js +6317 -0
  17. package/dist/StylePack-CD_BC-Mv.js.map +1 -0
  18. package/dist/WorldArchive-dYf1OpSe.js +417 -0
  19. package/dist/WorldArchive-dYf1OpSe.js.map +1 -0
  20. package/dist/WorldIO-Dqz4MqTQ.js +149 -0
  21. package/dist/WorldIO-Dqz4MqTQ.js.map +1 -0
  22. package/dist/blankWorld-OoOvN_IK.js +75 -0
  23. package/dist/blankWorld-OoOvN_IK.js.map +1 -0
  24. package/dist/core.d.ts +68 -0
  25. package/dist/core.js +209 -0
  26. package/dist/core.js.map +1 -0
  27. package/dist/disposeObject3D-B3HCflvO.js +128 -0
  28. package/dist/disposeObject3D-B3HCflvO.js.map +1 -0
  29. package/dist/environments-B1WaICAN.js +4197 -0
  30. package/dist/environments-B1WaICAN.js.map +1 -0
  31. package/dist/gltfIO-BMK1hc2D.js +9 -0
  32. package/dist/gltfIO-BMK1hc2D.js.map +1 -0
  33. package/dist/grandUrbanBlock-Bdjgc6ZT.js +515 -0
  34. package/dist/grandUrbanBlock-Bdjgc6ZT.js.map +1 -0
  35. package/dist/index.d.ts +275 -0
  36. package/dist/index.js +16239 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/magicCabin-DPQi_jh-.js +11019 -0
  39. package/dist/magicCabin-DPQi_jh-.js.map +1 -0
  40. package/dist/mcp.d.ts +2 -0
  41. package/dist/mcp.js +1 -0
  42. package/dist/monumentHall-IOLbRZQC.js +403 -0
  43. package/dist/monumentHall-IOLbRZQC.js.map +1 -0
  44. package/dist/node.d.ts +16 -0
  45. package/dist/node.js +26 -0
  46. package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
  47. package/dist/ruinedCourtyard-BtaF_aOi.js +696 -0
  48. package/dist/ruinedCourtyard-BtaF_aOi.js.map +1 -0
  49. package/dist/runtime/application/AgentTools.js +28 -0
  50. package/dist/runtime/application/README.md +14 -0
  51. package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
  52. package/dist/runtime/application/agent/StudioMcpAllowlist.js +8 -0
  53. package/dist/runtime/application/buildTaskObservation.js +117 -0
  54. package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +46 -0
  55. package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
  56. package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
  57. package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +72 -0
  58. package/dist/runtime/application/createSession.js +66 -0
  59. package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
  60. package/dist/runtime/application/generation/GenerationOrchestrator.js +629 -0
  61. package/dist/runtime/application/generation/GenerationRuntime.js +214 -0
  62. package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +285 -0
  63. package/dist/runtime/application/native-scene/CodeProject.js +119 -0
  64. package/dist/runtime/application/native-scene/CodeProjectModules.js +128 -0
  65. package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +62 -0
  66. package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
  67. package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
  68. package/dist/runtime/application/native-scene/NativeSceneHost.js +319 -0
  69. package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
  70. package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
  71. package/dist/runtime/application/object-forge/SceneObjectForge.js +232 -0
  72. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
  73. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
  74. package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
  75. package/dist/runtime/application/scene/CapabilityResolver.js +79 -0
  76. package/dist/runtime/application/scene/RequestWindow.js +54 -0
  77. package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
  78. package/dist/runtime/application/scene/SceneContracts.js +45 -0
  79. package/dist/runtime/application/scene/SceneEditService.js +144 -0
  80. package/dist/runtime/application/scene/SceneFacade.js +261 -0
  81. package/dist/runtime/application/scene/SceneInteractionAdapters.js +40 -0
  82. package/dist/runtime/application/scene/SceneJobController.js +229 -0
  83. package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
  84. package/dist/runtime/application/scene/ScenePackage.js +162 -0
  85. package/dist/runtime/application/scene/ScenePersistence.js +50 -0
  86. package/dist/runtime/application/scene/SceneProject.js +95 -0
  87. package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
  88. package/dist/runtime/application/scene/StarterScene.js +56 -0
  89. package/dist/runtime/application/scene/WorldArchive.js +87 -0
  90. package/dist/runtime/application/scene/WorldDirectory.js +20 -0
  91. package/dist/runtime/application/scene/WorldDocument.js +74 -0
  92. package/dist/runtime/application/scene/WorldIO.js +103 -0
  93. package/dist/runtime/application/scene/WorldStorage.js +137 -0
  94. package/dist/runtime/application/skills/SkillRegistry.js +189 -0
  95. package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
  96. package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
  97. package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
  98. package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
  99. package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
  100. package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
  101. package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
  102. package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
  103. package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
  104. package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
  105. package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
  106. package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
  107. package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
  108. package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
  109. package/dist/runtime/application/skills/skillPrimitives.js +4 -0
  110. package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
  111. package/dist/runtime/application/tasks.jsonl +67 -0
  112. package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
  113. package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
  114. package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
  115. package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
  116. package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
  117. package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
  118. package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
  119. package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
  120. package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
  121. package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
  122. package/dist/runtime/application/world-authoring/HeadlessImageExport.js +174 -0
  123. package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
  124. package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
  125. package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +77 -0
  126. package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
  127. package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
  128. package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
  129. package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
  130. package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
  131. package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
  132. package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
  133. package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
  134. package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
  135. package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +132 -0
  136. package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
  137. package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
  138. package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
  139. package/dist/runtime/apps/mcp-server/README.md +150 -0
  140. package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
  141. package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
  142. package/dist/runtime/apps/mcp-server/SessionManager.js +80 -0
  143. package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +58 -0
  144. package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +190 -0
  145. package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
  146. package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
  147. package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
  148. package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
  149. package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
  150. package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
  151. package/dist/runtime/apps/mcp-server/main.mjs +65 -0
  152. package/dist/runtime/apps/mcp-server/registerTools.js +225 -0
  153. package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
  154. package/dist/runtime/apps/mcp-server/security.js +21 -0
  155. package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
  156. package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
  157. package/dist/runtime/apps/server/README.md +7 -0
  158. package/dist/runtime/apps/server/WorldDiskStorage.js +51 -0
  159. package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
  160. package/dist/runtime/apps/server/tasks.jsonl +10 -0
  161. package/dist/runtime/foundation/EventBus.js +18 -0
  162. package/dist/runtime/foundation/JsonGateway.js +47 -0
  163. package/dist/runtime/foundation/PolicyEngine.js +21 -0
  164. package/dist/runtime/foundation/README.md +7 -0
  165. package/dist/runtime/foundation/TraceRecorder.js +76 -0
  166. package/dist/runtime/foundation/errors.js +8 -0
  167. package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
  168. package/dist/runtime/foundation/version.js +2 -0
  169. package/dist/runtime/modules/agent/README.md +11 -0
  170. package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
  171. package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
  172. package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
  173. package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
  174. package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
  175. package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
  176. package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
  177. package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
  178. package/dist/runtime/modules/agent/prompt/index.js +52 -0
  179. package/dist/runtime/modules/agent/tasks.jsonl +94 -0
  180. package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
  181. package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
  182. package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
  183. package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
  184. package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
  185. package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
  186. package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
  187. package/dist/runtime/modules/artifact/README.md +7 -0
  188. package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
  189. package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
  190. package/dist/runtime/modules/asset/AssetModule.js +399 -0
  191. package/dist/runtime/modules/asset/README.md +54 -0
  192. package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
  193. package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
  194. package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
  195. package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
  196. package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
  197. package/dist/runtime/modules/asset/model/AssetInputContracts.js +100 -0
  198. package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
  199. package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
  200. package/dist/runtime/modules/asset/model/admission.js +117 -0
  201. package/dist/runtime/modules/asset/model/errors.js +6 -0
  202. package/dist/runtime/modules/asset/model/parts.js +27 -0
  203. package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
  204. package/dist/runtime/modules/asset/model/schema.js +150 -0
  205. package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
  206. package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
  207. package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
  208. package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
  209. package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
  210. package/dist/runtime/modules/asset/production/AssetRecipe.js +47 -0
  211. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
  212. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
  213. package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
  214. package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
  215. package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
  216. package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
  217. package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
  218. package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
  219. package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
  220. package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
  221. package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
  222. package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
  223. package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
  224. package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
  225. package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
  226. package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
  227. package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
  228. package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
  229. package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
  230. package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
  231. package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
  232. package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
  233. package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
  234. package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
  235. package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
  236. package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
  237. package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
  238. package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
  239. package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
  240. package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
  241. package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
  242. package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
  243. package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
  244. package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
  245. package/dist/runtime/modules/asset/tasks.jsonl +87 -0
  246. package/dist/runtime/modules/generation/README.md +9 -0
  247. package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
  248. package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
  249. package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
  250. package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
  251. package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
  252. package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
  253. package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
  254. package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
  255. package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
  256. package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
  257. package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
  258. package/dist/runtime/modules/generation/tasks.jsonl +35 -0
  259. package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
  260. package/dist/runtime/modules/navigation/RecastNavigationBackend.js +245 -0
  261. package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
  262. package/dist/runtime/modules/physics/PhysicsApiSurface.js +651 -0
  263. package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
  264. package/dist/runtime/modules/physics/RapierPhysicsBackend.js +410 -0
  265. package/dist/runtime/modules/rendering/README.md +7 -0
  266. package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
  267. package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
  268. package/dist/runtime/modules/rendering/createRenderer.js +76 -0
  269. package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
  270. package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
  271. package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
  272. package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
  273. package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
  274. package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
  275. package/dist/runtime/modules/world/README.md +13 -0
  276. package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
  277. package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
  278. package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
  279. package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
  280. package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
  281. package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
  282. package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
  283. package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
  284. package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
  285. package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
  286. package/dist/runtime/modules/world/content/blankWorld.js +35 -0
  287. package/dist/runtime/modules/world/content/environments.js +84 -0
  288. package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
  289. package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
  290. package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
  291. package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
  292. package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
  293. package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
  294. package/dist/runtime/modules/world/content/magicCabin.js +190 -0
  295. package/dist/runtime/modules/world/content/monumentHall.js +154 -0
  296. package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
  297. package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
  298. package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
  299. package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
  300. package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
  301. package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
  302. package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
  303. package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
  304. package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
  305. package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
  306. package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
  307. package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
  308. package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
  309. package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
  310. package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
  311. package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
  312. package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
  313. package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
  314. package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
  315. package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
  316. package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
  317. package/dist/runtime/modules/world/errors.js +9 -0
  318. package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
  319. package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
  320. package/dist/runtime/modules/world/runtime/CommandHistory.js +80 -0
  321. package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +150 -0
  322. package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
  323. package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
  324. package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
  325. package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +207 -0
  326. package/dist/runtime/modules/world/runtime/SceneSerializer.js +246 -0
  327. package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
  328. package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
  329. package/dist/runtime/modules/world/runtime/WorldCommands.js +502 -0
  330. package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
  331. package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
  332. package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
  333. package/dist/runtime/modules/world/runtime/WorldRuntime.js +665 -0
  334. package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +107 -0
  335. package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
  336. package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
  337. package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
  338. package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
  339. package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
  340. package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +305 -0
  341. package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
  342. package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
  343. package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +222 -0
  344. package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +130 -0
  345. package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
  346. package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
  347. package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +120 -0
  348. package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +102 -0
  349. package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
  350. package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +99 -0
  351. package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
  352. package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
  353. package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +125 -0
  354. package/dist/runtime/modules/world/runtime/systems/Instrument.js +38 -0
  355. package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +728 -0
  356. package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +269 -0
  357. package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +469 -0
  358. package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1673 -0
  359. package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +457 -0
  360. package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +284 -0
  361. package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
  362. package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
  363. package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
  364. package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
  365. package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
  366. package/dist/runtime/modules/world/tasks.jsonl +530 -0
  367. package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
  368. package/dist/runtime/modules/world/verification/Finding.js +105 -0
  369. package/dist/runtime/modules/world/verification/InteractionEvidence.js +69 -0
  370. package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
  371. package/dist/runtime/modules/world/verification/WorldAcceptance.js +158 -0
  372. package/dist/runtime/modules/world/verification/WorldValidator.js +65 -0
  373. package/dist/runtime/package-lock.json +16048 -0
  374. package/dist/runtime/package.json +105 -0
  375. package/dist/runtime/public/assets/cabinet.glb +0 -0
  376. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
  377. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
  378. package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
  379. package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
  380. package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
  381. package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
  382. package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
  383. package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
  384. package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
  385. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
  386. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
  387. package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
  388. package/dist/schema-BWpTl0Wj.js +359 -0
  389. package/dist/schema-BWpTl0Wj.js.map +1 -0
  390. package/dist/suzhouGarden-H9tiPgxq.js +6150 -0
  391. package/dist/suzhouGarden-H9tiPgxq.js.map +1 -0
  392. package/dist/woodlandWorkshop-D6zzSbHr.js +483 -0
  393. package/dist/woodlandWorkshop-D6zzSbHr.js.map +1 -0
  394. package/dist/yuanmingyuan-D6IHqjZ-.js +4955 -0
  395. package/dist/yuanmingyuan-D6IHqjZ-.js.map +1 -0
  396. package/package.json +70 -4
@@ -0,0 +1,30 @@
1
+ import { parentPort, workerData } from 'node:worker_threads';
2
+ import { getQuickJS } from 'quickjs-emscripten';
3
+
4
+ // No host functions, module loader, filesystem, network or credentials are exposed to QuickJS.
5
+ const { bundle, code, source, mode='authoring', document, timeoutMs, memoryBytes }=workerData;
6
+ const QuickJS=await getQuickJS();
7
+ const runtime=QuickJS.newRuntime();
8
+ runtime.setMemoryLimit(memoryBytes);
9
+ runtime.setMaxStackSize(1024*1024);
10
+ const context=runtime.newContext();
11
+ let deadline=Date.now()+5000;
12
+ runtime.setInterruptHandler(()=>Date.now()>deadline);
13
+ try {
14
+ const setup=context.evalCode(bundle,'trusted-authoring-bootstrap.js');
15
+ if (setup.error) { setup.error.dispose(); throw new Error('AUTHORING_SANDBOX_INIT_FAILED'); }
16
+ setup.value.dispose();
17
+ deadline=Date.now()+timeoutMs;
18
+ const expression=mode==='procedural' ? `AuthoringSandbox.build(${JSON.stringify(source)})` : `AuthoringSandbox.execute(${JSON.stringify(code)},${JSON.stringify(document)})`;
19
+ const output=context.evalCode(`JSON.stringify(${expression})`,'agent-authoring.js');
20
+ if (output.error) {
21
+ const error=context.dump(output.error); output.error.dispose();
22
+ const message=Date.now()>deadline?'AUTHORING_CODE_TIMEOUT':String(error?.message || 'AUTHORING_CODE_FAILED').slice(0,500);
23
+ parentPort.postMessage({error:message});
24
+ } else {
25
+ const json=context.getString(output.value); output.value.dispose();
26
+ if (json.length>2097152) throw new Error('AUTHORING_DOCUMENT_LIMIT');
27
+ parentPort.postMessage({json});
28
+ }
29
+ } catch(error) { parentPort.postMessage({error:String(error.message).slice(0,500)}); }
30
+ finally { context.dispose(); runtime.dispose(); }
@@ -0,0 +1,17 @@
1
+ import { readFile,readdir } from 'node:fs/promises';
2
+ import { createHash } from 'node:crypto';
3
+ import { fileURLToPath } from 'node:url';
4
+ import path from 'node:path';
5
+ let cached;
6
+ // Version the trusted compiler/validation pipeline as well as the container image.
7
+ export function pipelineDigest() {
8
+ cached ||= (async()=>{
9
+ const root=fileURLToPath(new URL('../../',import.meta.url));
10
+ const directories=['modules/asset/production','modules/asset/model','modules/world/verification','application/programmatic-assets','application/world-authoring'];
11
+ const files=[];const walk=async dir=>{for(const entry of await readdir(path.join(root,dir),{withFileTypes:true})){const relative=path.posix.join(dir,entry.name);if(entry.isDirectory())await walk(relative);else if(/\.[cm]?js$/.test(entry.name))files.push(relative);}};
12
+ for(const dir of directories)await walk(dir);
13
+ files.push('apps/mcp-server/HeadlessGLTFLoader.js','modules/asset/AssetModule.js','package-lock.json');
14
+ const digest=createHash('sha256');for(const file of files.sort())digest.update(file).update(await readFile(path.join(root,file)));
15
+ return digest.digest('hex');
16
+ })();return cached;
17
+ }
@@ -0,0 +1,71 @@
1
+ import { Worker } from 'node:worker_threads';
2
+ import { sandboxBundle } from './SandboxBundle.js';
3
+ import { pipelineDigest } from './BuildEnvironment.js';
4
+ import { validateRemoteAuthoringDocument } from './RemoteAuthoringDocument.js';
5
+ import { DockerBuildRunner } from './DockerBuildRunner.js';
6
+
7
+ /** Execution contract: environment(), run(request, {signal}), execute(), close().
8
+ * Worker resource limits are reliability controls, NOT OS isolation.
9
+ */
10
+ export function createCodeExecutor({ mode = 'worker-wasm', authorized = false, remote = false, timeoutMs = 1500,
11
+ wallTimeoutMs = 12000, memoryBytes = 96 * 1024 * 1024, ...options } = {}) {
12
+ if (!['disabled', 'worker-wasm', 'trusted-local', 'os-isolated'].includes(mode)) throw new Error('CODE_EXECUTION_MODE_INVALID');
13
+ if (remote && !['disabled', 'os-isolated'].includes(mode)) throw new Error('OS_ISOLATION_REQUIRED');
14
+ if (mode === 'trusted-local' && authorized !== true) throw new Error('CODE_EXECUTION_AUTHORIZATION_REQUIRED');
15
+ if (mode === 'os-isolated') return new DockerBuildRunner(options);
16
+ const active = new Set();
17
+ let closed = false;
18
+ const check = () => {
19
+ if (closed) throw new Error('AUTHORING_EXECUTOR_CLOSED');
20
+ if (mode === 'disabled') throw new Error('CODE_EXECUTION_DISABLED');
21
+ };
22
+ const executor = {
23
+ async environment() {
24
+ check();
25
+ return { engine: mode, builderVersion: '2', threeVersion: '0.186.0',
26
+ digest: (await sandboxBundle()).digest, pipelineDigest: await pipelineDigest() };
27
+ },
28
+ async run(request, { signal } = {}) {
29
+ check();
30
+ if (signal?.aborted) throw new Error('BUILD_CANCELLED');
31
+ if (!['authoring', 'procedural'].includes(request.mode)) throw new Error('BUILD_MODE_INVALID');
32
+ const source = request.mode === 'procedural' ? request.source : request.code;
33
+ if (typeof source !== 'string' || Buffer.byteLength(source) > 32768) throw new Error('BUILD_SOURCE_LIMIT');
34
+ if (request.mode === 'authoring') validateRemoteAuthoringDocument(request.document);
35
+ const environment = await executor.environment();
36
+ const bundle = mode === 'worker-wasm' ? (await sandboxBundle()).code : undefined;
37
+ check();
38
+ if (signal?.aborted) throw new Error('BUILD_CANCELLED');
39
+ return new Promise((resolve, reject) => {
40
+ const worker = new Worker(new URL(mode === 'worker-wasm' ? './AuthoringSandboxWorker.mjs' : './TrustedAuthoringWorker.mjs', import.meta.url), {
41
+ workerData: { ...request, bundle, timeoutMs, memoryBytes }, resourceLimits: { maxOldGenerationSizeMb: Math.ceil(memoryBytes / 1048576) }, execArgv: []
42
+ });
43
+ let finished = false;
44
+ const finish = (error, value) => {
45
+ if (finished) return;
46
+ finished = true; clearTimeout(timer); signal?.removeEventListener('abort', abort);
47
+ active.delete(cancel); void worker.terminate();
48
+ if (error) reject(error); else resolve(value);
49
+ };
50
+ const abort = () => finish(new Error('BUILD_CANCELLED'));
51
+ const cancel = () => finish(new Error('AUTHORING_EXECUTOR_CLOSED'));
52
+ const timer = setTimeout(() => finish(new Error('AUTHORING_CODE_TIMEOUT')), wallTimeoutMs);
53
+ active.add(cancel); signal?.addEventListener('abort', abort, { once: true });
54
+ if (signal?.aborted) abort();
55
+ worker.once('message', message => {
56
+ if (message.error) return finish(Object.assign(new Error('BUILD_EXECUTION_FAILED'), { details: { message: message.error } }));
57
+ try {
58
+ if (typeof message.json !== 'string' || message.json.length > 2097152) throw new Error('BUILD_OUTPUT_LIMIT');
59
+ finish(null, { document: validateRemoteAuthoringDocument(JSON.parse(message.json)), environment,
60
+ security: { mode, osIsolation: false, trusted: mode === 'trusted-local', memoryBytes, wallTimeoutMs } });
61
+ } catch (error) { finish(error); }
62
+ });
63
+ worker.once('error', error => finish(Object.assign(new Error('AUTHORING_SANDBOX_FAILED'), { details: { message: error.message } })));
64
+ worker.once('exit', () => finish(new Error('AUTHORING_SANDBOX_STOPPED')));
65
+ });
66
+ },
67
+ async execute(request, options) { return (await executor.run({ ...request, mode: 'authoring' }, options)).document; },
68
+ close() { closed = true; for (const cancel of active) cancel(); }
69
+ };
70
+ return executor;
71
+ }
@@ -0,0 +1,42 @@
1
+ # PC2 AgentDock deployment
2
+
3
+ Validated on 2026-11-04 on PC2 (`RANRAN4060`). MCP is merged into
4
+ `feat/ui-design-system-unify` at merge commit `a607445`.
5
+
6
+ - Source: `D:\a_programming_list\A-Python-Project\wk08\AgentScape`
7
+ - Application: `apps/mcp-server/main.mjs`; Studio starts independently.
8
+ - AgentDock dynamic server: `agentscape-world`, Streamable HTTP,
9
+ `http://127.0.0.1:39015/mcp`, 24 tools after the v0.3 programmatic asset upgrade.
10
+ - Authorization header references the server's isolated environment variable
11
+ `AGENTSCAPE_WORLD_AUTHORIZATION`, configured through `mcp_manage`.
12
+ - Windows task `AgentScape-World-MCP` starts a hidden supervisor at the current
13
+ user's logon. It is running now; Node restarts after exit with a five-second delay.
14
+ This is a user logon task, not a system service before logon.
15
+ - Supervisor and private runtime files live in
16
+ `C:\Users\yuminghui\.agentdock\agentscape-world`.
17
+ `start.ps1` loads an independent Windows-user-protected credential from
18
+ `credential.clixml`. Do not publish these private files or credential values.
19
+ - Exported scenes live in the source checkout's ignored `.mcp-sessions` directory.
20
+ Worlds are in memory and do not survive process restart.
21
+
22
+ v0.3 additionally stores published assets, source versions and explicitly saved worlds
23
+ under `D:\AgentScapeData\mcp-assets`. `world_restore` resolves server save IDs after
24
+ restart. Programmatic builds require Docker Desktop Linux and a provisioned
25
+ `sandbox.json`; unavailable isolation fails closed. See `PROGRAMMATIC-ASSETS.md`.
26
+
27
+ The official SDK unified HTTP handler serves both 2026-07-28 request envelopes
28
+ and legacy clients. The original legacy-only transport failed AgentDock discovery.
29
+ `tests/mcp/modern-protocol.test.js` covers discovery and tool listing without
30
+ a legacy handshake; existing HTTP tests cover the complete physics workflow.
31
+
32
+ Real AgentDock acceptance created a private world, observed four objects, opened
33
+ the cabinet, picked up the cup and placed it on the table. All three actions
34
+ returned `verified`; final verification passed six checks and reported empty hands.
35
+ Export returned four objects (9140 bytes), and the session was closed.
36
+ Full call evidence is saved privately in the runtime directory's `acceptance.json`.
37
+
38
+ Use `mcp_manage inspect/refresh` for connection health and `mcp_tool_search`,
39
+ `mcp_tool_inspect`, `mcp_tool_call` to discover and invoke tools.
40
+ To stop maintenance, stop the Windows task and its Node child; stopping only Node
41
+ causes the supervisor to restart it. Future Node installations may require updating
42
+ the explicit executable path in `start.ps1`.
@@ -0,0 +1,66 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { validateRemoteAuthoringDocument } from './RemoteAuthoringDocument.js';
5
+ import { pipelineDigest } from './BuildEnvironment.js';
6
+ import { sandboxBundle } from './SandboxBundle.js';
7
+
8
+ export function runCommand(command,args,{input='',timeoutMs=15000,maxBytes=4194304,signal}={}) {
9
+ return new Promise((resolve,reject)=>{
10
+ const child=spawn(command,args,{windowsHide:true,stdio:['pipe','pipe','pipe']});
11
+ const output=[],errors=[];let size=0,problem;
12
+ const stop=code=>{problem ||= new Error(code);child.kill();};
13
+ const timer=setTimeout(()=>stop('BUILD_TIMEOUT'),timeoutMs);
14
+ const abort=()=>stop('BUILD_CANCELLED');signal?.addEventListener('abort',abort,{once:true});if(signal?.aborted)abort();
15
+ child.stdout.on('data',chunk=>{size+=chunk.length;if(size>maxBytes)stop('BUILD_OUTPUT_LIMIT');else output.push(chunk);});
16
+ child.stderr.on('data',chunk=>{if(errors.reduce((n,b)=>n+b.length,0)<4096)errors.push(chunk);});
17
+ child.on('error',()=>{clearTimeout(timer);signal?.removeEventListener('abort',abort);reject(new Error('SANDBOX_UNAVAILABLE'));});
18
+ child.on('close',code=>{clearTimeout(timer);signal?.removeEventListener('abort',abort);if(problem)reject(problem);else resolve({code,stdout:Buffer.concat(output).toString('utf8'),stderr:Buffer.concat(errors).toString('utf8')});});
19
+ child.stdin.on('error',()=>{});child.stdin.end(input);
20
+ });
21
+ }
22
+
23
+ export class DockerBuildRunner {
24
+ constructor({configPath,command='docker',timeoutMs=15000}={}) {Object.assign(this,{configPath,command,timeoutMs});this.controllers=new Set();this.id=randomUUID();}
25
+ async environment() {
26
+ if(this.closed)throw new Error('AUTHORING_EXECUTOR_CLOSED');
27
+ try {
28
+ const config=JSON.parse(await readFile(this.configPath,'utf8'));
29
+ if(config.digest!==(await sandboxBundle()).digest)throw Error();
30
+ if(!/^sha256:[a-f0-9]{64}$/.test(config.image))throw Error();
31
+ const image=await runCommand(this.command,['image','inspect',config.image],{timeoutMs:5000});
32
+ if(image.code!==0)throw Error();
33
+ const metadata=JSON.parse(image.stdout)[0];
34
+ if(metadata.Os!=='linux'||metadata.Config?.Labels?.['agentscape.sandbox.version']!=='1'||metadata.Config?.Labels?.['agentscape.sandbox.digest']!==config.digest)throw Error();
35
+ return {...config,engine:'docker-linux',builderVersion:'1',threeVersion:'0.186.0',pipelineDigest:await pipelineDigest()};
36
+ }catch{throw new Error('SANDBOX_UNAVAILABLE');}
37
+ }
38
+ async run(request,{signal}={}) {
39
+ const environment=await this.environment();
40
+ const controller=new AbortController();this.controllers.add(controller);
41
+ const abort=()=>controller.abort();signal?.addEventListener('abort',abort,{once:true});if(signal?.aborted)abort();
42
+ const name=`agentscape-build-${randomUUID()}`;
43
+ let container=name;
44
+ try {
45
+ const created=await runCommand(this.command,['create','--name',name,'--label',`agentscape.runner=${this.id}`,'--interactive','--network','none','--read-only','--cap-drop','ALL','--security-opt','no-new-privileges','--pids-limit','64','--memory','256m','--memory-swap','256m','--cpus','1','--user','65534:65534','--tmpfs','/tmp:rw,noexec,nosuid,size=16m','--init','--pull','never',environment.image],{timeoutMs:5000,signal:controller.signal});
46
+ if(created.code!==0)throw new Error('SANDBOX_UNAVAILABLE');
47
+ container=created.stdout.trim();if(!/^[a-f0-9]{64}$/.test(container))throw new Error('SANDBOX_UNAVAILABLE');
48
+ const inspected=await runCommand(this.command,['inspect',container],{timeoutMs:5000});
49
+ const info=JSON.parse(inspected.stdout)[0],h=info.HostConfig;
50
+ if(info.Image!==environment.image||info.Config.User!=='65534:65534'||!h.ReadonlyRootfs||h.NetworkMode!=='none'||h.Privileged||h.PidsLimit!==64||h.Memory!==268435456||h.MemorySwap!==268435456||h.NanoCpus!==1e9||!h.CapDrop.includes('ALL')||!h.SecurityOpt.some(s=>s.startsWith('no-new-privileges'))||info.Mounts.some(m=>m.Type!=='tmpfs'))throw new Error('SANDBOX_POLICY_MISMATCH');
51
+ const result=await runCommand(this.command,['start','--attach','--interactive',container],{input:JSON.stringify(request),timeoutMs:this.timeoutMs,signal:controller.signal});
52
+ let data;try{data=JSON.parse(result.stdout);}catch{throw new Error(result.code===137?'BUILD_MEMORY_LIMIT':'BUILD_EXECUTION_FAILED');}
53
+ if(result.code!==0||data.error)throw new Error(/^[A-Z_]+$/.test(data.error||'')?data.error:'BUILD_EXECUTION_FAILED');
54
+ return {document:validateRemoteAuthoringDocument(data.document),environment,security:{network:'none',readOnly:true,user:'65534:65534',memoryBytes:h.Memory,pids:h.PidsLimit,cpus:1,noNewPrivileges:true,capabilities:[],mounts:[]}};
55
+ } finally {
56
+ signal?.removeEventListener('abort',abort);this.controllers.delete(controller);
57
+ const cleaned=await runCommand(this.command,['rm','--force',container],{timeoutMs:5000}).catch(()=>null);
58
+ if(!cleaned||cleaned.code!==0){
59
+ const remaining=await runCommand(this.command,['inspect',container],{timeoutMs:5000}).catch(()=>null);
60
+ if(!remaining||remaining.code===0||!remaining.stderr.includes('No such'))throw new Error('SANDBOX_CLEANUP_FAILED');
61
+ }
62
+ }
63
+ }
64
+ async execute(request,options) {return (await this.run({...request,mode:'authoring'},options)).document;}
65
+ close() {this.closed=true;for(const controller of this.controllers)controller.abort();this.controllers.clear();}
66
+ }
@@ -0,0 +1,159 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { mkdir, readFile, writeFile, rename, rm, readdir, lstat } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { parseDefinition, canonical, proceduralContract } from '../../application/programmatic-assets/ProgrammaticAssetContract.js';
5
+ import { validateAssetManifest } from '../../modules/asset/model/schema.js';
6
+ import { assetAdmission } from '../../modules/asset/model/admission.js';
7
+ import { SceneObjectForge } from '../../application/object-forge/SceneObjectForge.js';
8
+
9
+ export const hash=value=>createHash('sha256').update(value).digest('hex');
10
+ export const assetVersion=(source,definition,environment)=>hash(canonical({contract:proceduralContract,source,definition,environment}));
11
+ const assetPattern=/^pa_[a-f0-9]{64}$/;
12
+ const projectContract='agentscape.project-asset.v1';
13
+ const projectVersion=(definition,template,bytes)=>hash(canonical({contract:projectContract,definition,template,glbHash:hash(bytes)}));
14
+ const uuidPattern=/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
15
+ export class FileAssetRepository {
16
+ constructor(root) {this.root=path.resolve(root);}
17
+ ownerRoot(owner) {return path.join(this.root,'owners',hash(owner));}
18
+ target(owner,kind,id) {
19
+ if(!['assets','builds','requests','worlds'].includes(kind)||!(kind==='assets'?assetPattern:uuidPattern).test(id))throw new Error('STORAGE_ID_INVALID');
20
+ return path.join(this.ownerRoot(owner),kind,id);
21
+ }
22
+ async read(file,max=4194304) {
23
+ const stat=await lstat(file);if(!stat.isFile()||stat.isSymbolicLink()||stat.size>max)throw new Error('STORAGE_INTEGRITY_FAILED');
24
+ return readFile(file);
25
+ }
26
+ async json(file) {return JSON.parse((await this.read(file)).toString('utf8'));}
27
+ async atomic(file,value) {
28
+ await mkdir(path.dirname(file),{recursive:true});const temp=`${file}.${randomUUID()}.tmp`;
29
+ try{await writeFile(temp,JSON.stringify(value),{flag:'wx'});await rename(temp,file);}finally{await rm(temp,{force:true});}
30
+ }
31
+ async ids(owner,kind) {try{return(await readdir(path.join(this.ownerRoot(owner),kind))).filter(id=>(kind==='assets'?assetPattern:uuidPattern).test(id));}catch(e){if(e.code==='ENOENT')return [];throw e;}}
32
+ async save(owner,{source,definition,environment,...result}) {
33
+ const version=assetVersion(source,definition,environment),assetId=`pa_${version}`;
34
+ const target=this.target(owner,'assets',assetId);
35
+ const manifestJSON=JSON.stringify(result.manifest);
36
+ const hashes={source:hash(source),definition:hash(canonical(definition)),glb:hash(result.bytes),manifest:hash(manifestJSON)};
37
+ try{const previous=await this.get(owner,assetId);if(previous.build.hashes.glb!==hashes.glb)throw new Error('BUILD_NONDETERMINISTIC');return previous;}catch(e){if(e.code!=='ENOENT')throw e;}
38
+ if((await this.ids(owner,'assets')).length>=128)throw new Error('ASSET_STORAGE_QUOTA');
39
+ const build={schema:proceduralContract,assetId,logicalId:definition?.id || 'visual',version,owner:hash(owner),definition,environment,hashes,admission:result.admission,validation:result.validation,security:result.security,createdAt:new Date().toISOString()};
40
+ if(Buffer.byteLength(JSON.stringify(build))>1048576||Buffer.byteLength(manifestJSON)>262144)throw new Error('BUILD_METADATA_LIMIT');
41
+ await mkdir(path.dirname(target),{recursive:true});const staging=path.join(path.dirname(target),`.tmp-${randomUUID()}`);
42
+ try{
43
+ await mkdir(staging);await writeFile(path.join(staging,'source.js'),source);await writeFile(path.join(staging,'asset.glb'),result.bytes);await writeFile(path.join(staging,'manifest.json'),manifestJSON);await writeFile(path.join(staging,'build.json'),JSON.stringify(build));
44
+ if(hash(await this.read(path.join(staging,'asset.glb')))!==hashes.glb)throw new Error('STORAGE_INTEGRITY_FAILED');
45
+ try{await rename(staging,target);}catch(error){
46
+ if(!['EEXIST','ENOTEMPTY','EPERM'].includes(error.code))throw error;
47
+ const previous=await this.get(owner,assetId);if(previous.build.hashes.glb!==hashes.glb)throw new Error('BUILD_NONDETERMINISTIC');
48
+ }
49
+ }finally{await rm(staging,{recursive:true,force:true});}
50
+ return this.get(owner,assetId);
51
+ }
52
+
53
+ /** Promote a locally compiled, ready project asset into an immutable owner-owned version. */
54
+ async saveProjectAsset(owner,{definition,manifest,bytes}) {
55
+ const source=SceneObjectForge.validateTransfer({objects:[{id:'source',assetId:manifest.id}]},
56
+ [{id:'source',assetId:manifest.id,revision:1,definition}])[0].definition;
57
+ if(!(bytes instanceof Uint8Array)||!bytes.length||bytes.length>4194304)throw new Error('ASSET_STORAGE_QUOTA');
58
+ const admission=assetAdmission(manifest);
59
+ if(admission.status!=='ready')throw new Error('ASSET_NOT_READY');
60
+ const template=JSON.parse(JSON.stringify(manifest));
61
+ delete template.id;delete template.source;
62
+ const version=projectVersion(source,template,bytes),assetId='pa_'+version;
63
+ const publishedManifest={...template,id:assetId,source:{kind:'compiled',key:assetId}};
64
+ validateAssetManifest(publishedManifest);
65
+ const sourceText=JSON.stringify(source),manifestJSON=JSON.stringify(publishedManifest);
66
+ const hashes={source:hash(sourceText),definition:hash(canonical(source)),glb:hash(bytes),manifest:hash(manifestJSON)};
67
+ const build={schema:projectContract,assetId,logicalId:source.type||source.definition?.id||source.id||'project-asset',
68
+ version,owner:hash(owner),definition:source,compilerDefinition:template,
69
+ environment:{threeVersion:'0.186.0'},hashes,admission,
70
+ validation:{status:'compiled-and-admitted',runtimeActionVerification:'not-run'},
71
+ security:{scope:'owner',sourceKind:'editable-definition',executedDuringPublish:false},
72
+ createdAt:new Date().toISOString()};
73
+ if(Buffer.byteLength(JSON.stringify(build))>1048576 || Buffer.byteLength(manifestJSON)>262144)throw new Error('BUILD_METADATA_LIMIT');
74
+ const target=this.target(owner,'assets',assetId);
75
+ try{
76
+ const existing=await this.get(owner,assetId);
77
+ if(existing.build.hashes.glb!==hashes.glb)throw new Error('BUILD_NONDETERMINISTIC');
78
+ return existing;
79
+ }catch(error){if(error.code!=='ENOENT')throw error;}
80
+ if((await this.ids(owner,'assets')).length>=128)throw new Error('ASSET_STORAGE_QUOTA');
81
+ await mkdir(path.dirname(target),{recursive:true});
82
+ const staging=path.join(path.dirname(target),'.tmp-'+randomUUID());
83
+ try{
84
+ await mkdir(staging);
85
+ await writeFile(path.join(staging,'source.json'),sourceText);
86
+ await writeFile(path.join(staging,'asset.glb'),bytes);
87
+ await writeFile(path.join(staging,'manifest.json'),manifestJSON);
88
+ await writeFile(path.join(staging,'build.json'),JSON.stringify(build));
89
+ if(hash(await this.read(path.join(staging,'asset.glb')))!==hashes.glb)throw new Error('STORAGE_INTEGRITY_FAILED');
90
+ try{await rename(staging,target);}
91
+ catch(error){
92
+ if(!['EEXIST','ENOTEMPTY','EPERM'].includes(error.code))throw error;
93
+ const previous=await this.get(owner,assetId);
94
+ if(previous.build.hashes.glb!==hashes.glb)throw new Error('BUILD_NONDETERMINISTIC');
95
+ }
96
+ }finally{await rm(staging,{recursive:true,force:true});}
97
+ return this.get(owner,assetId);
98
+ }
99
+ async get(owner,assetId,{published=false}={}) {
100
+ const directory=this.target(owner,'assets',assetId);
101
+ const build=await this.json(path.join(directory,'build.json'));
102
+ const [source,bytes,manifestBytes]=await Promise.all([
103
+ this.read(path.join(directory,build.schema===projectContract?'source.json':'source.js'),131072),
104
+ this.read(path.join(directory,'asset.glb')),this.read(path.join(directory,'manifest.json'),262144)
105
+ ]);
106
+ const isProject=build.schema===projectContract;
107
+ const validVersion=isProject
108
+ ? projectVersion(build.definition,build.compilerDefinition,bytes)===build.version
109
+ && source.toString('utf8')===JSON.stringify(build.definition)
110
+ : build.schema===proceduralContract
111
+ && assetVersion(source.toString('utf8'),(build.definition==null?null:parseDefinition(build.definition)),build.environment)===build.version;
112
+ if(build.owner!==hash(owner)||build.assetId!==assetId||build.environment?.threeVersion!=='0.186.0'
113
+ ||!validVersion||assetId!==('pa_'+build.version)
114
+ ||hash(source)!==build.hashes.source||hash(canonical(build.definition))!==build.hashes.definition
115
+ ||hash(bytes)!==build.hashes.glb||hash(manifestBytes)!==build.hashes.manifest)throw new Error('STORAGE_INTEGRITY_FAILED');
116
+ const manifest=JSON.parse(manifestBytes.toString('utf8'));validateAssetManifest(manifest);
117
+ if(manifest.id!==assetId||manifest.source.kind!=='compiled'||manifest.source.key!==assetId||manifest.source.fallbackUrl)throw new Error('STORAGE_INTEGRITY_FAILED');
118
+ if(isProject && canonical((({id,source,...rest})=>rest)(manifest))!==canonical(build.compilerDefinition))throw new Error('STORAGE_INTEGRITY_FAILED');
119
+ let isPublished=false;try{const marker=await this.json(path.join(directory,'published.json'));if(marker.assetId!==assetId||marker.owner!==hash(owner))throw new Error('STORAGE_INTEGRITY_FAILED');isPublished=true;}catch(e){if(e.code!=='ENOENT')throw e;}
120
+ if(published&&!isPublished)throw new Error('ASSET_NOT_PUBLISHED');
121
+ return {build,manifest,source:source.toString('utf8'),bytes,published:isPublished};
122
+ }
123
+ async publish(owner,assetId) {const asset=await this.get(owner,assetId);await this.atomic(path.join(this.target(owner,'assets',assetId),'published.json'),{assetId,owner:hash(owner)});return asset;}
124
+ async list(owner) {
125
+ const result=[];for(const id of await this.ids(owner,'assets')){const asset=await this.get(owner,id);if(asset.published)result.push({assetId:id,logicalId:asset.build.logicalId,version:asset.build.version,label:asset.manifest.label,admission:asset.build.admission});}return result;
126
+ }
127
+ compiledStore(owner) {
128
+ const memory=new Map();return {
129
+ put:async(key,bytes,metadata)=>{if(assetPattern.test(key))throw new Error('ASSET_VERSION_IMMUTABLE');memory.set(key,{bytes,metadata});return key;},
130
+ get:async key=>assetPattern.test(key)?{bytes:(await this.get(owner,key,{published:true})).bytes}:memory.get(key),
131
+ has:async key=>assetPattern.test(key)?Boolean(await this.get(owner,key,{published:true})):memory.has(key)
132
+ };
133
+ }
134
+ async attach(owner,assets,ids=null) {
135
+ for(const assetId of ids || (await this.list(owner)).map(a=>a.assetId)){const asset=await this.get(owner,assetId,{published:true});await assets.registerManifest(asset.manifest);}
136
+ }
137
+ async saveWorld(owner,snapshot) {
138
+ if((await this.ids(owner,'worlds')).length>=128)throw new Error('WORLD_STORAGE_QUOTA');
139
+ const dependencies=[];
140
+ for(const assetId of new Set(snapshot.objects.map(o=>o.assetId))){
141
+ if(assetPattern.test(assetId)){const a=await this.get(owner,assetId,{published:true});dependencies.push({assetId,manifestHash:a.build.hashes.manifest});}
142
+ else if(!['agent','cabinet','cup','table'].includes(assetId))throw new Error('WORLD_ASSET_NOT_PUBLISHED');
143
+ }
144
+ const saveId=randomUUID(),snapshotText=JSON.stringify(snapshot);
145
+ if(Buffer.byteLength(snapshotText)>4194304)throw new Error('EXPORT_LIMIT');
146
+ const record={schema:'agentscape.saved-world.v1',owner:hash(owner),hash:hash(snapshotText),snapshot,dependencies,createdAt:new Date().toISOString()};
147
+ if(Buffer.byteLength(JSON.stringify(record))>4194304)throw new Error('EXPORT_LIMIT');
148
+ await this.atomic(this.target(owner,'worlds',saveId),record);
149
+ return {saveId,dependencies,objects:snapshot.objects.length};
150
+ }
151
+ async loadWorld(owner,saveId) {
152
+ const data=await this.json(this.target(owner,'worlds',saveId));
153
+ if(data.schema!=='agentscape.saved-world.v1'||data.owner!==hash(owner)||hash(JSON.stringify(data.snapshot))!==data.hash)throw new Error('STORAGE_INTEGRITY_FAILED');
154
+ for(const dependency of data.dependencies){const asset=await this.get(owner,dependency.assetId,{published:true});if(asset.build.hashes.manifest!==dependency.manifestHash)throw new Error('STORAGE_INTEGRITY_FAILED');}
155
+ const resolved=new Set(data.dependencies.map(d=>d.assetId));
156
+ if(data.snapshot.objects.some(o=>assetPattern.test(o.assetId)&&!resolved.has(o.assetId)))throw new Error('STORAGE_INTEGRITY_FAILED');
157
+ return data;
158
+ }
159
+ }
@@ -0,0 +1,8 @@
1
+ // Node has Blob but no FileReader; GLTFExporter needs these two asynchronous reads.
2
+ export function installHeadlessAssetIO() {
3
+ globalThis.ProgressEvent ||= class ProgressEvent { constructor(type,init={}) { this.type=type; Object.assign(this,init); } };
4
+ globalThis.FileReader ||= class FileReader {
5
+ readAsArrayBuffer(blob) { blob.arrayBuffer().then(result=>{this.result=result;this.onloadend?.();},error=>{this.error=error;this.onerror?.(error);}); }
6
+ readAsDataURL(blob) { blob.arrayBuffer().then(bytes=>{this.result=`data:${blob.type};base64,${Buffer.from(bytes).toString('base64')}`;this.onloadend?.();},error=>{this.error=error;this.onerror?.(error);}); }
7
+ };
8
+ }
@@ -0,0 +1,47 @@
1
+ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
2
+ import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';
3
+ import { DataTexture, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter, LinearFilter, NearestMipmapNearestFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter } from 'three';
4
+ import sharp from 'sharp';
5
+
6
+ const filters={9728:NearestFilter,9729:LinearFilter,9984:NearestMipmapNearestFilter,9985:LinearMipmapNearestFilter,9986:NearestMipmapLinearFilter,9987:LinearMipmapLinearFilter};
7
+ const wrapping={33071:ClampToEdgeWrapping,33648:MirroredRepeatWrapping,10497:RepeatWrapping};
8
+ // Headless GLTFLoader cannot use DOM Image/ImageBitmap. Decode trusted embedded bytes
9
+ // to real DataTextures; never drop a missing texture or fetch an external URI.
10
+ export function createHeadlessGLTFLoader() {
11
+ const loader=new GLTFLoader().setMeshoptDecoder(MeshoptDecoder).register(parser=>({
12
+ name:'AGENTSCAPE_headless_texture',
13
+ async loadTexture(index) {
14
+ const definition=parser.json.textures[index];
15
+ const source=parser.json.images?.[definition.source];
16
+ if (!Number.isInteger(source?.bufferView) || source.uri) throw new Error('AUTHORING_EXTERNAL_TEXTURE_UNSUPPORTED');
17
+ const bytes=await parser.getDependency('bufferView',source.bufferView);
18
+ const {data,info}=await sharp(Buffer.from(bytes),{limitInputPixels:65536}).ensureAlpha().raw().toBuffer({resolveWithObject:true});
19
+ const texture=new DataTexture(new Uint8Array(data),info.width,info.height);
20
+ const sampler=parser.json.samplers?.[definition.sampler] || {};
21
+ texture.magFilter=filters[sampler.magFilter] || LinearFilter;
22
+ texture.minFilter=filters[sampler.minFilter] || LinearMipmapLinearFilter;
23
+ texture.wrapS=wrapping[sampler.wrapS] || RepeatWrapping;
24
+ texture.wrapT=wrapping[sampler.wrapT] || RepeatWrapping;
25
+ texture.flipY=false;
26
+ texture.name=definition.name || source.name || '';
27
+ texture.needsUpdate=true;
28
+ parser.associations.set(texture,{textures:index});
29
+ return texture;
30
+ }
31
+ }));
32
+ return {
33
+ async loadBytes(bytes) {
34
+ const buffer=bytes.buffer.slice(bytes.byteOffset,bytes.byteOffset+bytes.byteLength);
35
+ const gltf=await loader.parseAsync(buffer,'');
36
+ if(!gltf.scene)throw new Error('ASSET_SCENE_MISSING');
37
+ gltf.scene.animations=[...(gltf.animations || [])];
38
+ return gltf.scene;
39
+ },
40
+ async loadScene(url) {
41
+ const gltf=await loader.loadAsync(url);
42
+ if(!gltf.scene) throw new Error('ASSET_SCENE_MISSING');
43
+ gltf.scene.animations=[...(gltf.animations || [])];
44
+ return gltf.scene;
45
+ }
46
+ };
47
+ }
@@ -0,0 +1,132 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { setImmediate as yieldLoop } from 'node:timers/promises';
3
+ import { createSession } from '../../application/createSession.js';
4
+ import { AgentTools } from '../../application/AgentTools.js';
5
+ import { createAssetModule } from '../../modules/asset/AssetModule.js';
6
+ import { assetManifests } from '../../modules/asset/registry/manifests/index.js';
7
+ import { createMonumentHall } from '../../modules/world/content/monumentHall.js';
8
+ import { WorldBuilder } from '../../modules/world/build/WorldBuilder.js';
9
+ import { createCodeExecutor } from './CodeExecutor.js';
10
+ import { installHeadlessAssetIO } from './HeadlessAssetIO.js';
11
+ import { createHeadlessGLTFLoader } from './HeadlessGLTFLoader.js';
12
+ export const authoringSkills = ['runAuthoringCode','listAuthoringNodes','prepareAuthoringAsset','promoteAuthoringNode','updateAuthoringEntity','verifyAuthoringEntity'];
13
+ export const allowedSkills = ['spawnAsset','moveObject','approachAndInteract','approachAndPickup','approachAndPlace','navigateTo','replaceAsset'];
14
+ export const criteria = [
15
+ {id:'valid',kind:'world-valid'},
16
+ {id:'open',kind:'interaction-verified',targetId:'cabinet_01',capability:'OPEN'},
17
+ {id:'pickup',kind:'interaction-verified',targetId:'cup_01',capability:'PICKUP'},
18
+ {id:'place',kind:'interaction-verified',targetId:'table_01',capability:'PLACE'},
19
+ {id:'support',kind:'relation-exists',subject:'cup_01',predicate:'ON',object:'table_01',surfaceId:'top'},
20
+ {id:'unresolved',kind:'no-unresolved'}
21
+ ];
22
+ export class HeadlessWorldHost {
23
+ static async create(options = {}) {
24
+ installHeadlessAssetIO();
25
+ const manifests=structuredClone(assetManifests);
26
+ const bytes=await readFile(new URL('../../public/assets/cabinet.glb',import.meta.url));
27
+ manifests.cabinet.source={kind:'glb',url:`data:model/gltf-binary;base64,${bytes.toString('base64')}`};
28
+ // Start with trusted template assets; later assets are compiled within this session.
29
+ const local=Object.fromEntries(['agent','cabinet','cup','table'].map(id=>[id,manifests[id]]));
30
+ const executor=options.executorFactory ? options.executorFactory() : createCodeExecutor({...options.codeExecution,configPath:options.sandboxConfig || 'D:/AgentScapeData/mcp-assets/sandbox.json'});
31
+ const session=createSession(null,{codeExecutor:executor,codeGLTFLoader:createHeadlessGLTFLoader(),authoringOptions:{executeCode:request=>executor.execute(request)},assetModule:createAssetModule({manifests:local,compiledStore:options.repository?.compiledStore(options.owner),manifestStore:null,libraryStore:null,gltfLoader:createHeadlessGLTFLoader()}),environmentFactory:o=>createMonumentHall({...o,loadAssets:false})});
32
+ const {world}=session;
33
+ const host=new HeadlessWorldHost(world,{...options,session,executor});
34
+ try { if(options.repository&&options.assetIds?.length)await options.repository.attach(options.owner,world.assetModule,options.assetIds);await world.init(); await host.prepare(); return host; }
35
+ catch(error) { host.close(); throw error; }
36
+ }
37
+ constructor(world,{maxSteps=12000,timeoutMs=30000,maxObjects=64,session,executor}={}) {
38
+ this.world=world; this.maxSteps=maxSteps; this.timeoutMs=timeoutMs; this.maxObjects=maxObjects;
39
+ this.session=session; this.executor=executor;
40
+ this.authoringSources=[];
41
+ world.policy.profiles.set('remote',new Set(['world.read','world.write','spatial.read','physics.read','asset.read','asset.write']));
42
+ this.actionCount=0; this.unresolved=new Map();
43
+ world.lastTaskObservation={unresolvedMutations:[]};
44
+ this.tools=new AgentTools(world,{profile:'remote',actor:'agent_01',source:'remote-mcp'});
45
+ }
46
+ async prepare() {
47
+ const ir={schema:'agentscape.world-ir',schemaVersion:1,revision:{id:'remote-monument-r1',reason:'trusted offline template'},provenance:{source:'remote-mcp',createdBy:'AgentScape',evidenceRefs:[]},intent:{name:'Remote Monument Hall',description:'Open cabinet, pick up cup, place on table'},policy:{generation:{generate:false},physics:{fallbackPolicy:'deny'}},entities:[
48
+ {id:'agent_01',asset:{assetId:'agent'},transform:{position:[0,0,9]},capabilityIntent:[],initialState:{}},
49
+ {id:'cabinet_01',asset:{assetId:'cabinet'},transform:{position:[-5.2,0,3.9]},capabilityIntent:['OPEN'],initialState:{}},
50
+ {id:'cup_01',asset:{assetId:'cup'},capabilityIntent:['PICKUP'],initialState:{}},
51
+ {id:'table_01',asset:{assetId:'table'},transform:{position:[5.2,0,4.2]},capabilityIntent:[],initialState:{}}
52
+ ],spatial:{relations:[{subject:'cup_01',predicate:'INSIDE',object:'cabinet_01',receptacleId:'interior'}],constraints:[]},interactions:[],rules:[],acceptance:[]};
53
+ const result=await new WorldBuilder(this.world).run(ir);
54
+ if(result.pipeline.state.reports.worldAdmission.status==='rejected') throw new Error('TEMPLATE_REJECTED');
55
+ }
56
+ async execute(skill,args,signal) {
57
+ if(this.closed) throw new Error('HOST_CLOSED');
58
+ if(signal?.aborted)throw new Error('ACTION_CANCELLED');
59
+ if(![...allowedSkills,...authoringSkills].includes(skill)) throw new Error('SKILL_FORBIDDEN');
60
+ if(++this.actionCount>256) throw new Error('ACTION_BUDGET_EXHAUSTED');
61
+ if(['spawnAsset','promoteAuthoringNode'].includes(skill) && this.world.store.list().length>=this.maxObjects) throw new Error('OBJECT_LIMIT');
62
+ if(['prepareAuthoringAsset','promoteAuthoringNode','updateAuthoringEntity'].includes(skill) && this.world.assetModule.registry.size>=32) throw new Error('ASSET_LIMIT');
63
+ if (skill==='runAuthoringCode' && this.authoringSources.reduce((n,s)=>n+s.code.length,0)+args.code.length>262144) throw new Error('AUTHORING_SOURCE_LIMIT');
64
+ if (authoringSkills.includes(skill)) {
65
+ if (signal?.aborted) throw new Error('ACTION_CANCELLED');
66
+ const cancel=()=>this.executor?.close();
67
+ signal?.addEventListener('abort',cancel,{once:true});
68
+ try {
69
+ const result=await this.tools.call(skill,args);
70
+ if (skill==='runAuthoringCode' && result.status==='authoring-code-applied') this.authoringSources.push({code:args.code,label:args.label,revision:result.revision});
71
+ // Authored asset admission and behavior evidence remain distinct from transport success.
72
+ return {state:this.tools.executionPolicy(skill,result).outcome.state,result,tick:this.world.simulation.tick};
73
+ } finally { signal?.removeEventListener('abort',cancel); }
74
+ }
75
+ let done=false,result,error;
76
+ const pending=this.scene.executeSkill(skill,args).then(v=>{done=true;result=v;},e=>{done=true;error=e;});
77
+ // 资源替换是异步结构事务,不需要推进物理帧;避免回滚时并发更新 World。
78
+ if(skill==='replaceAsset') await pending;
79
+ const start=performance.now();
80
+ let steps=0;
81
+ let termination=null,cleanupSteps=0;
82
+ while(!done) {
83
+ if(signal?.aborted || steps>=this.maxSteps || performance.now()-start>this.timeoutMs) termination ||= signal?.aborted?'ACTION_CANCELLED':'ACTION_TIMEOUT';
84
+ if(termination) {
85
+ this.world.interactions.cancelPending('REMOTE_CANCELLED'); this.world.locomotion.cancelAll('REMOTE_CANCELLED');
86
+ this.executor?.close();
87
+ if(++cleanupSteps>240) { this.close(); break; }
88
+ }
89
+ this.world.simulation.step(); steps++;
90
+ if(steps%12===0) await yieldLoop(); else await Promise.resolve();
91
+ }
92
+ if(termination) {
93
+ this.unresolved.set(JSON.stringify([skill,args]),{tool:skill,args,state:'failed',reason:termination});
94
+ this.world.lastTaskObservation={unresolvedMutations:[...this.unresolved.values()]};
95
+ throw new Error(termination);
96
+ }
97
+ const outcome=error?{state:'failed'}:this.tools.executionPolicy(skill,result).outcome;
98
+ const key=JSON.stringify([skill,args]);
99
+ if(outcome.state==='verified') this.unresolved.delete(key); else this.unresolved.set(key,{tool:skill,args,state:outcome.state});
100
+ this.world.lastTaskObservation={unresolvedMutations:[...this.unresolved.values()]};
101
+ if(error) throw error;
102
+ return {state:outcome.state,result,steps,tick:this.world.simulation.tick};
103
+ }
104
+ observe(offset=0,limit=25) {
105
+ const ids=this.scene.observe().objects.map(object=>object.id),page=ids.slice(offset,offset+limit);
106
+ return {environmentId:this.world.environment.id,tick:this.world.simulation.tick,objects:page.map(id=>this.world.queries.getObjectInfo(id)),agent:this.world.observation.actor('agent_01'),relations:this.world.observation.relations(page,{limit:100}),total:ids.length,nextOffset:offset+limit<ids.length?offset+limit:null};
107
+ }
108
+ inspect(id) { if(!this.world.queries.hasObject(id)) throw new Error('OBJECT_NOT_FOUND'); return {object:this.world.queries.getObjectInfo(id),articulation:this.world.observation.articulation(id),relations:this.world.observation.relations([id],{limit:100})}; }
109
+ async verify(checks=criteria) {
110
+ const evidence=await this.scene.executeSkill('evaluateWorldAcceptance',{criteria:checks});
111
+ const carry=this.world.queries.carryStatus('agent_01');
112
+ return {state:evidence.status==='world-accepted' && (checks!==criteria || carry.status==='empty')?'verified':'unverified',evidence,carry};
113
+ }
114
+ close() { if(!this.closed) {this.closed=true; this.executor?.close(); this.session?.promotion?.dispose(); this.session?.authoring?.dispose(); this.world.dispose();} }
115
+ get scene() { if(this.closed) throw new Error('HOST_CLOSED'); return this.session.scene; }
116
+ startSceneInteraction(input) {
117
+ const job=this.scene.interact(input);
118
+ this.pumpSceneJob(job.id).catch(()=>this.close());
119
+ return job;
120
+ }
121
+ async pumpSceneJob(id) {
122
+ const start=performance.now(); let steps=0,cleanup=0;
123
+ while(!this.closed && this.scene.getJob(id).status==='running') {
124
+ if(steps>=this.maxSteps || performance.now()-start>this.timeoutMs) {
125
+ this.scene.cancelJob(id);
126
+ if(++cleanup>240) { this.close(); return; }
127
+ }
128
+ this.scene.step(); steps++;
129
+ if(steps%12===0) await yieldLoop(); else await Promise.resolve();
130
+ }
131
+ }
132
+ }
@@ -0,0 +1,6 @@
1
+ import { createCodeExecutor } from './CodeExecutor.js';
2
+
3
+ // Compatibility name; WASM/Worker isolation is not OS isolation.
4
+ export function createIsolatedAuthoringExecutor(options = {}) {
5
+ return createCodeExecutor({ ...options, mode: 'worker-wasm' });
6
+ }