@inneranimalmedia/agentsam-sdk 2.6.5 → 2.6.7

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 (371) hide show
  1. package/AGENTSAM.md +29 -0
  2. package/apps/README.md +5 -0
  3. package/apps/cad-creator/README.md +4 -4
  4. package/apps/cad-creator/shared/cad/package.json +1 -1
  5. package/apps/client-cms-editor/AGENTS.md +12 -7
  6. package/apps/client-cms-editor/README.md +76 -48
  7. package/apps/client-cms-editor/agentsam.app.json +26 -9
  8. package/apps/client-cms-editor/backend/package.json +20 -3
  9. package/apps/client-cms-editor/backend/src/api/client.ts +134 -101
  10. package/apps/client-cms-editor/backend/src/index.ts +1 -1
  11. package/apps/client-cms-editor/backend/src/model.ts +11 -115
  12. package/apps/client-cms-editor/backend/src/preview/bridge.ts +1 -1
  13. package/apps/client-cms-editor/backend/tsconfig.json +6 -1
  14. package/apps/client-cms-editor/bin/agentsam-cms.js +262 -0
  15. package/apps/client-cms-editor/bin/agentsam-cms.mjs +2 -228
  16. package/apps/client-cms-editor/frontend/package.json +16 -7
  17. package/apps/client-cms-editor/frontend/src/AgentSamDrawer.tsx +9 -41
  18. package/apps/client-cms-editor/frontend/src/CmsAgentSurface.tsx +19 -174
  19. package/apps/client-cms-editor/frontend/src/adapters/heuristic.ts +29 -0
  20. package/apps/client-cms-editor/frontend/src/adapters/http.ts +628 -0
  21. package/apps/client-cms-editor/frontend/src/adapters/memory.ts +510 -0
  22. package/apps/client-cms-editor/frontend/src/editor/CmsEditor.tsx +213 -0
  23. package/apps/client-cms-editor/frontend/src/editor/CmsEditorProvider.tsx +20 -0
  24. package/apps/client-cms-editor/frontend/src/editor/canvas/PreviewCanvas.tsx +53 -0
  25. package/apps/client-cms-editor/frontend/src/{CmsEditor.tsx → editor/legacy/CmsEditorPrototype.tsx} +52 -23
  26. package/apps/client-cms-editor/frontend/src/editor/useCmsEditorController.ts +218 -0
  27. package/apps/client-cms-editor/frontend/src/index.ts +19 -5
  28. package/apps/client-cms-editor/frontend/src/lib/agent-host.ts +24 -0
  29. package/apps/client-cms-editor/frontend/src/main.tsx +82 -8
  30. package/apps/client-cms-editor/frontend/src/mount.tsx +92 -30
  31. package/apps/client-cms-editor/frontend/src/styles/agentsam-drawer.css +1 -1
  32. package/apps/client-cms-editor/frontend/src/styles/cmsShell.css +8 -8
  33. package/apps/client-cms-editor/frontend/src/styles/studio.css +55 -3
  34. package/apps/client-cms-editor/frontend/tsconfig.json +12 -1
  35. package/apps/client-cms-editor/frontend/vite.config.ts +12 -0
  36. package/apps/client-cms-editor/package-lock.json +973 -134
  37. package/apps/client-cms-editor/package.json +118 -6
  38. package/apps/client-cms-editor/reference/harvest/HARVEST_RECEIPT.json +201 -0
  39. package/apps/client-cms-editor/reference/harvest/PROVENANCE_HISTORY.txt +10 -0
  40. package/apps/client-cms-editor/reference/harvest/README.md +8 -0
  41. package/apps/client-cms-editor/reference/harvest/plans/ARCHIVE-INTAKE.md +135 -0
  42. package/apps/client-cms-editor/reference/harvest/plans/CHATGPT-IDENTITY-HARVEST.md +83 -0
  43. package/apps/client-cms-editor/reference/harvest/plans/CMS-EDITOR-HARVEST.md +166 -0
  44. package/apps/client-cms-editor/reference/harvest/plans/HARVEST-INDEX.md +196 -0
  45. package/apps/client-cms-editor/reference/harvest/plans/INNERANIMALS-CONTENT-001.md +137 -0
  46. package/apps/client-cms-editor/reference/harvest/plans/NO-IMPLICIT-SIDE-EFFECTS.md +87 -0
  47. package/apps/client-cms-editor/reference/harvest/plans/STOREFRONT-SURFACE-MAP.md +140 -0
  48. package/apps/client-cms-editor/reference/harvest/plans/THEME-INNERANIMALS-HARVEST.md +137 -0
  49. package/apps/client-cms-editor/reference/harvest/plans/TOOLING-LAB.md +63 -0
  50. package/apps/client-cms-editor/reference/harvest/plans/harvest-manifest.json +97 -0
  51. package/apps/client-cms-editor/reference/harvest/plans/local-cms-harvest-schema.sql +328 -0
  52. package/apps/client-cms-editor/shared/cms/package.json +17 -7
  53. package/apps/client-cms-editor/shared/cms/src/adapter.ts +204 -0
  54. package/apps/client-cms-editor/shared/cms/src/agent-context.ts +7 -5
  55. package/apps/client-cms-editor/shared/cms/src/editor-types.ts +32 -0
  56. package/apps/client-cms-editor/shared/cms/src/host.ts +82 -0
  57. package/apps/client-cms-editor/shared/cms/src/index.ts +4 -0
  58. package/apps/client-cms-editor/shared/cms/src/map.ts +115 -0
  59. package/apps/client-cms-editor/shared/cms/src/starter-pack.ts +158 -0
  60. package/contracts/source-types.v1.json +353 -0
  61. package/docs/CMS_CONTEXTUAL_COMPOSER.md +1 -1
  62. package/docs/PRODUCT_LIFECYCLE.md +566 -0
  63. package/docs/THEME_REFINERY.md +2 -2
  64. package/docs/architecture/AGENTSAM_RUNTIME_PROTOCOL.md +40 -20
  65. package/docs/content-studio/REVISION_GATE_2026-09-27.md +1 -1
  66. package/docs/plans/LOCAL_STUDIO_DESKTOP_RELEASE_2026-09-29.md +150 -0
  67. package/migrations/d1/0017_identity_native_oauth.sql +21 -0
  68. package/native/agentsam-machine/Cargo.lock +426 -0
  69. package/native/agentsam-machine/Cargo.toml +9 -0
  70. package/native/agentsam-machine/cli/Cargo.toml +14 -0
  71. package/native/agentsam-machine/cli/src/main.rs +77 -0
  72. package/native/agentsam-machine/core/Cargo.toml +15 -0
  73. package/native/agentsam-machine/core/src/assets.rs +790 -0
  74. package/native/agentsam-machine/core/src/bound.rs +298 -0
  75. package/native/agentsam-machine/core/src/enrich.rs +706 -0
  76. package/native/agentsam-machine/core/src/frontend.rs +442 -0
  77. package/native/agentsam-machine/core/src/lib.rs +1086 -0
  78. package/native/agentsam-machine/core/src/liquid.rs +528 -0
  79. package/native/agentsam-machine/core/src/source_types.rs +78 -0
  80. package/package.json +51 -21
  81. package/packages/agentsam-brand/README.md +1 -1
  82. package/packages/agentsam-brand/package.json +4 -4
  83. package/packages/agentsam-brand/src/index.js +1 -1
  84. package/packages/agentsam-contracts/package.json +13 -3
  85. package/packages/agentsam-contracts/src/tools.ts +22 -0
  86. package/packages/agentsam-errors/package.json +13 -3
  87. package/packages/agentsam-knowledge/package.json +18 -4
  88. package/packages/agentsam-knowledge/src/autorag/index.js +10 -3
  89. package/packages/agentsam-knowledge/src/backends/index.js +33 -1
  90. package/packages/agentsam-knowledge/test/autorag.test.mjs +60 -1
  91. package/packages/agentsam-nav/package.json +24 -6
  92. package/packages/agentsam-queue-control/README.md +1 -1
  93. package/packages/agentsam-queue-control/package.json +7 -2
  94. package/packages/agentsam-rapid-rust/src/main.rs +1 -1
  95. package/packages/agentsam-repository/package.json +13 -3
  96. package/packages/agentsam-repository/src/source-types.js +8 -0
  97. package/packages/agentsam-vault/package.json +14 -4
  98. package/packages/agentsam-workbench/package.json +15 -4
  99. package/packages/agentsam-workbench/src/agent/ToolPermissionRequest.tsx +94 -0
  100. package/packages/agentsam-workbench/src/agent/index.ts +2 -0
  101. package/packages/agentsam-workbench/src/agent/tool-permission.css +134 -0
  102. package/packages/connectors/cloudflare/package.json +13 -3
  103. package/packages/connectors/cloudflare/src/api-client.js +3 -2
  104. package/packages/connectors/cloudflare/src/families/vectorize.js +127 -0
  105. package/packages/connectors/cloudflare/src/index.js +1 -0
  106. package/packages/heuristic-theme/README.md +2 -2
  107. package/packages/heuristic-theme/package.json +8 -3
  108. package/packages/heuristic-theme/src/registry.js +2 -2
  109. package/packages/heuristic-theme/src/theme.js +1 -1
  110. package/packages/heuristic-theme/test/theme.test.mjs +1 -1
  111. package/packages/identity/.agentsam/features/oauth-login-portal/agentsam.feature.json +1 -1
  112. package/packages/identity/.agentsam/features/oauth-login-portal/providers.json +27 -7
  113. package/packages/identity/README.md +2 -2
  114. package/packages/identity/migrations/D1_SCHEMA_MAPPING.md +18 -15
  115. package/packages/identity/migrations/apply-portable.js +109 -0
  116. package/packages/identity/migrations/sqlite/004_identity_oauth_consent_catalog.sql +1 -1
  117. package/packages/identity/migrations/sqlite/005_identity_company_native.sql +52 -0
  118. package/packages/identity/package.json +27 -6
  119. package/packages/identity/schema/agentsam.identity/manifest.json +101 -0
  120. package/packages/identity/scripts/local-identity-bridge.mjs +13 -7
  121. package/packages/identity/scripts/preview-auth-portal.mjs +6 -6
  122. package/packages/identity/src/adapters/cloudflare-d1/index.js +8 -401
  123. package/packages/identity/src/adapters/iam-compat/index.js +540 -0
  124. package/packages/identity/src/adapters/portable-d1/index.js +18 -0
  125. package/packages/identity/src/adapters/portable-store.js +479 -0
  126. package/packages/identity/src/adapters/sqlite/index.js +13 -312
  127. package/packages/identity/src/contracts/auth-config.js +0 -1
  128. package/packages/identity/src/contracts/identity-store.js +56 -5
  129. package/packages/identity/src/contracts/provider.js +1 -0
  130. package/packages/identity/src/contracts/sign-in-options.js +104 -0
  131. package/packages/identity/src/core/constants.js +1 -1
  132. package/packages/identity/src/core/session-policy.js +31 -0
  133. package/packages/identity/src/frontend/auth-portal/pages/login.html +6 -6
  134. package/packages/identity/src/frontend/auth-portal/pages/reset.html +5 -5
  135. package/packages/identity/src/frontend/auth-portal/pages/signup.html +5 -5
  136. package/packages/identity/src/frontend/auth-portal/shared/company-branding.js +1 -1
  137. package/packages/identity/src/frontend/auth-portal/shared/desktop-identity-bridge.js +6 -37
  138. package/packages/identity/src/index.js +28 -1
  139. package/packages/identity/src/migrations/README.md +23 -23
  140. package/packages/identity/src/oauth/README.md +1 -1
  141. package/packages/identity/src/oauth/credentials.js +10 -11
  142. package/packages/identity/src/oauth/google-desktop-exchange.js +195 -27
  143. package/packages/identity/src/oauth/iam-platform.js +21 -9
  144. package/packages/identity/src/oauth/native-handoff.js +136 -0
  145. package/packages/identity/src/providers/chatgpt/headers.js +65 -0
  146. package/packages/identity/src/providers/chatgpt/index.js +86 -0
  147. package/packages/identity/src/providers/chatgpt/mapper.js +43 -0
  148. package/packages/identity/src/providers/chatgpt/paths.js +45 -0
  149. package/packages/identity/src/providers/github/oauth.js +1 -2
  150. package/packages/identity/src/providers/github/profile.js +16 -2
  151. package/packages/identity/src/providers/index.js +11 -3
  152. package/packages/identity/src/server/identity-service.js +2 -1
  153. package/packages/identity/src/server/worker-router.js +71 -18
  154. package/packages/identity/tests/chatgpt-provider.test.mjs +75 -0
  155. package/packages/identity/tests/google-desktop-identity-login.test.mjs +210 -0
  156. package/packages/identity/tests/identity-init-scaffold.test.mjs +15 -4
  157. package/packages/identity/tests/lane1-identity-store-parity.test.mjs +527 -0
  158. package/packages/identity/tests/lane1-packed-consumer.test.mjs +175 -0
  159. package/packages/identity/tests/native-oauth-handoff.test.mjs +292 -0
  160. package/packages/identity/tests/oauth-credentials.test.mjs +4 -4
  161. package/packages/identity/tests/preview-auth-portal.test.mjs +4 -2
  162. package/packages/identity/tests/session-routes-policy.test.mjs +13 -1
  163. package/packages/identity/tests/worker-runtime-boundary.test.mjs +11 -0
  164. package/packages/providers/completeful/package.json +7 -2
  165. package/packages/theme-church-site/package.json +17 -6
  166. package/packages/theme-church-site/src/harvest.json +4 -2
  167. package/packages/theme-church-site/src/index.js +7 -3
  168. package/packages/theme-church-site/test/theme.test.mjs +4 -2
  169. package/packages/theme-companions-site/package.json +17 -6
  170. package/packages/theme-companions-site/src/harvest.json +4 -2
  171. package/packages/theme-companions-site/src/index.js +7 -3
  172. package/packages/theme-companions-site/test/theme.test.mjs +4 -2
  173. package/packages/theme-floors-site/package.json +17 -6
  174. package/packages/theme-floors-site/src/harvest.json +4 -2
  175. package/packages/theme-floors-site/src/index.js +7 -3
  176. package/packages/theme-floors-site/test/theme.test.mjs +4 -2
  177. package/packages/theme-fuelnfree-site/package.json +17 -6
  178. package/packages/theme-fuelnfree-site/src/harvest.json +4 -2
  179. package/packages/theme-fuelnfree-site/src/index.js +7 -3
  180. package/packages/theme-fuelnfree-site/test/theme.test.mjs +4 -2
  181. package/packages/theme-handyman-site/package.json +17 -6
  182. package/packages/theme-handyman-site/src/harvest.json +4 -2
  183. package/packages/theme-handyman-site/src/index.js +7 -3
  184. package/packages/theme-handyman-site/test/theme.test.mjs +4 -2
  185. package/packages/theme-insurance-site/package.json +17 -6
  186. package/packages/theme-insurance-site/src/harvest.json +4 -2
  187. package/packages/theme-insurance-site/src/index.js +7 -3
  188. package/packages/theme-insurance-site/test/theme.test.mjs +4 -2
  189. package/packages/theme-scenes/README.md +1 -1
  190. package/packages/theme-scenes/package.json +4 -3
  191. package/packages/theme-scenes/src/registry.js +187 -0
  192. package/packages/theme-shinshu-site/package.json +17 -6
  193. package/packages/theme-shinshu-site/src/harvest.json +4 -2
  194. package/packages/theme-shinshu-site/src/index.js +7 -3
  195. package/packages/theme-shinshu-site/test/theme.test.mjs +4 -2
  196. package/packages/work-graph/package.json +14 -4
  197. package/protocol/FILEMETA_V1.md +2 -2
  198. package/protocol/capabilities/manifest.json +1 -1
  199. package/protocol/database/agentsam.schema-pack.v1.schema.json +72 -0
  200. package/protocol/presets/catalog.json +2 -2
  201. package/protocol/theme-refinery/lineage-registry.json +105 -0
  202. package/protocol/theme-refinery/product-metadata.schema.json +21 -1
  203. package/skills/grok-auth/SKILL.md +110 -0
  204. package/skills/grok-auth/agentsam.skill.json +25 -0
  205. package/skills/grok-auth/references/grok-identity.md +64 -0
  206. package/skills/grok-auth/references/per-user-data.md +49 -0
  207. package/skills/grok-auth/references/prewired-and-env.md +54 -0
  208. package/skills/grok-auth/references/session-ui.md +133 -0
  209. package/skills/grok-auth/references/sign-in-methods.md +55 -0
  210. package/skills/grok-auth/references/wiring.md +71 -0
  211. package/skills/grok-building-games/SKILL.md +213 -0
  212. package/skills/grok-building-games/agentsam.skill.json +25 -0
  213. package/skills/grok-building-games/references/3d-libs.md +64 -0
  214. package/skills/grok-building-games/references/ai-pathfinding.md +122 -0
  215. package/skills/grok-building-games/references/audio.md +129 -0
  216. package/skills/grok-building-games/references/babylon.md +202 -0
  217. package/skills/grok-building-games/references/collision-physics.md +122 -0
  218. package/skills/grok-building-games/references/ecs-architecture.md +111 -0
  219. package/skills/grok-building-games/references/game-feel-juice.md +110 -0
  220. package/skills/grok-building-games/references/genres/board-card-chess.md +89 -0
  221. package/skills/grok-building-games/references/genres/endless-runner.md +83 -0
  222. package/skills/grok-building-games/references/genres/fps.md +105 -0
  223. package/skills/grok-building-games/references/genres/platformer-2d.md +97 -0
  224. package/skills/grok-building-games/references/genres/puzzle-match3-tetris.md +131 -0
  225. package/skills/grok-building-games/references/genres/racing-kart.md +106 -0
  226. package/skills/grok-building-games/references/genres/topdown-twin-stick.md +97 -0
  227. package/skills/grok-building-games/references/genres/tower-defense.md +84 -0
  228. package/skills/grok-building-games/references/genres/voxel-minecraft.md +89 -0
  229. package/skills/grok-building-games/references/input.md +139 -0
  230. package/skills/grok-building-games/references/phaser.md +277 -0
  231. package/skills/grok-building-games/references/procedural-generation.md +141 -0
  232. package/skills/grok-building-games/references/save-persistence.md +108 -0
  233. package/skills/grok-building-games/references/threejs-foundational.md +148 -0
  234. package/skills/grok-controls/SKILL.md +274 -0
  235. package/skills/grok-controls/agentsam.skill.json +25 -0
  236. package/skills/grok-design-ui/SKILL.md +122 -0
  237. package/skills/grok-design-ui/agentsam.skill.json +25 -0
  238. package/skills/grok-design-ui/references/animations.md +379 -0
  239. package/skills/grok-design-ui/references/performance.md +88 -0
  240. package/skills/grok-design-ui/references/refined-ui.md +384 -0
  241. package/skills/grok-design-ui/references/surfaces.md +247 -0
  242. package/skills/grok-design-ui/references/typography.md +123 -0
  243. package/skills/grok-game-animation-frames/SKILL.md +84 -0
  244. package/skills/grok-game-animation-frames/agentsam.skill.json +25 -0
  245. package/skills/grok-game-asset-core/SKILL.md +69 -0
  246. package/skills/grok-game-asset-core/agentsam.skill.json +25 -0
  247. package/skills/grok-game-character-consistency/SKILL.md +69 -0
  248. package/skills/grok-game-character-consistency/agentsam.skill.json +25 -0
  249. package/skills/grok-game-tilesets/SKILL.md +65 -0
  250. package/skills/grok-game-tilesets/agentsam.skill.json +25 -0
  251. package/skills/grok-game-ui-icons/SKILL.md +56 -0
  252. package/skills/grok-game-ui-icons/agentsam.skill.json +25 -0
  253. package/skills/grok-generate2dmap/LICENSE +21 -0
  254. package/skills/grok-generate2dmap/SKILL.md +120 -0
  255. package/skills/grok-generate2dmap/SOURCE.md +6 -0
  256. package/skills/grok-generate2dmap/agentsam.skill.json +25 -0
  257. package/skills/grok-generate2dmap/references/deliverables.md +101 -0
  258. package/skills/grok-generate2dmap/references/layered-map-contract.md +209 -0
  259. package/skills/grok-generate2dmap/references/map-strategies.md +341 -0
  260. package/skills/grok-generate2dmap/references/object-production-gate.md +24 -0
  261. package/skills/grok-generate2dmap/references/pipeline.md +149 -0
  262. package/skills/grok-generate2dmap/references/prop-pack-contract.md +174 -0
  263. package/skills/grok-generate2dmap/references/side-scroll-stages.md +29 -0
  264. package/skills/grok-generate2dmap/scripts/compose_layered_preview.py +157 -0
  265. package/skills/grok-generate2dmap/scripts/extract_prop_pack.py +369 -0
  266. package/skills/grok-generate2dsprite/LICENSE +21 -0
  267. package/skills/grok-generate2dsprite/SKILL.md +313 -0
  268. package/skills/grok-generate2dsprite/SOURCE.md +6 -0
  269. package/skills/grok-generate2dsprite/agentsam.skill.json +25 -0
  270. package/skills/grok-generate2dsprite/references/modes.md +124 -0
  271. package/skills/grok-generate2dsprite/references/prompt-rules.md +315 -0
  272. package/skills/grok-generate2dsprite/scripts/generate2dsprite.py +1031 -0
  273. package/skills/grok-generate2dsprite/scripts/make_layout_guide.py +109 -0
  274. package/skills/grok-imagine/SKILL.md +201 -0
  275. package/skills/grok-imagine/agentsam.skill.json +25 -0
  276. package/skills/grok-multiplayer-p2p/SKILL.md +111 -0
  277. package/skills/grok-multiplayer-p2p/agentsam.skill.json +25 -0
  278. package/skills/grok-multiplayer-p2p/references/react-binding.md +144 -0
  279. package/skills/grok-multiplayer-p2p/references/signaling-relay.md +269 -0
  280. package/skills/grok-neon/SKILL.md +157 -0
  281. package/skills/grok-neon/agentsam.skill.json +25 -0
  282. package/skills/grok-og/SKILL.md +102 -0
  283. package/skills/grok-og/agentsam.skill.json +25 -0
  284. package/skills/grok-og/references/brand-pass.md +53 -0
  285. package/skills/grok-og/references/custom-card.md +107 -0
  286. package/skills/grok-og/references/favicon-and-icons.md +48 -0
  287. package/skills/grok-og/references/og-type-contract.md +18 -0
  288. package/skills/grok-og/references/placeholder-card.md +21 -0
  289. package/skills/grok-og/references/x-banner.md +41 -0
  290. package/skills/grok-threejs/SKILL.md +67 -0
  291. package/skills/grok-threejs/agentsam.skill.json +25 -0
  292. package/skills/grok-threejs/references/llms-full.txt +2780 -0
  293. package/skills/grok-video2dsprite/LICENSE +21 -0
  294. package/skills/grok-video2dsprite/SKILL.md +236 -0
  295. package/skills/grok-video2dsprite/SOURCE.md +6 -0
  296. package/skills/grok-video2dsprite/agentsam.skill.json +25 -0
  297. package/skills/grok-video2dsprite/references/pipeline.md +90 -0
  298. package/skills/grok-video2dsprite/references/prompt-rules.md +63 -0
  299. package/skills/grok-video2dsprite/scripts/video2dsprite.py +490 -0
  300. package/skills/grok-xai-api/SKILL.md +152 -0
  301. package/skills/grok-xai-api/agentsam.skill.json +25 -0
  302. package/src/cli/command-catalog.js +46 -4
  303. package/src/cli/dispatch.js +1 -0
  304. package/src/cli.js +10 -0
  305. package/src/cloudflare/runtime-status.js +2 -1
  306. package/src/commands/autorag.js +67 -13
  307. package/src/commands/cheat-sheet.js +29 -4
  308. package/src/commands/codebaseindex.js +45 -2
  309. package/src/commands/knowledge.js +59 -2
  310. package/src/commands/machine-binary.js +103 -0
  311. package/src/commands/machine.js +137 -0
  312. package/src/commands/security.js +67 -4
  313. package/src/commands/setup.js +33 -16
  314. package/src/commands/status.js +8 -1
  315. package/src/features/resolve.js +1 -0
  316. package/src/knowledge/engine.js +21 -2
  317. package/src/knowledge/runtime-discovery.js +127 -0
  318. package/src/lib/identity-scaffold.js +53 -13
  319. package/src/lib/setup/recipes.js +1 -1
  320. package/src/models/discovery.js +40 -22
  321. package/src/models/inventory-core.d.ts +105 -0
  322. package/src/models/inventory-core.js +54 -6
  323. package/src/security/logs.js +3 -0
  324. package/src/ui/cli/help.js +41 -0
  325. package/test/apps-scaffold-contract.test.mjs +3 -2
  326. package/test/cli/api-key-env-whoami.test.mjs +2 -2
  327. package/test/cli/catalog-authority.test.mjs +64 -0
  328. package/test/cli/machine-command.test.mjs +34 -0
  329. package/test/fixtures/project-authority/customer-app/.agentsam/app.json +5 -0
  330. package/test/fixtures/project-authority/customer-app/apps/my-product/index.ts +1 -0
  331. package/test/fixtures/project-authority/customer-app/wrangler.toml +17 -0
  332. package/test/integration/autorag-project-authority.integration.test.mjs +51 -0
  333. package/test/integration/autorag-runtime-discovery.test.mjs +107 -0
  334. package/test/integration/cms-app-scaffold.test.mjs +37 -31
  335. package/test/integration/cms-site-tenancy-contract.test.mjs +28 -17
  336. package/test/integration/codebaseindex-ingest.test.mjs +41 -0
  337. package/test/integration/database-hosted-honesty.test.mjs +49 -0
  338. package/test/integration/desktop-keychain-boundary.test.mjs +45 -0
  339. package/test/integration/hosted-work-host-authority.test.mjs +47 -0
  340. package/test/integration/inventory-eligibility.test.mjs +59 -0
  341. package/test/integration/local-provider-bridge.test.mjs +65 -0
  342. package/test/integration/local-studio-settings-production.test.mjs +40 -0
  343. package/test/integration/lockfile-sync.test.mjs +26 -0
  344. package/test/integration/provider-env-cli.test.mjs +13 -3
  345. package/test/integration/runtime-status.integration.test.mjs +16 -1
  346. package/test/integration/theme-package-registry.test.mjs +31 -0
  347. package/test/repository-snapshot-view.test.mjs +2 -2
  348. package/test/security.test.mjs +14 -0
  349. package/test/terminal-machine-identity.test.mjs +2 -2
  350. package/apps/client-cms-editor/backend/src/demo-bootstrap.ts +0 -145
  351. package/packages/agentsam-nav/dist/Nav.d.ts +0 -43
  352. package/packages/agentsam-nav/dist/NavCollapsible.d.ts +0 -10
  353. package/packages/agentsam-nav/dist/NavContent.d.ts +0 -2
  354. package/packages/agentsam-nav/dist/NavFooter.d.ts +0 -2
  355. package/packages/agentsam-nav/dist/NavGroup.d.ts +0 -3
  356. package/packages/agentsam-nav/dist/NavHeader.d.ts +0 -2
  357. package/packages/agentsam-nav/dist/NavMenu.d.ts +0 -22
  358. package/packages/agentsam-nav/dist/NavProvider.d.ts +0 -35
  359. package/packages/agentsam-nav/dist/NavTrigger.d.ts +0 -2
  360. package/packages/agentsam-nav/dist/Surfaces.d.ts +0 -41
  361. package/packages/agentsam-nav/dist/browser.d.ts +0 -11
  362. package/packages/agentsam-nav/dist/browser.global.js +0 -132
  363. package/packages/agentsam-nav/dist/browser.js +0 -613
  364. package/packages/agentsam-nav/dist/contracts.d.ts +0 -76
  365. package/packages/agentsam-nav/dist/index.d.ts +0 -11
  366. package/packages/agentsam-nav/dist/index.js +0 -614
  367. package/packages/agentsam-nav/dist/legacy.css +0 -83
  368. package/packages/agentsam-nav/dist/shell.css +0 -113
  369. package/packages/agentsam-nav/dist/theme.css +0 -113
  370. package/packages/agentsam-nav/dist/utils.d.ts +0 -1
  371. package/packages/agentsam-repository/src/goap.js.bak-20260922011251 +0 -670
@@ -0,0 +1,137 @@
1
+ /**
2
+ * agentsam machine — graduate the native Machine engine to the product CLI.
3
+ *
4
+ * Graduation rule: capability is complete when reachable through
5
+ * `agentsam machine …`, emits bounded deterministic receipts, and preserves evidence.
6
+ *
7
+ * Asset perception rule: discovery is read-only and network-free by default.
8
+ */
9
+
10
+ import path from 'node:path';
11
+ import { resolveMachineBinary, spawnMachine } from './machine-binary.js';
12
+
13
+ function usage() {
14
+ return `agentsam machine — deterministic local perception (native engine)
15
+
16
+ Usage:
17
+ agentsam machine inspect <path> [--json] [--run-id <id>] [--include-generated]
18
+ agentsam machine doctor [--json]
19
+ agentsam machine --help
20
+
21
+ Notes:
22
+ Default inspect is read-only and network-free.
23
+ Large detail is externalized under <target>/.agentsam/machine/runs/<run_id>/.
24
+ Generated/cache trees are summarized unless --include-generated is set.
25
+ Remote fetch/probe, optimization, storage, and reference rewriting are separate explicit actions.
26
+ Set AGENTSAM_MACHINE_BIN to force a specific agentsam-machine binary.`;
27
+ }
28
+
29
+ function parseArgs(argv = []) {
30
+ const out = {
31
+ help: false,
32
+ json: false,
33
+ includeGenerated: false,
34
+ runId: null,
35
+ subcommand: null,
36
+ target: null,
37
+ positionals: [],
38
+ };
39
+ for (let i = 0; i < argv.length; i += 1) {
40
+ const arg = argv[i];
41
+ if (arg === '--help' || arg === '-h') out.help = true;
42
+ else if (arg === '--json') out.json = true;
43
+ else if (arg === '--include-generated') out.includeGenerated = true;
44
+ else if (arg === '--run-id') {
45
+ const value = argv[++i];
46
+ if (value == null || value.startsWith('--')) {
47
+ throw new Error('--run-id requires a value');
48
+ }
49
+ out.runId = value;
50
+ } else if (arg.startsWith('-')) {
51
+ throw new Error(`unknown machine option: ${arg}`);
52
+ } else {
53
+ out.positionals.push(arg);
54
+ }
55
+ }
56
+ out.subcommand = out.positionals[0] || null;
57
+ out.target = out.positionals[1] || null;
58
+ return out;
59
+ }
60
+
61
+ function printTextDoctor(resolution) {
62
+ if (resolution.kind === 'binary') {
63
+ console.log(`agentsam-machine available (${resolution.source}): ${resolution.path}`);
64
+ console.log('capability: machine.inspect');
65
+ return;
66
+ }
67
+ if (resolution.kind === 'cargo') {
68
+ console.log(`agentsam-machine via cargo run (${resolution.source}): ${resolution.manifest}`);
69
+ console.log('capability: machine.inspect (dev fallback)');
70
+ return;
71
+ }
72
+ console.log('agentsam-machine unavailable');
73
+ console.log(`tried: ${(resolution.tried || []).join(', ')}`);
74
+ }
75
+
76
+ /**
77
+ * @param {string[]} argv
78
+ */
79
+ export async function runMachine(argv = []) {
80
+ const args = parseArgs(argv);
81
+ if (args.help || !args.subcommand) {
82
+ console.log(usage());
83
+ return 0;
84
+ }
85
+
86
+ const resolution = resolveMachineBinary();
87
+
88
+ if (args.subcommand === 'doctor') {
89
+ const payload = {
90
+ capability: 'machine.doctor',
91
+ available: resolution.kind !== 'missing',
92
+ resolution,
93
+ };
94
+ if (args.json) console.log(JSON.stringify(payload));
95
+ else printTextDoctor(resolution);
96
+ return resolution.kind === 'missing' ? 1 : 0;
97
+ }
98
+
99
+ if (args.subcommand === 'inspect') {
100
+ const target = args.target || process.cwd();
101
+ const abs = path.resolve(target);
102
+ const machineArgv = ['inspect', abs];
103
+ if (args.runId) machineArgv.push('--run-id', args.runId);
104
+ if (args.includeGenerated) machineArgv.push('--include-generated');
105
+ if (args.json) machineArgv.push('--json');
106
+
107
+ const result = spawnMachine(resolution, machineArgv, {
108
+ stdio: args.json ? ['ignore', 'pipe', 'pipe'] : 'inherit',
109
+ // Large donors still emit bounded compact JSON; raise buffer for safety.
110
+ maxBuffer: 32 * 1024 * 1024,
111
+ });
112
+
113
+ if (result.error) throw result.error;
114
+ if (args.json) {
115
+ const stdout = String(result.stdout || '');
116
+ const stderr = String(result.stderr || '');
117
+ if (result.status && result.status !== 0) {
118
+ const err = new Error(stderr.trim() || `agentsam-machine exited with code ${result.status}`);
119
+ err.exitCode = result.status;
120
+ throw err;
121
+ }
122
+ try {
123
+ const parsed = JSON.parse(stdout);
124
+ console.log(JSON.stringify(parsed));
125
+ } catch {
126
+ process.stdout.write(stdout);
127
+ }
128
+ if (stderr.trim()) process.stderr.write(stderr);
129
+ }
130
+ return result.status ?? 0;
131
+ }
132
+
133
+ console.log(usage());
134
+ const err = new Error(`Unknown machine subcommand: ${args.subcommand}`);
135
+ err.exitCode = 1;
136
+ throw err;
137
+ }
@@ -1,5 +1,4 @@
1
1
  import fs from 'node:fs';
2
- import { scanProjectSecurity, reportExitCode, repairProject, formatSecurityReport } from '../security/index.js';
3
2
  import { runProcess } from '../security/process.js';
4
3
  import { diagnosticFromError, renderDiagnosticError } from '../errors/index.js';
5
4
 
@@ -19,6 +18,54 @@ const help = [
19
18
  'Exit: 0 clean/verified, 1 unresolved findings or command failure, 2 incomplete/error.',
20
19
  ''
21
20
  ].join('\n');
21
+
22
+ async function loadSecurityModules() {
23
+ // Deferred until after any pre-install child command (e.g. npm ci) so the
24
+ // Merkle/TypeScript trust-boundary stack is not required before dependencies exist.
25
+ return import('../security/index.js');
26
+ }
27
+
28
+ /** Bootstrap-safe receipt when the child install/build command fails — never import the heavy scan stack. */
29
+ function bootstrapSafeCommandFailureReceipt(result, childArgs) {
30
+ const stdout = result.stdout || '';
31
+ const stderr = result.stderr || '';
32
+ return {
33
+ schema_version: 1,
34
+ ok: false,
35
+ complete: true,
36
+ status: 'command-failed',
37
+ command: childArgs,
38
+ command_exit_code: result.code,
39
+ signal: result.signal || null,
40
+ stdout,
41
+ stderr,
42
+ log: stdout + (stdout && stderr ? '\n' : '') + stderr,
43
+ issues: [`Child command exited with code ${result.code}`],
44
+ findings: [],
45
+ results: [],
46
+ dependency_count: 0,
47
+ checked_count: 0,
48
+ dependency_complete: false,
49
+ };
50
+ }
51
+
52
+ function formatCommandFailureReport(report) {
53
+ const lines = [
54
+ 'Agent Sam · security · COMMAND-FAILED',
55
+ '',
56
+ 'Command: ' + (Array.isArray(report.command) ? report.command.join(' ') : String(report.command || '')),
57
+ 'Exit code: ' + String(report.command_exit_code),
58
+ ];
59
+ if (report.signal) lines.push('Signal: ' + report.signal);
60
+ for (const issue of report.issues || []) lines.push(' ! ' + issue);
61
+ if (report.stderr) {
62
+ lines.push('', 'stderr:', report.stderr.trimEnd());
63
+ } else if (report.stdout) {
64
+ lines.push('', 'stdout:', report.stdout.trimEnd());
65
+ }
66
+ return lines.join('\n') + '\n';
67
+ }
68
+
22
69
  export async function runSecurity(argv) {
23
70
  const ownArgs = argv.slice(0, argv.indexOf('--') < 0 ? argv.length : argv.indexOf('--'));
24
71
  if (ownArgs.includes('--help') || ownArgs.includes('-h') || !argv.length) { process.stdout.write(help); return; }
@@ -52,13 +99,29 @@ export async function runSecurity(argv) {
52
99
  const abort = () => controller.abort();
53
100
  process.once('SIGINT', abort); process.once('SIGTERM', abort);
54
101
  let report;
102
+ let reportExitCode;
103
+ let formatSecurityReport;
55
104
  try {
56
105
  if (command === 'run') {
57
106
  const result = await runProcess(childArgs[0], childArgs.slice(1), { cwd: options.projectRoot || process.cwd(), signal: options.signal });
58
- report = await scanProjectSecurity({ ...options, log: result.stdout + '\n' + result.stderr });
107
+ // Child failure must surface as command-failed without importing Merkle/TypeScript.
108
+ if (result.code !== 0) {
109
+ report = bootstrapSafeCommandFailureReceipt(result, childArgs);
110
+ process.stdout.write(options.json ? JSON.stringify(report, null, 2) + '\n' : formatCommandFailureReport(report));
111
+ process.exitCode = 1;
112
+ return;
113
+ }
114
+ const security = await loadSecurityModules();
115
+ reportExitCode = security.reportExitCode;
116
+ formatSecurityReport = security.formatSecurityReport;
117
+ report = await security.scanProjectSecurity({ ...options, log: result.stdout + '\n' + result.stderr });
59
118
  report.command_exit_code = result.code;
60
- if (result.code) { report.ok = false; report.status = 'command-failed'; }
61
- } else report = command === 'repair' ? await repairProject(options) : await scanProjectSecurity(options);
119
+ } else {
120
+ const security = await loadSecurityModules();
121
+ reportExitCode = security.reportExitCode;
122
+ formatSecurityReport = security.formatSecurityReport;
123
+ report = command === 'repair' ? await security.repairProject(options) : await security.scanProjectSecurity(options);
124
+ }
62
125
  } finally {
63
126
  process.removeListener('SIGINT', abort); process.removeListener('SIGTERM', abort);
64
127
  }
@@ -18,11 +18,39 @@ import {
18
18
  RUNTIME_PROFILES,
19
19
  } from '../lib/setup/runtime.js';
20
20
  import { runRuntime } from './runtime.js';
21
+ import { getCliCommand } from '../cli/command-catalog.js';
21
22
 
22
23
  function writeLine(write, value = '') {
23
24
  write(`${value}\n`);
24
25
  }
25
26
 
27
+ function catalogCommand(id, args = '') {
28
+ const entry = getCliCommand(id);
29
+ if (!entry) throw new Error(`setup_next_command_not_catalogued: ${id}`);
30
+ return `agentsam ${entry.id}${args ? ` ${args}` : ''}`;
31
+ }
32
+
33
+ export function setupNextCommands(capabilityIds = []) {
34
+ const commands = [
35
+ catalogCommand('status'),
36
+ catalogCommand('capabilities'),
37
+ catalogCommand('google-cloud', 'doctor'),
38
+ ];
39
+ if (capabilityIds.includes('google.cloud')) {
40
+ commands.push(catalogCommand('setup', 'google.cloud --inventory'));
41
+ }
42
+ if (capabilityIds.includes('image.vectorize')) {
43
+ commands.push(catalogCommand('capabilities', 'image.vectorize'));
44
+ }
45
+ return [...new Set(commands)];
46
+ }
47
+
48
+ function writeSetupNext(write, capabilityIds = []) {
49
+ writeLine(write, ' Next');
50
+ for (const command of setupNextCommands(capabilityIds)) writeLine(write, ` ${command}`);
51
+ writeLine(write, '');
52
+ }
53
+
26
54
  function printHelp(write) {
27
55
  writeLine(write, '');
28
56
  writeLine(write, ' Agent Sam · setup');
@@ -220,9 +248,9 @@ export async function runSetup(argv = [], options = {}) {
220
248
  }
221
249
  writeLine(write, '');
222
250
  writeLine(write, ' Next');
223
- writeLine(write, ' agentsam gcloud auth login');
224
- writeLine(write, ' agentsam google-cloud connection set --identity EMAIL --project PROJECT');
225
- writeLine(write, ' agentsam google-cloud doctor');
251
+ writeLine(write, ` ${catalogCommand('google-cloud', 'auth login')}`);
252
+ writeLine(write, ` ${catalogCommand('google-cloud', 'connection set --identity EMAIL --project PROJECT')}`);
253
+ writeLine(write, ` ${catalogCommand('google-cloud', 'doctor')}`);
226
254
  writeLine(write, '');
227
255
  }
228
256
  return inv.errors?.length ? 2 : 0;
@@ -243,8 +271,7 @@ export async function runSetup(argv = [], options = {}) {
243
271
  if (dryRun || !plan.would_install.length) {
244
272
  if (!plan.would_install.length) {
245
273
  writeLine(write, ' ✓ setup complete — requested capabilities already satisfied');
246
- writeLine(write, ' Next: agentsam doctor · agentsam capabilities · agentsam google-cloud doctor');
247
- writeLine(write, '');
274
+ writeSetupNext(write, capabilityIds);
248
275
  }
249
276
  if (json) write(JSON.stringify({ environment, plan, executed: false }, null, 2) + '\n');
250
277
  return 0;
@@ -262,17 +289,7 @@ export async function runSetup(argv = [], options = {}) {
262
289
  writeLine(write, receipt.ok ? ' ✓ Agent Sam setup complete' : ' ✕ Setup finished with failures');
263
290
  writeLine(write, ` Receipt ${receipt.path}`);
264
291
  writeLine(write, '');
265
- writeLine(write, ' Next');
266
- writeLine(write, ' agentsam doctor');
267
- writeLine(write, ' agentsam capabilities');
268
- if (capabilityIds.includes('google.cloud')) {
269
- writeLine(write, ' agentsam setup google.cloud --inventory');
270
- writeLine(write, ' agentsam gcloud auth login');
271
- }
272
- if (capabilityIds.includes('image.vectorize')) {
273
- writeLine(write, ' agentsam image optimize ./logo.png # when image command ships');
274
- }
275
- writeLine(write, '');
292
+ writeSetupNext(write, capabilityIds);
276
293
 
277
294
  if (json) write(JSON.stringify({ environment, plan, receipt }, null, 2) + '\n');
278
295
  return receipt.ok ? 0 : 2;
@@ -4,6 +4,7 @@ import { buildStatusActionPlan } from '../status/actions.js';
4
4
  import { openExternalUrl } from '../lib/open-url.js';
5
5
  import readline from 'node:readline/promises';
6
6
  import { stdin as input, stdout as output } from 'node:process';
7
+ import { renderCommandHelp } from '../ui/cli/help.js';
7
8
 
8
9
  function parseStatusArgs(argv = []) {
9
10
  const opts = {
@@ -11,12 +12,14 @@ function parseStatusArgs(argv = []) {
11
12
  offline: false,
12
13
  discoverModels: true,
13
14
  interactive: false,
15
+ help: false,
14
16
  };
15
17
  for (const arg of argv) {
16
18
  if (arg === '--json') opts.json = true;
17
19
  else if (arg === '--offline') opts.offline = true;
18
20
  else if (arg === '--no-discover') opts.discoverModels = false;
19
21
  else if (arg === '--interactive' || arg === '-i') opts.interactive = true;
22
+ else if (arg === '--help' || arg === '-h') opts.help = true;
20
23
  else throw new Error(`unknown status option: ${arg}`);
21
24
  }
22
25
  return opts;
@@ -68,13 +71,17 @@ async function runInteractiveMenu(status, write) {
68
71
 
69
72
  export async function runStatus(argv = [], opts = {}) {
70
73
  const parsed = parseStatusArgs(argv);
74
+ const write = opts.write || ((value) => process.stdout.write(value));
75
+ if (parsed.help) {
76
+ write(renderCommandHelp('status'));
77
+ return null;
78
+ }
71
79
  const status = await (opts.collectRuntime || collectRuntimeStatus)({
72
80
  ...opts,
73
81
  cwd: opts.cwd || process.cwd(),
74
82
  offline: parsed.offline,
75
83
  discoverModels: parsed.discoverModels,
76
84
  });
77
- const write = opts.write || ((value) => process.stdout.write(value));
78
85
  if (parsed.json) {
79
86
  const plan = buildStatusActionPlan(status);
80
87
  write(`${JSON.stringify({ ...status, next: plan }, null, 2)}\n`);
@@ -39,6 +39,7 @@ export function normalizeProviderTemplateId(id) {
39
39
  if (!key) return '';
40
40
  if (key === 'iam') return 'inneranimalmedia';
41
41
  if (key === 'google-desktop') return 'google_desktop';
42
+ if (key === 'openai' || key === 'chatgpt-hosted' || key === 'chatgpt_hosted') return 'chatgpt';
42
43
  return key;
43
44
  }
44
45
 
@@ -59,7 +59,7 @@ export async function planIndex({ root, config: input, store, embed = false, lim
59
59
  limits: Number.isFinite(maxFiles) || Number.isFinite(maxChunks) ? { max_files: maxFiles, max_chunks: maxChunks } : null } };
60
60
  }
61
61
 
62
- export async function runIndex({ root, config, store, embedder, embed = false, maxInputs = 100, maxCharacters = 200000, limits = null }) {
62
+ export async function runIndex({ root, config, store, embedder, embed = false, vectorBackend = null, vectorContext = {}, maxInputs = 100, maxCharacters = 200000, limits = null }) {
63
63
  if (!store) throw new Error('A writable knowledge store is required.');
64
64
  if (!Number.isInteger(maxInputs) || maxInputs < 0 || !Number.isInteger(maxCharacters) || maxCharacters < 0) throw new Error('Embedding budgets must be nonnegative integers.');
65
65
  const plan = await planIndex({ root, config, store, embed, limits });
@@ -76,6 +76,25 @@ export async function runIndex({ root, config, store, embedder, embed = false, m
76
76
  // Completed work remains reusable even if a later request or publication fails.
77
77
  await store.cachePut(key, vector);
78
78
  }
79
+ let vectorUpsert = null;
80
+ if (embed && plan.config.lane?.backend === 'cloudflare_vectorize') {
81
+ if (!vectorBackend?.upsert) throw new Error('cloudflare_vectorize_backend_required');
82
+ const records = [];
83
+ for (const chunk of plan.chunks) {
84
+ const vector = validateVector(await store.cacheGet(chunk.embedding_key), plan.config.embedding.dimensions);
85
+ records.push({
86
+ id: chunk.id,
87
+ vector,
88
+ metadata: { path: chunk.path, ordinal: chunk.ordinal, content_hash: chunk.content_hash },
89
+ });
90
+ }
91
+ vectorUpsert = await vectorBackend.upsert(records, {
92
+ ...vectorContext,
93
+ binding: plan.config.lane.binding,
94
+ index: plan.config.lane.index,
95
+ profile: { ...plan.config.lane, dimensions: plan.config.embedding.dimensions },
96
+ });
97
+ }
79
98
  // A generation describes one coherent source snapshot. Never publish after a mid-run edit.
80
99
  const check = [];
81
100
  const checkFiles = inventory(root, plan.config.scope).slice(0, limits?.maxFiles == null ? Infinity : limits.maxFiles);
@@ -85,7 +104,7 @@ export async function runIndex({ root, config, store, embedder, embed = false, m
85
104
  source_hash: receipt.source_hash, config_hash: receipt.config_hash, config: plan.config, profile_id: receipt.profile_id,
86
105
  git: gitEvidence(root), files: plan.files, chunks: plan.chunks, symbols: plan.symbols, edges: plan.edges, receipt };
87
106
  await store.publish(generation, plan.previous?.id || null);
88
- return { ...receipt, generation_id: generation.id, published: true };
107
+ return { ...receipt, generation_id: generation.id, published: true, vector_upsert: vectorUpsert };
89
108
  }
90
109
 
91
110
  export async function retrieve({ store, config: input, text, semantic = false, embedder, topK = 8, tokenBudget = 6000, generationId, resultPolicy: requestedResultPolicy }) {
@@ -0,0 +1,127 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { readCloudflareDeploymentContract } from '../cloudflare/runtime-status.js';
4
+ import { getRepositoryId, portableRepositoryIdFromGit, tryReadProjectConfig } from '../lib/project-config.js';
5
+ import { resolveProviderCredential } from '../lib/provider-credentials.js';
6
+ import { tryResolveGitContext } from '../../packages/agentsam-repository/src/git-context.js';
7
+
8
+ export const PROJECT_CONTEXT_SCHEMA = 'agentsam.project-context.v1';
9
+ const clean = value => value == null ? '' : String(value).trim();
10
+ const localIndexPath = root => path.join(root, '.agentsam', 'knowledge', 'index.sqlite');
11
+ function readJson(filename) { try { return JSON.parse(fs.readFileSync(filename, 'utf8')); } catch { return null; } }
12
+ function executionState({ observed = false, selected = false, local = false, remote = false, conflicting = false, source = null, reason = null } = {}) {
13
+ return { observed: Boolean(observed), explicitly_selected: Boolean(selected), locally_executable: Boolean(local), remotely_executable: Boolean(remote), missing: !observed, conflicting: Boolean(conflicting), source: source || null, reason: reason || null };
14
+ }
15
+ function cloudflareCredentialState(env) {
16
+ try {
17
+ const credential = resolveProviderCredential('cloudflare', { env });
18
+ const configured = Boolean(credential?.configured);
19
+ const accountResolved = Boolean(clean(credential?.account_id));
20
+ return { configured, account_resolved: accountResolved, executable: configured && accountResolved, source: credential?.source || null, error: credential?.error || (!configured ? 'cloudflare_authorization_required' : !accountResolved ? 'cloudflare_account_id_required' : null) };
21
+ } catch (error) {
22
+ return { configured: false, account_resolved: false, executable: false, source: null, error: error?.message || String(error) };
23
+ }
24
+ }
25
+ function policyConflict(policy, vectorize) {
26
+ if (policy?.lane?.backend !== 'cloudflare_vectorize') return [];
27
+ const binding = clean(policy.lane.binding), index = clean(policy.lane.index);
28
+ if (vectorize.some(row => row.binding === binding && row.index === index)) return [];
29
+ return [{ kind: 'knowledge_deployment_drift', backend: 'cloudflare_vectorize', policy: { binding: binding || null, index: index || null }, observed: vectorize.map(row => ({ binding: row.binding, index: row.index })), detail: 'Knowledge policy selects a Vectorize binding/index that is not declared by the active Wrangler deployment contract.' }];
30
+ }
31
+
32
+ export function discoverProjectContext(root = process.cwd(), options = {}) {
33
+ const resolvedRoot = fs.realpathSync(path.resolve(root));
34
+ const env = options.env || process.env;
35
+ const policy = options.knowledgeConfig || null;
36
+ const projectConfig = options.projectConfig || tryReadProjectConfig(resolvedRoot);
37
+ const git = tryResolveGitContext({ cwd: resolvedRoot });
38
+ const repositoryId = getRepositoryId(projectConfig) || portableRepositoryIdFromGit(resolvedRoot) || `local:${path.basename(resolvedRoot)}`;
39
+ const hostInstallPath = path.join(resolvedRoot, '.agentsam', 'app.json');
40
+ const hostInstall = fs.existsSync(hostInstallPath) ? readJson(hostInstallPath) : null;
41
+ const productManifestPath = path.join(resolvedRoot, 'agentsam.app.json');
42
+ const productManifest = fs.existsSync(productManifestPath) ? readJson(productManifestPath) : null;
43
+ let contract = null, contractError = null;
44
+ try { contract = readCloudflareDeploymentContract(resolvedRoot, projectConfig || {}); } catch (error) { contractError = error?.message || String(error); }
45
+ const bindings = contract?.bindings || [];
46
+ const ai = bindings.find(row => row.type === 'ai') || null;
47
+ const vectorize = bindings.filter(row => row.type === 'vectorize').map(row => ({ binding: row.name, index: row.index_name || null, source: row.source || 'wrangler_config' }));
48
+ const d1 = bindings.filter(row => row.type === 'd1');
49
+ const r2 = bindings.filter(row => row.type === 'r2_bucket');
50
+ const credential = cloudflareCredentialState(env);
51
+ const remoteConfigured = Boolean(contract?.configured);
52
+ const conflicts = policyConflict(policy, vectorize);
53
+ const indexPath = localIndexPath(resolvedRoot);
54
+ const localIndex = { exists: fs.existsSync(indexPath), path: path.relative(resolvedRoot, indexPath) };
55
+ const policyBinding = clean(policy?.lane?.binding), policyIndex = clean(policy?.lane?.index);
56
+ const vectorizeResources = vectorize.map(row => {
57
+ const selected = policy?.lane?.backend === 'cloudflare_vectorize' && row.binding === policyBinding && row.index === policyIndex;
58
+ return {
59
+ ...row,
60
+ configured: Boolean(row.binding && row.index),
61
+ ...executionState({
62
+ observed: Boolean(row.binding && row.index), selected,
63
+ local: Boolean(row.binding && row.index && credential.executable),
64
+ remote: Boolean(row.binding && row.index && remoteConfigured),
65
+ conflicting: conflicts.length > 0 && !selected,
66
+ source: row.source,
67
+ reason: credential.executable ? null : 'Local CLI/Desktop Vectorize execution requires the current user Cloudflare authorization and account id.',
68
+ }),
69
+ };
70
+ });
71
+ const workersAi = ai ? {
72
+ binding: ai.name, configured: true, credential_state: credential,
73
+ ...executionState({ observed: true, selected: policy?.embedding?.provider === 'workers-ai', local: false, remote: remoteConfigured, source: ai.source || 'wrangler_config', reason: 'Workers AI binding is executable in the configured Worker runtime; a local Node process does not possess env.<AI_BINDING>.' }),
74
+ } : {
75
+ binding: null, configured: false, credential_state: credential,
76
+ ...executionState({ observed: false, source: contract?.config || null, reason: 'No Workers AI binding declared.' }),
77
+ };
78
+ const mapBoundResource = row => ({
79
+ binding: row.name,
80
+ name: row.database_name || row.bucket_name || null,
81
+ id: row.database_id || null,
82
+ ...executionState({ observed: true, local: false, remote: remoteConfigured, source: row.source || 'wrangler_config', reason: 'This receipt describes runtime binding execution; local provider API execution is a separate authorized transport.' }),
83
+ });
84
+ const lanes = [];
85
+ if (localIndex.exists) lanes.push({ id: 'local-index', backend: 'local_exact', source: 'local_index', configured: true, locally_executable: true, remotely_executable: false });
86
+ for (const row of vectorizeResources) lanes.push({ id: `cloudflare-vectorize:${row.binding}`, backend: 'cloudflare_vectorize', binding: row.binding, index: row.index, source: row.source, configured: row.configured, locally_executable: row.locally_executable, remotely_executable: row.remotely_executable, explicitly_selected: row.explicitly_selected, conflicting: row.conflicting });
87
+
88
+ return {
89
+ schema: PROJECT_CONTEXT_SCHEMA,
90
+ version: 1,
91
+ repository: { root: resolvedRoot, identity: repositoryId, branch: git?.branch || null, revision: git?.revisionSha || null, dirty: git?.dirty ?? null, source: git ? 'git' : projectConfig ? '.agentsam/config.json' : 'filesystem' },
92
+ project: {
93
+ config_present: Boolean(projectConfig), config_source: projectConfig ? '.agentsam/config.json' : null,
94
+ product_manifest: productManifest ? { id: clean(productManifest.id) || null, source: 'agentsam.app.json' } : null,
95
+ host_install: hostInstall ? { app_id: clean(hostInstall.app_id || hostInstall.id) || null, name: clean(hostInstall.name) || null, role: clean(hostInstall.role) || null, mounts: hostInstall.mounts || null, schema: clean(hostInstall.schema) || null, source: '.agentsam/app.json' } : null,
96
+ },
97
+ deployment: { configured: remoteConfigured, worker_name: contract?.worker_name || null, config: contract?.config || null, error: contractError },
98
+ knowledge: {
99
+ policy_configured: Boolean(policy), policy_source: policy ? '.agentsam/knowledge.json' : null,
100
+ selected_backend: policy?.lane?.backend || null,
101
+ suggested_backend: !policy && vectorizeResources.length === 1 ? 'cloudflare_vectorize' : (!policy ? 'local_exact' : null),
102
+ local_index: { ...localIndex, ...executionState({ observed: localIndex.exists, selected: policy?.lane?.backend === 'local_exact', local: localIndex.exists, remote: false, source: localIndex.exists ? localIndex.path : null, reason: localIndex.exists ? null : 'No local knowledge SQLite index exists.' }) },
103
+ },
104
+ authorization: { cloudflare: credential },
105
+ resources: {
106
+ workers_ai: workersAi,
107
+ vectorize: vectorizeResources,
108
+ d1: d1.map(mapBoundResource),
109
+ r2: r2.map(mapBoundResource),
110
+ },
111
+ conflicts,
112
+ local_index: localIndex,
113
+ cloudflare: {
114
+ configured: remoteConfigured,
115
+ worker_name: contract?.worker_name || null,
116
+ config: contract?.config || null,
117
+ ai_binding: ai?.name || null,
118
+ vectorize: vectorizeResources.map(row => ({ binding: row.binding, index: row.index, source: row.source })),
119
+ error: contractError,
120
+ },
121
+ lanes,
122
+ };
123
+ }
124
+
125
+ export function discoverKnowledgeRuntime(root = process.cwd(), options = {}) {
126
+ return discoverProjectContext(root, options);
127
+ }