@inneranimalmedia/agentsam-sdk 2.6.7 → 2.6.9

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/README.md +37 -0
  2. package/apps/README.md +25 -0
  3. package/apps/cad-creator/shared/cad/package.json +1 -1
  4. package/apps/client-cms-editor/backend/package.json +4 -6
  5. package/apps/client-cms-editor/frontend/package.json +6 -8
  6. package/apps/client-cms-editor/frontend/tsconfig.json +27 -8
  7. package/apps/client-cms-editor/package.json +1 -1
  8. package/apps/client-cms-editor/shared/cms/package.json +4 -6
  9. package/docs/LOCAL_ENGINE_COMPUTE_AUDIT_PLAN.md +299 -0
  10. package/docs/REPO_FILE_MAP.txt +132 -0
  11. package/migrations/d1/0018_goap_control_plane_remaster.sql +40 -0
  12. package/migrations/d1/0019_agentsam_agent_run_plan_todo.sql +14 -0
  13. package/migrations/d1/README_PORTABLE_CONTROL_PLANE.md +20 -9
  14. package/migrations/runtime/0002_goap_blackboard_v1.sql +15 -0
  15. package/migrations/runtime/0004_agent_run_plan_linkage.sql +8 -0
  16. package/native/agentsam-machine/cli/Cargo.toml +8 -1
  17. package/native/agentsam-machine/cli/README.md +21 -0
  18. package/native/agentsam-machine/core/Cargo.toml +7 -0
  19. package/native/agentsam-machine/core/README.md +14 -0
  20. package/native/agentsam-machine/core/build.rs +33 -0
  21. package/native/agentsam-machine/core/contracts/source-types.v1.json +353 -0
  22. package/native/agentsam-machine/core/src/lib.rs +6 -0
  23. package/native/agentsam-machine/core/src/source_types.rs +2 -2
  24. package/package.json +31 -10
  25. package/packages/agentsam-brand/package.json +1 -1
  26. package/packages/agentsam-contracts/package.json +71 -20
  27. package/packages/agentsam-contracts/scripts/build.mjs +18 -0
  28. package/packages/agentsam-contracts/test/contracts.test.mjs +4 -1
  29. package/packages/agentsam-contracts/test/repository.test.mjs +4 -1
  30. package/packages/agentsam-contracts/tsconfig.build.json +10 -0
  31. package/packages/agentsam-errors/package.json +3 -2
  32. package/packages/agentsam-errors/src/index.js +1 -0
  33. package/packages/agentsam-errors/src/tool.js +56 -0
  34. package/packages/agentsam-errors/test/tool.test.mjs +58 -0
  35. package/packages/agentsam-goap/README.md +52 -0
  36. package/packages/agentsam-goap/package.json +37 -0
  37. package/packages/agentsam-goap/src/adapters/d1-sqlite.js +570 -0
  38. package/packages/agentsam-goap/src/adapters/memory.js +199 -0
  39. package/packages/agentsam-goap/src/contracts.js +226 -0
  40. package/packages/agentsam-goap/src/control-plane.js +112 -0
  41. package/packages/agentsam-goap/src/errors.js +157 -0
  42. package/packages/agentsam-goap/src/index.js +5 -0
  43. package/packages/agentsam-goap/src/world.js +202 -0
  44. package/packages/agentsam-goap/test/goap-control-plane.test.mjs +245 -0
  45. package/packages/agentsam-goap/test/world.test.mjs +79 -0
  46. package/packages/agentsam-knowledge/package.json +3 -2
  47. package/packages/agentsam-nav/package.json +1 -1
  48. package/packages/agentsam-queue-control/package.json +1 -1
  49. package/packages/agentsam-rapid-rust/src/main.rs +1 -0
  50. package/packages/agentsam-repository/package.json +3 -2
  51. package/packages/agentsam-repository/src/goap.js +13 -14
  52. package/packages/agentsam-repository/src/tickets.js +15 -22
  53. package/packages/agentsam-repository/test/goap-tickets-workspace-state.test.mjs +19 -8
  54. package/packages/agentsam-vault/package.json +8 -5
  55. package/packages/agentsam-workbench/package.json +44 -17
  56. package/packages/connectors/cloudflare/package.json +4 -2
  57. package/packages/heuristic-theme/package.json +1 -1
  58. package/packages/identity/package.json +4 -3
  59. package/packages/identity/tests/lane1-packed-consumer.test.mjs +10 -2
  60. package/packages/providers/completeful/package.json +1 -1
  61. package/packages/theme-church-site/README.md +2 -2
  62. package/packages/theme-church-site/package.json +3 -4
  63. package/packages/theme-church-site/src/index.js +1 -1
  64. package/packages/theme-church-site/test/theme.test.mjs +1 -1
  65. package/packages/theme-companions-site/README.md +2 -2
  66. package/packages/theme-companions-site/package.json +3 -4
  67. package/packages/theme-companions-site/src/index.js +1 -1
  68. package/packages/theme-companions-site/test/theme.test.mjs +1 -1
  69. package/packages/theme-floors-site/README.md +2 -2
  70. package/packages/theme-floors-site/package.json +3 -4
  71. package/packages/theme-floors-site/src/index.js +1 -1
  72. package/packages/theme-floors-site/test/theme.test.mjs +1 -1
  73. package/packages/theme-fuelnfree-site/README.md +2 -2
  74. package/packages/theme-fuelnfree-site/package.json +3 -4
  75. package/packages/theme-fuelnfree-site/src/index.js +1 -1
  76. package/packages/theme-fuelnfree-site/test/theme.test.mjs +1 -1
  77. package/packages/theme-handyman-site/README.md +2 -2
  78. package/packages/theme-handyman-site/package.json +3 -4
  79. package/packages/theme-handyman-site/src/index.js +1 -1
  80. package/packages/theme-handyman-site/test/theme.test.mjs +1 -1
  81. package/packages/theme-insurance-site/README.md +2 -2
  82. package/packages/theme-insurance-site/package.json +3 -4
  83. package/packages/theme-insurance-site/src/index.js +1 -1
  84. package/packages/theme-insurance-site/test/theme.test.mjs +1 -1
  85. package/packages/theme-scenes/package.json +1 -1
  86. package/packages/theme-shinshu-site/README.md +2 -2
  87. package/packages/theme-shinshu-site/package.json +3 -4
  88. package/packages/theme-shinshu-site/src/index.js +1 -1
  89. package/packages/theme-shinshu-site/test/theme.test.mjs +1 -1
  90. package/packages/work-graph/package.json +3 -2
  91. package/protocol/local-engine/benchmark.v1.schema.json +14 -0
  92. package/protocol/local-engine/engine.v1.schema.json +17 -0
  93. package/python/agentsam_sdk/repository/intelligence/discovery.py +27 -2
  94. package/python/agentsam_sdk/repository/intelligence/git.py +4 -0
  95. package/python/tests/test_repository_intelligence.py +30 -0
  96. package/src/cli/command-catalog.js +3 -1
  97. package/src/cli.js +20 -1
  98. package/src/commands/app.js +10 -0
  99. package/src/commands/engine.js +10 -0
  100. package/src/commands/goap-world.js +134 -0
  101. package/src/commands/goap.js +11 -4
  102. package/src/commands/machine-binary.js +33 -27
  103. package/src/commands/machine-runtime.js +266 -0
  104. package/src/commands/machine.js +155 -51
  105. package/src/commands/package.js +537 -0
  106. package/src/commands/plan-ledger.js +370 -0
  107. package/src/commands/plan.js +183 -0
  108. package/src/commands/runtime.js +25 -10
  109. package/src/commands/setup.js +30 -6
  110. package/src/commands/skill.js +78 -17
  111. package/src/commands/terminal.js +20 -8
  112. package/src/errors/contract.js +4 -4
  113. package/src/errors/diagnostic.js +1 -1
  114. package/src/errors/index.js +1 -1
  115. package/src/index.js +20 -0
  116. package/src/indexing/ingest/materials.js +237 -30
  117. package/src/knowledge/source.js +1 -1
  118. package/src/lib/setup/runtime.js +4 -2
  119. package/src/lib/slash-commands.js +1 -1
  120. package/src/local/runtime-store.js +24 -2
  121. package/src/local/sqlite.js +17 -0
  122. package/src/local-engine/assets.js +37 -0
  123. package/src/local-engine/audit.js +133 -0
  124. package/src/local-engine/benchmark.js +26 -0
  125. package/src/local-engine/contracts.js +101 -0
  126. package/src/local-engine/engines.js +142 -0
  127. package/src/local-engine/index.js +18 -0
  128. package/src/local-engine/runtime.js +39 -0
  129. package/src/sam/operations/package-audit.js +41 -0
  130. package/src/sam/seed.js +2 -0
  131. package/skills/grok-auth/SKILL.md +0 -110
  132. package/skills/grok-auth/agentsam.skill.json +0 -25
  133. package/skills/grok-auth/references/grok-identity.md +0 -64
  134. package/skills/grok-auth/references/per-user-data.md +0 -49
  135. package/skills/grok-auth/references/prewired-and-env.md +0 -54
  136. package/skills/grok-auth/references/session-ui.md +0 -133
  137. package/skills/grok-auth/references/sign-in-methods.md +0 -55
  138. package/skills/grok-auth/references/wiring.md +0 -71
  139. package/skills/grok-building-games/SKILL.md +0 -213
  140. package/skills/grok-building-games/agentsam.skill.json +0 -25
  141. package/skills/grok-building-games/references/3d-libs.md +0 -64
  142. package/skills/grok-building-games/references/ai-pathfinding.md +0 -122
  143. package/skills/grok-building-games/references/audio.md +0 -129
  144. package/skills/grok-building-games/references/babylon.md +0 -202
  145. package/skills/grok-building-games/references/collision-physics.md +0 -122
  146. package/skills/grok-building-games/references/ecs-architecture.md +0 -111
  147. package/skills/grok-building-games/references/game-feel-juice.md +0 -110
  148. package/skills/grok-building-games/references/genres/board-card-chess.md +0 -89
  149. package/skills/grok-building-games/references/genres/endless-runner.md +0 -83
  150. package/skills/grok-building-games/references/genres/fps.md +0 -105
  151. package/skills/grok-building-games/references/genres/platformer-2d.md +0 -97
  152. package/skills/grok-building-games/references/genres/puzzle-match3-tetris.md +0 -131
  153. package/skills/grok-building-games/references/genres/racing-kart.md +0 -106
  154. package/skills/grok-building-games/references/genres/topdown-twin-stick.md +0 -97
  155. package/skills/grok-building-games/references/genres/tower-defense.md +0 -84
  156. package/skills/grok-building-games/references/genres/voxel-minecraft.md +0 -89
  157. package/skills/grok-building-games/references/input.md +0 -139
  158. package/skills/grok-building-games/references/phaser.md +0 -277
  159. package/skills/grok-building-games/references/procedural-generation.md +0 -141
  160. package/skills/grok-building-games/references/save-persistence.md +0 -108
  161. package/skills/grok-building-games/references/threejs-foundational.md +0 -148
  162. package/skills/grok-controls/SKILL.md +0 -274
  163. package/skills/grok-controls/agentsam.skill.json +0 -25
  164. package/skills/grok-design-ui/SKILL.md +0 -122
  165. package/skills/grok-design-ui/agentsam.skill.json +0 -25
  166. package/skills/grok-design-ui/references/animations.md +0 -379
  167. package/skills/grok-design-ui/references/performance.md +0 -88
  168. package/skills/grok-design-ui/references/refined-ui.md +0 -384
  169. package/skills/grok-design-ui/references/surfaces.md +0 -247
  170. package/skills/grok-design-ui/references/typography.md +0 -123
  171. package/skills/grok-game-animation-frames/SKILL.md +0 -84
  172. package/skills/grok-game-animation-frames/agentsam.skill.json +0 -25
  173. package/skills/grok-game-asset-core/SKILL.md +0 -69
  174. package/skills/grok-game-asset-core/agentsam.skill.json +0 -25
  175. package/skills/grok-game-character-consistency/SKILL.md +0 -69
  176. package/skills/grok-game-character-consistency/agentsam.skill.json +0 -25
  177. package/skills/grok-game-tilesets/SKILL.md +0 -65
  178. package/skills/grok-game-tilesets/agentsam.skill.json +0 -25
  179. package/skills/grok-game-ui-icons/SKILL.md +0 -56
  180. package/skills/grok-game-ui-icons/agentsam.skill.json +0 -25
  181. package/skills/grok-generate2dmap/LICENSE +0 -21
  182. package/skills/grok-generate2dmap/SKILL.md +0 -120
  183. package/skills/grok-generate2dmap/SOURCE.md +0 -6
  184. package/skills/grok-generate2dmap/agentsam.skill.json +0 -25
  185. package/skills/grok-generate2dmap/references/deliverables.md +0 -101
  186. package/skills/grok-generate2dmap/references/layered-map-contract.md +0 -209
  187. package/skills/grok-generate2dmap/references/map-strategies.md +0 -341
  188. package/skills/grok-generate2dmap/references/object-production-gate.md +0 -24
  189. package/skills/grok-generate2dmap/references/pipeline.md +0 -149
  190. package/skills/grok-generate2dmap/references/prop-pack-contract.md +0 -174
  191. package/skills/grok-generate2dmap/references/side-scroll-stages.md +0 -29
  192. package/skills/grok-generate2dmap/scripts/compose_layered_preview.py +0 -157
  193. package/skills/grok-generate2dmap/scripts/extract_prop_pack.py +0 -369
  194. package/skills/grok-generate2dsprite/LICENSE +0 -21
  195. package/skills/grok-generate2dsprite/SKILL.md +0 -313
  196. package/skills/grok-generate2dsprite/SOURCE.md +0 -6
  197. package/skills/grok-generate2dsprite/agentsam.skill.json +0 -25
  198. package/skills/grok-generate2dsprite/references/modes.md +0 -124
  199. package/skills/grok-generate2dsprite/references/prompt-rules.md +0 -315
  200. package/skills/grok-generate2dsprite/scripts/generate2dsprite.py +0 -1031
  201. package/skills/grok-generate2dsprite/scripts/make_layout_guide.py +0 -109
  202. package/skills/grok-imagine/SKILL.md +0 -201
  203. package/skills/grok-imagine/agentsam.skill.json +0 -25
  204. package/skills/grok-multiplayer-p2p/SKILL.md +0 -111
  205. package/skills/grok-multiplayer-p2p/agentsam.skill.json +0 -25
  206. package/skills/grok-multiplayer-p2p/references/react-binding.md +0 -144
  207. package/skills/grok-multiplayer-p2p/references/signaling-relay.md +0 -269
  208. package/skills/grok-neon/SKILL.md +0 -157
  209. package/skills/grok-neon/agentsam.skill.json +0 -25
  210. package/skills/grok-og/SKILL.md +0 -102
  211. package/skills/grok-og/agentsam.skill.json +0 -25
  212. package/skills/grok-og/references/brand-pass.md +0 -53
  213. package/skills/grok-og/references/custom-card.md +0 -107
  214. package/skills/grok-og/references/favicon-and-icons.md +0 -48
  215. package/skills/grok-og/references/og-type-contract.md +0 -18
  216. package/skills/grok-og/references/placeholder-card.md +0 -21
  217. package/skills/grok-og/references/x-banner.md +0 -41
  218. package/skills/grok-threejs/SKILL.md +0 -67
  219. package/skills/grok-threejs/agentsam.skill.json +0 -25
  220. package/skills/grok-threejs/references/llms-full.txt +0 -2780
  221. package/skills/grok-video2dsprite/LICENSE +0 -21
  222. package/skills/grok-video2dsprite/SKILL.md +0 -236
  223. package/skills/grok-video2dsprite/SOURCE.md +0 -6
  224. package/skills/grok-video2dsprite/agentsam.skill.json +0 -25
  225. package/skills/grok-video2dsprite/references/pipeline.md +0 -90
  226. package/skills/grok-video2dsprite/references/prompt-rules.md +0 -63
  227. package/skills/grok-video2dsprite/scripts/video2dsprite.py +0 -490
  228. package/skills/grok-xai-api/SKILL.md +0 -152
  229. package/skills/grok-xai-api/agentsam.skill.json +0 -25
  230. package/test/account-session.test.mjs +0 -101
  231. package/test/agent-capabilities.test.mjs +0 -67
  232. package/test/app-authority-context.test.mjs +0 -32
  233. package/test/app-building-skills.test.mjs +0 -61
  234. package/test/apps-scaffold-contract.test.mjs +0 -115
  235. package/test/blender-cad.test.mjs +0 -146
  236. package/test/cad-docker.test.mjs +0 -96
  237. package/test/capabilities.test.mjs +0 -133
  238. package/test/cli/api-key-env-whoami.test.mjs +0 -129
  239. package/test/cli/catalog-authority.test.mjs +0 -64
  240. package/test/cli/codebaseindex-plan-ux.test.mjs +0 -37
  241. package/test/cli/eval-live.test.mjs +0 -219
  242. package/test/cli/go.test.mjs +0 -128
  243. package/test/cli/local-vault-and-provider-setup.test.mjs +0 -268
  244. package/test/cli/machine-command.test.mjs +0 -34
  245. package/test/cli/mcp-client.test.mjs +0 -256
  246. package/test/cli/preferences-runtime.test.mjs +0 -11
  247. package/test/cli/runtime-persist.test.mjs +0 -56
  248. package/test/cli/runtime-ui.test.mjs +0 -141
  249. package/test/cli/rust-command.test.mjs +0 -21
  250. package/test/cli/skill-npm-and-env.test.mjs +0 -52
  251. package/test/cli/status-actions.test.mjs +0 -88
  252. package/test/cli/wireframes-go-registry.test.mjs +0 -139
  253. package/test/cli-preferences.test.mjs +0 -46
  254. package/test/cloudflare-connector.test.mjs +0 -93
  255. package/test/cloudflare-runtime.test.mjs +0 -82
  256. package/test/context.test.mjs +0 -159
  257. package/test/credentials-audit.test.mjs +0 -113
  258. package/test/deploy-health-scan.test.mjs +0 -95
  259. package/test/deploy-receipt.test.mjs +0 -91
  260. package/test/dockerize.test.mjs +0 -93
  261. package/test/error-diagnostics.test.mjs +0 -124
  262. package/test/eval-context.test.mjs +0 -37
  263. package/test/execution-approvals.test.mjs +0 -27
  264. package/test/fixtures/cad/courtyard-house.json +0 -208
  265. package/test/fixtures/knowledge-rpc-worker.mjs +0 -16
  266. package/test/fixtures/project-authority/customer-app/.agentsam/app.json +0 -5
  267. package/test/fixtures/project-authority/customer-app/apps/my-product/index.ts +0 -1
  268. package/test/fixtures/project-authority/customer-app/wrangler.toml +0 -17
  269. package/test/gcloud-auth.test.mjs +0 -111
  270. package/test/go/build-source-identity.test.mjs +0 -31
  271. package/test/go/cloudflare-probe.test.mjs +0 -317
  272. package/test/go/distribution.test.mjs +0 -28
  273. package/test/google-cloud-connection.test.mjs +0 -83
  274. package/test/google-cloud-inventory.test.mjs +0 -64
  275. package/test/indexing-provider.test.mjs +0 -29
  276. package/test/init-options.test.mjs +0 -35
  277. package/test/integration/ai-access-onboarding.test.mjs +0 -47
  278. package/test/integration/app-command.test.mjs +0 -85
  279. package/test/integration/autorag-project-authority.integration.test.mjs +0 -51
  280. package/test/integration/autorag-runtime-discovery.test.mjs +0 -107
  281. package/test/integration/cad-discovery.test.mjs +0 -158
  282. package/test/integration/cad-docker-executor.test.mjs +0 -249
  283. package/test/integration/cad-execution.test.mjs +0 -184
  284. package/test/integration/cad-project-app.test.mjs +0 -31
  285. package/test/integration/cad-project-d1.test.mjs +0 -25
  286. package/test/integration/cad-project-native.test.mjs +0 -24
  287. package/test/integration/cad-project-workflow.test.mjs +0 -9
  288. package/test/integration/cad-project.test.mjs +0 -85
  289. package/test/integration/cli-help.test.mjs +0 -41
  290. package/test/integration/cms-app-scaffold.test.mjs +0 -77
  291. package/test/integration/cms-site-tenancy-contract.test.mjs +0 -268
  292. package/test/integration/codebaseindex-ingest.test.mjs +0 -255
  293. package/test/integration/core-client.integration.test.mjs +0 -55
  294. package/test/integration/database-hosted-honesty.test.mjs +0 -49
  295. package/test/integration/desktop-keychain-boundary.test.mjs +0 -45
  296. package/test/integration/error-runtime-rpc.test.mjs +0 -71
  297. package/test/integration/features-resolve.test.mjs +0 -147
  298. package/test/integration/hosted-work-host-authority.test.mjs +0 -47
  299. package/test/integration/icon-registry.test.mjs +0 -67
  300. package/test/integration/ingest-discover-models.test.mjs +0 -30
  301. package/test/integration/inspect-path-cli.test.mjs +0 -46
  302. package/test/integration/install-script.test.mjs +0 -110
  303. package/test/integration/inventory-core.test.mjs +0 -53
  304. package/test/integration/inventory-eligibility.test.mjs +0 -59
  305. package/test/integration/inventory-evidence.test.mjs +0 -125
  306. package/test/integration/knowledge-rpc.test.mjs +0 -112
  307. package/test/integration/local-fs.test.mjs +0 -113
  308. package/test/integration/local-provider-bridge.test.mjs +0 -65
  309. package/test/integration/local-studio-settings-production.test.mjs +0 -40
  310. package/test/integration/lockfile-sync.test.mjs +0 -26
  311. package/test/integration/merkle-cli.test.mjs +0 -61
  312. package/test/integration/merkle-persistence-identity.test.mjs +0 -48
  313. package/test/integration/plugins-cloudflare.integration.test.mjs +0 -28
  314. package/test/integration/provider-env-cli.test.mjs +0 -60
  315. package/test/integration/provider-factory.test.mjs +0 -197
  316. package/test/integration/repository-company-graph.test.mjs +0 -90
  317. package/test/integration/runtime-migrations.test.mjs +0 -87
  318. package/test/integration/runtime-status.integration.test.mjs +0 -227
  319. package/test/integration/sam-activity-recovery.test.mjs +0 -147
  320. package/test/integration/sam-decision.test.mjs +0 -584
  321. package/test/integration/sam-kernel.test.mjs +0 -99
  322. package/test/integration/sam-planning-astar.test.mjs +0 -279
  323. package/test/integration/scaffold-cloudflare.test.mjs +0 -46
  324. package/test/integration/skill-runtime.test.mjs +0 -240
  325. package/test/integration/storage-architecture.test.mjs +0 -154
  326. package/test/integration/store-discovery.test.mjs +0 -44
  327. package/test/integration/studio-fs-pty-e2e.test.mjs +0 -294
  328. package/test/integration/terminal-exec.integration.test.mjs +0 -86
  329. package/test/integration/theme-package-registry.test.mjs +0 -31
  330. package/test/integration/tool-runtime.test.mjs +0 -124
  331. package/test/integration/tool-schema.test.mjs +0 -59
  332. package/test/jr-dev-skill.test.mjs +0 -26
  333. package/test/knowledge-context-pack.test.mjs +0 -19
  334. package/test/knowledge-postgres.test.mjs +0 -40
  335. package/test/knowledge-service.test.mjs +0 -110
  336. package/test/knowledge.test.mjs +0 -206
  337. package/test/live/terminal-transport.live.test.mjs +0 -24
  338. package/test/local-sessions.test.mjs +0 -57
  339. package/test/local-studio-deploy.test.mjs +0 -83
  340. package/test/loopback-oauth.test.mjs +0 -53
  341. package/test/merkle-render.test.mjs +0 -31
  342. package/test/mini.test.mjs +0 -140
  343. package/test/model-catalog.test.mjs +0 -70
  344. package/test/models.test.mjs +0 -309
  345. package/test/npm10-lock.test.mjs +0 -29
  346. package/test/ollama.test.mjs +0 -137
  347. package/test/open-url.test.mjs +0 -64
  348. package/test/openai-responses.test.mjs +0 -155
  349. package/test/portable-context.test.mjs +0 -94
  350. package/test/project-config.test.mjs +0 -81
  351. package/test/project-rules.test.mjs +0 -44
  352. package/test/provider-credentials.test.mjs +0 -106
  353. package/test/rehydrate.test.mjs +0 -25
  354. package/test/release-hygiene.test.mjs +0 -42
  355. package/test/repository-snapshot-view.test.mjs +0 -112
  356. package/test/responses-runner.test.mjs +0 -465
  357. package/test/runtime-activity.test.mjs +0 -98
  358. package/test/sdk-worker-contract.test.mjs +0 -72
  359. package/test/security.test.mjs +0 -266
  360. package/test/setup-planner.test.mjs +0 -74
  361. package/test/setup-runtime.test.mjs +0 -51
  362. package/test/shell.test.mjs +0 -281
  363. package/test/skills.test.mjs +0 -22
  364. package/test/smoke.mjs +0 -122
  365. package/test/telemetry.test.mjs +0 -79
  366. package/test/terminal/local-pty.mock.test.mjs +0 -153
  367. package/test/terminal-machine-identity.test.mjs +0 -88
  368. package/test/theme-portability.test.mjs +0 -14
  369. package/test/tools-search.test.mjs +0 -73
  370. package/test/unit/website-assets-bindings.test.mjs +0 -60
  371. package/test/whoami-resume.test.mjs +0 -157
@@ -90,6 +90,23 @@ export async function createLocalSqliteDatabase(filePath = '.agentsam/data/agent
90
90
  },
91
91
  };
92
92
  },
93
+ async batch(statements = []) {
94
+ database.exec('BEGIN IMMEDIATE');
95
+ try {
96
+ const results = [];
97
+ for (const statement of statements) {
98
+ if (!statement || typeof statement.run !== 'function') {
99
+ throw new TypeError('Local SQLite batch entries must expose run()');
100
+ }
101
+ results.push(await statement.run());
102
+ }
103
+ database.exec('COMMIT');
104
+ return results;
105
+ } catch (error) {
106
+ try { database.exec('ROLLBACK'); } catch {}
107
+ throw error;
108
+ }
109
+ },
93
110
  exec(sql) {
94
111
  database.exec(sql);
95
112
  },
@@ -0,0 +1,37 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import crypto from 'node:crypto';
5
+
6
+ export const ASSET_MANIFEST_SCHEMA = 'agentsam.local-model-assets.v1';
7
+ export function agentsamHome(env = process.env) {
8
+ const configured = String(env.AGENTSAM_HOME || '').trim();
9
+ return configured ? path.resolve(configured.replace(/^~(?=\/|$)/, os.homedir())) : path.join(os.homedir(), '.agentsam');
10
+ }
11
+ export function assetManifestPath(env = process.env) { return path.join(agentsamHome(env), 'models', 'manifest.v1.json'); }
12
+ function safeStat(file) { try { return fs.statSync(file); } catch { return null; } }
13
+ function fileId(stat) { return stat ? `${stat.dev}:${stat.ino}` : null; }
14
+ export function readAssetManifest(env = process.env) {
15
+ const file = assetManifestPath(env);
16
+ if (!fs.existsSync(file)) return { schema_version: ASSET_MANIFEST_SCHEMA, generated_at: null, assets: [] };
17
+ try { const parsed = JSON.parse(fs.readFileSync(file, 'utf8')); return parsed?.schema_version === ASSET_MANIFEST_SCHEMA ? parsed : { schema_version: ASSET_MANIFEST_SCHEMA, generated_at: null, assets: [] }; } catch { return { schema_version: ASSET_MANIFEST_SCHEMA, generated_at: null, assets: [] }; }
18
+ }
19
+ function writeManifest(manifest, env = process.env) {
20
+ const file = assetManifestPath(env); fs.mkdirSync(path.dirname(file), { recursive: true });
21
+ const temp = `${file}.${process.pid}.tmp`; fs.writeFileSync(temp, JSON.stringify(manifest, null, 2) + '\n', { mode: 0o600 }); fs.renameSync(temp, file); return file;
22
+ }
23
+ export function adoptAsset(file, metadata = {}, options = {}) {
24
+ const absolute = path.resolve(file); const stat = safeStat(absolute);
25
+ if (!stat || !stat.isFile()) throw new Error(`model asset is not a regular file: ${absolute}`);
26
+ const env = options.env || process.env; const manifest = readAssetManifest(env);
27
+ const asset = { id: metadata.id || crypto.createHash('sha256').update(`${absolute}:${stat.size}:${stat.mtimeMs}`).digest('hex').slice(0, 16), engine_id: metadata.engine_id || null, model: metadata.model || path.basename(absolute), format: metadata.format || path.extname(absolute).slice(1) || 'unknown', canonical_path: absolute, reference: 'external', size_bytes: stat.size, file_id: fileId(stat), digest: metadata.digest || null, seen_at: new Date().toISOString() };
28
+ const assets = manifest.assets.filter((row) => row.canonical_path !== absolute); assets.push(asset);
29
+ const next = { ...manifest, schema_version: ASSET_MANIFEST_SCHEMA, generated_at: new Date().toISOString(), assets }; const manifestPath = writeManifest(next, env);
30
+ return { asset, manifest_path: manifestPath, copied: false };
31
+ }
32
+ export function auditAssets(options = {}) {
33
+ const env = options.env || process.env; const manifest = readAssetManifest(env);
34
+ const assets = manifest.assets.map((asset) => { const stat = safeStat(asset.canonical_path); return { ...asset, exists: Boolean(stat), current_size_bytes: stat?.size || null, current_file_id: fileId(stat), stale: !stat || stat.size !== asset.size_bytes }; });
35
+ const byFile = new Map(); for (const asset of assets) if (asset.file_id) byFile.set(asset.file_id, [...(byFile.get(asset.file_id) || []), asset.id]);
36
+ return { schema_version: ASSET_MANIFEST_SCHEMA, generated_at: new Date().toISOString(), root: path.join(agentsamHome(env), 'models'), assets, duplicates: [...byFile.entries()].filter(([, ids]) => ids.length > 1).map(([file_id, ids]) => ({ file_id, asset_ids: ids })) };
37
+ }
@@ -0,0 +1,133 @@
1
+ import os from 'node:os';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { executable, runCommand } from './runtime.js';
4
+
5
+ export const COMPUTE_AUDIT_SCHEMA = 'agentsam.compute.audit.v1';
6
+
7
+ function command(command, args = [], runner = spawnSync) {
8
+ const result = runner(command, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 5000 });
9
+ return { ok: result.status === 0, stdout: String(result.stdout || '').trim(), stderr: String(result.stderr || '').trim(), status: result.status };
10
+ }
11
+
12
+ function value(text, key) {
13
+ const match = String(text || '').match(new RegExp(`^${key}:\\s*(.+)$`, 'mi'));
14
+ return match?.[1]?.trim() || null;
15
+ }
16
+
17
+ function bytes(valueText) {
18
+ const n = Number(valueText);
19
+ if (Number.isFinite(n) && n > 0) return Math.floor(n);
20
+ const match = String(valueText || '').match(/([\d.]+)\s*(GB|TB|MB)/i);
21
+ if (!match) return null;
22
+ const factor = { mb: 1024 ** 2, gb: 1024 ** 3, tb: 1024 ** 4 }[match[2].toLowerCase()];
23
+ return Math.floor(Number(match[1]) * factor);
24
+ }
25
+
26
+ export function parseSystemProfilerHardware(text) {
27
+ const chip = text.match(/Chip:\s*(.+)/i)?.[1]?.trim() || text.match(/Processor Name:\s*(.+)/i)?.[1]?.trim() || null;
28
+ const memory = text.match(/Memory:\s*(.+)/i)?.[1]?.trim() || null;
29
+ const cores = text.match(/Total Number of Cores:\s*(.+)/i)?.[1]?.trim() || null;
30
+ return { chip, unified_memory_bytes: bytes(memory), core_summary: cores };
31
+ }
32
+
33
+ export function parseAppleAudit({ sysctlText = '', profilerText = '', platform = process.platform, arch = process.arch } = {}) {
34
+ const hardware = parseSystemProfilerHardware(profilerText);
35
+ const chip = hardware.chip || value(sysctlText, 'machdep.cpu.brand_string') || value(sysctlText, 'hw.model');
36
+ const memory = hardware.unified_memory_bytes || bytes(value(sysctlText, 'hw.memsize'));
37
+ const appleSilicon = platform === 'darwin' && (arch === 'arm64' || /apple\s*m[1-9]/i.test(chip || ''));
38
+ return {
39
+ schema_version: COMPUTE_AUDIT_SCHEMA,
40
+ generated_at: new Date().toISOString(),
41
+ host: { platform, arch, hostname: os.hostname() },
42
+ apple_silicon: appleSilicon,
43
+ chip: { name: chip, family: chip?.match(/Apple\s+(M\d[^ ]*)/i)?.[1] || null, cores: hardware.core_summary },
44
+ memory: { unified_memory_bytes: memory, vram_bytes: null, model: appleSilicon ? 'unified' : 'unknown' },
45
+ metal: { available: appleSilicon ? null : false, features: [], evidence: appleSilicon ? 'not_probed' : 'non_apple_host' },
46
+ evidence: [],
47
+ warnings: appleSilicon ? ['Metal feature probing requires the macOS native helper and is not inferred from chip identity.'] : ['Apple Silicon audit is unavailable on this host.'],
48
+ };
49
+ }
50
+
51
+ export function auditAppleHost(options = {}) {
52
+ const env = options.env || process.env;
53
+ const platform = options.platform || process.platform;
54
+ const arch = options.arch || process.arch;
55
+ if (platform !== 'darwin') return parseAppleAudit({ platform, arch });
56
+ const sysctl = command('sysctl', ['-n', 'hw.model', 'hw.memsize'], options.runner || spawnSync);
57
+ const profiler = command('system_profiler', ['SPHardwareDataType', 'SPDisplaysDataType'], options.runner || spawnSync);
58
+ const audit = parseAppleAudit({ sysctlText: sysctl.stdout, profilerText: profiler.stdout, platform, arch });
59
+ audit.evidence.push({ source: 'sysctl', ok: sysctl.ok });
60
+ audit.evidence.push({ source: 'system_profiler', ok: profiler.ok });
61
+ audit.host.env_override = Boolean(env.AGENTSAM_HOME);
62
+ return audit;
63
+ }
64
+
65
+ export function auditTools(options = {}) {
66
+ const engines = [
67
+ { id: 'ollama', commands: ['ollama'] },
68
+ { id: 'llama.cpp', commands: ['llama-server', 'llama-cli'] },
69
+ { id: 'mlx-lm', commands: ['mlx_lm.server', 'mlx_lm'] },
70
+ ];
71
+ return engines.map((engine) => {
72
+ const hits = engine.commands.map((name) => ({ name, path: executable(name, options.env || process.env) })).filter((row) => row.path);
73
+ const version = hits[0] ? runCommand(hits[0].name, ['--version'], options).stdout.trim() : null;
74
+ return { engine_id: engine.id, installed: hits.length > 0, commands: hits, version: version || null };
75
+ });
76
+ }
77
+
78
+ function auditLinuxHost(options = {}) {
79
+ const env = options.env || process.env;
80
+ const memory = command('free', ['-b'], options.runner || spawnSync);
81
+ const cpu = command('lscpu', [], options.runner || spawnSync);
82
+ const osRelease = command('uname', ['-a'], options.runner || spawnSync);
83
+ const memoryLine = memory.stdout.split(/\n/).find((line) => /^Mem:/i.test(line));
84
+ const memoryBytes = memoryLine ? Number(memoryLine.trim().split(/\s+/)[1]) || null : null;
85
+ return {
86
+ schema_version: COMPUTE_AUDIT_SCHEMA,
87
+ generated_at: new Date().toISOString(),
88
+ host: { platform: 'linux', arch: options.arch || process.arch, hostname: os.hostname() },
89
+ apple_silicon: false,
90
+ chip: { name: value(cpu.stdout, 'Model name') || value(cpu.stdout, 'Architecture'), family: null, cores: value(cpu.stdout, 'CPU\\(s\\)') },
91
+ memory: { unified_memory_bytes: null, system_memory_bytes: memoryBytes, vram_bytes: null, model: 'system' },
92
+ accelerators: [{ id: 'nvidia-smi', available: Boolean(executable('nvidia-smi', env)), evidence: 'optional' }],
93
+ shells: auditShells(options),
94
+ evidence: [{ source: 'uname', ok: osRelease.ok }, { source: 'lscpu', ok: cpu.ok }, { source: 'free', ok: memory.ok }],
95
+ warnings: ['Linux accelerator memory is engine/vendor-specific and is not inferred as system VRAM.'],
96
+ };
97
+ }
98
+
99
+ function auditWindowsHost(options = {}) {
100
+ const env = options.env || process.env;
101
+ const powershell = executable('pwsh', env) || executable('powershell.exe', env);
102
+ const result = powershell ? command(powershell, ['-NoProfile', '-NonInteractive', '-Command', '$c=Get-CimInstance Win32_ComputerSystem; $g=Get-CimInstance Win32_VideoController; [pscustomobject]@{model=$c.Model;memory=$c.TotalPhysicalMemory;gpu=($g.Name -join ";")}|ConvertTo-Json -Compress'], options.runner || spawnSync) : { ok: false, stdout: '' };
103
+ let facts = {}; try { facts = JSON.parse(result.stdout || '{}'); } catch {}
104
+ return {
105
+ schema_version: COMPUTE_AUDIT_SCHEMA,
106
+ generated_at: new Date().toISOString(),
107
+ host: { platform: 'windows', arch: options.arch || process.arch, hostname: os.hostname() },
108
+ apple_silicon: false,
109
+ chip: { name: facts.model || null, family: null, cores: null },
110
+ memory: { unified_memory_bytes: null, system_memory_bytes: Number(facts.memory) || null, vram_bytes: null, model: 'system' },
111
+ accelerators: [{ id: 'video-controller', available: Boolean(facts.gpu), name: facts.gpu || null }],
112
+ shells: auditShells(options),
113
+ evidence: [{ source: powershell || 'powershell', ok: result.ok }],
114
+ warnings: ['Windows GPU memory is reported only when the vendor API exposes it; no VRAM estimate is made.'],
115
+ };
116
+ }
117
+
118
+ function auditShells(options = {}) {
119
+ const env = options.env || process.env;
120
+ return ['pwsh', 'powershell.exe', 'bash', 'zsh', 'sh'].map((name) => ({ id: name, path: executable(name, env), available: Boolean(executable(name, env)) }));
121
+ }
122
+
123
+ export function auditHost(options = {}) {
124
+ const platform = options.platform || process.platform;
125
+ if (platform === 'darwin') return { ...auditAppleHost(options), shells: auditShells(options) };
126
+ if (platform === 'win32') return auditWindowsHost(options);
127
+ if (platform === 'linux') return auditLinuxHost(options);
128
+ return { ...parseAppleAudit({ platform, arch: options.arch || process.arch }), shells: auditShells(options) };
129
+ }
130
+
131
+ export function auditLocalCompute(options = {}) {
132
+ return { schema_version: COMPUTE_AUDIT_SCHEMA, generated_at: new Date().toISOString(), hardware: auditHost(options), engines: auditTools(options) };
133
+ }
@@ -0,0 +1,26 @@
1
+ import { LOCAL_ENGINE_BENCHMARK_SCHEMA } from './contracts.js';
2
+
3
+ function tokenCount(result) { return Number(result?.usage?.output_tokens || result?.usage?.completion_tokens || String(result?.output_text || '').trim().split(/\s+/).filter(Boolean).length); }
4
+ function validateShape(value, schema) {
5
+ if (!schema || typeof schema !== 'object') return { valid: true, error: null };
6
+ if (schema.type === 'object' && (value === null || typeof value !== 'object' || Array.isArray(value))) return { valid: false, error: 'expected_object' };
7
+ if (schema.type === 'array' && !Array.isArray(value)) return { valid: false, error: 'expected_array' };
8
+ if (schema.required) for (const key of schema.required) if (!(key in value)) return { valid: false, error: `missing_required:${key}` };
9
+ if (schema.properties && value && typeof value === 'object') for (const [key, child] of Object.entries(schema.properties)) if (key in value) { const result = validateShape(value[key], child); if (!result.valid) return { valid: false, error: `${key}.${result.error}` }; }
10
+ return { valid: true, error: null };
11
+ }
12
+ export function validateStructuredOutput(text, schema = null) {
13
+ try { const value = JSON.parse(String(text || '')); const shape = validateShape(value, schema); return { valid: shape.valid, parse_error: null, schema_error: shape.valid ? null : shape.error, value: shape.valid ? value : null, grammar_enforced: false, tool_arguments_valid: shape.valid }; } catch (error) { return { valid: false, parse_error: error.message, schema_error: null, value: null, grammar_enforced: false, tool_arguments_valid: false }; }
14
+ }
15
+ export async function benchmarkEngine(engine, options = {}) {
16
+ const runs = Math.max(1, Number(options.runs) || 1); const prompt = options.prompt || 'Reply with a short JSON object containing an answer field.'; const results = [];
17
+ for (let i = 0; i < runs; i += 1) {
18
+ const started = performance.now();
19
+ const result = await engine.chat({ model: options.model, messages: [{ role: 'user', content: prompt }], responseFormat: options.schema ? { type: 'json_object' } : null });
20
+ const ended = performance.now(); const outputTokens = tokenCount(result); const ttft = Number.isFinite(result?.timing?.ttft_ms) ? result.timing.ttft_ms : null; const elapsed = ended - started;
21
+ results.push({ run: i + 1, ttft_ms: ttft, elapsed_ms: elapsed, output_tokens: outputTokens, tokens_per_second: elapsed > 0 ? outputTokens / (elapsed / 1000) : null, structured_output: options.schema ? validateStructuredOutput(result.output_text, options.schema) : null });
22
+ }
23
+ return { schema_version: LOCAL_ENGINE_BENCHMARK_SCHEMA, engine_id: engine.id, model: options.model || null, generated_at: new Date().toISOString(), fixture: { id: options.fixtureId || 'default-json', prompt_hash: cryptoHash(prompt) }, runs: results, summary: summarize(results), resource: { memory: null, source: 'not_available' }, warnings: ['Memory utilization requires an engine/platform sampler.', 'TTFT is null unless the engine adapter reports a measured first-token time.'] };
24
+ }
25
+ function cryptoHash(value) { let h = 2166136261; for (const char of String(value)) h = Math.imul(h ^ char.charCodeAt(0), 16777619); return (h >>> 0).toString(16); }
26
+ function summarize(rows) { const average = (key) => { const values = rows.map((row) => row[key]).filter((x) => Number.isFinite(x)); return values.length ? values.reduce((a, b) => a + b, 0) / values.length : null; }; return { average_ttft_ms: average('ttft_ms'), average_tokens_per_second: average('tokens_per_second'), valid_structured_outputs: rows.filter((row) => row.structured_output?.valid === true).length, run_count: rows.length }; }
@@ -0,0 +1,101 @@
1
+ import { createToolError, ERROR_CODE, ERROR_REASON } from '@inneranimalmedia/agentsam-errors';
2
+
3
+ export const LOCAL_ENGINE_SCHEMA = 'agentsam.local-engine.v1';
4
+ export const LOCAL_ENGINE_BENCHMARK_SCHEMA = 'agentsam.engine.benchmark.v1';
5
+
6
+ export const ENGINE_CAPABILITIES = Object.freeze([
7
+ 'chat', 'chat.streaming', 'chat.tools', 'embed', 'embed.batch',
8
+ 'output.json', 'output.json_schema', 'output.grammar', 'model.load',
9
+ 'model.unload', 'metrics.ttft', 'metrics.tokens_per_second', 'metrics.memory',
10
+ 'runtime.metal', 'runtime.mlx', 'format.gguf', 'format.safetensors',
11
+ ]);
12
+
13
+ export const ENGINE_STATUS = Object.freeze(['installed', 'available', 'unavailable', 'unknown']);
14
+
15
+ export function clean(value) { return value == null ? '' : String(value).trim(); }
16
+
17
+ export function normalizeCapability(value) {
18
+ const id = clean(value).toLowerCase();
19
+ return ENGINE_CAPABILITIES.includes(id) ? id : null;
20
+ }
21
+
22
+ export function capabilityCard({ engineId, version = null, model = null, capabilities = {}, evidence = [], status = 'unknown', warnings = [] } = {}) {
23
+ if (!engineId) throw new TypeError('engineId is required');
24
+ const normalized = Object.fromEntries(ENGINE_CAPABILITIES.map((id) => [id, capabilities[id] === true]));
25
+ return Object.freeze({
26
+ schema_version: LOCAL_ENGINE_SCHEMA,
27
+ engine_id: clean(engineId),
28
+ version: version || null,
29
+ model: model || null,
30
+ status: ENGINE_STATUS.includes(status) ? status : 'unknown',
31
+ capabilities: Object.freeze(normalized),
32
+ evidence: Object.freeze(Array.isArray(evidence) ? evidence.map((row) => ({ ...row })) : []),
33
+ warnings: Object.freeze(Array.isArray(warnings) ? [...warnings] : []),
34
+ });
35
+ }
36
+
37
+ export function engineInventory({ engineId, version = null, installed = false, reachable = false, endpoint = null, models = [], capabilities = {}, evidence = [], warnings = [] } = {}) {
38
+ return Object.freeze({
39
+ schema_version: LOCAL_ENGINE_SCHEMA,
40
+ engine_id: clean(engineId),
41
+ version: version || null,
42
+ installed: installed === true,
43
+ reachable: reachable === true,
44
+ endpoint: endpoint || null,
45
+ models: Object.freeze((Array.isArray(models) ? models : []).map((row) => ({ ...row }))),
46
+ capabilities: Object.freeze({ ...capabilities }),
47
+ evidence: Object.freeze(Array.isArray(evidence) ? evidence.map((row) => ({ ...row })) : []),
48
+ warnings: Object.freeze(Array.isArray(warnings) ? [...warnings] : []),
49
+ });
50
+ }
51
+
52
+ export function engineError(localCode, message, details = {}) {
53
+ const unsupported = localCode === 'LOCAL_ENGINE_UNSUPPORTED';
54
+ const engineId = details.engine_id || details.engineId || 'unknown';
55
+ return createToolError({
56
+ tool: `local-engine.${engineId}`,
57
+ domain: 'runtime',
58
+ stage: details.operation || 'execute',
59
+ code: unsupported ? ERROR_CODE.UNIMPLEMENTED : ERROR_CODE.UNAVAILABLE,
60
+ reason: unsupported ? ERROR_REASON.UNSUPPORTED_OPERATION : ERROR_REASON.PROVIDER_UNAVAILABLE,
61
+ message: message || localCode,
62
+ retryable: !unsupported,
63
+ provider: engineId,
64
+ native: { code: localCode },
65
+ details: { ...details, local_code: localCode },
66
+ });
67
+ }
68
+
69
+ export function assertEngineContract(engine) {
70
+ for (const method of ['discover', 'capabilities', 'chat', 'embed', 'unload']) {
71
+ if (typeof engine?.[method] !== 'function') throw new TypeError(`local engine ${method}() is required`);
72
+ }
73
+ return engine;
74
+ }
75
+
76
+ export function normalizeChatResult(result = {}, engineId = null) {
77
+ return Object.freeze({
78
+ schema_version: LOCAL_ENGINE_SCHEMA,
79
+ engine_id: result.engine_id || engineId,
80
+ model: result.model || null,
81
+ status: result.status || 'completed',
82
+ output_text: String(result.output_text || ''),
83
+ tool_calls: Object.freeze(Array.isArray(result.tool_calls) ? result.tool_calls.map((row) => ({ ...row })) : []),
84
+ usage: Object.freeze({ ...(result.usage || {}) }),
85
+ timing: Object.freeze({ ...(result.timing || {}) }),
86
+ evidence: Object.freeze(Array.isArray(result.evidence) ? [...result.evidence] : []),
87
+ });
88
+ }
89
+
90
+ export function normalizeEmbedResult(result = {}, engineId = null) {
91
+ return Object.freeze({
92
+ schema_version: LOCAL_ENGINE_SCHEMA,
93
+ engine_id: result.engine_id || engineId,
94
+ model: result.model || null,
95
+ status: result.status || 'completed',
96
+ embeddings: Object.freeze(Array.isArray(result.embeddings) ? result.embeddings : []),
97
+ dimensions: Number(result.dimensions) || 0,
98
+ usage: Object.freeze({ ...(result.usage || {}) }),
99
+ evidence: Object.freeze(Array.isArray(result.evidence) ? [...result.evidence] : []),
100
+ });
101
+ }
@@ -0,0 +1,142 @@
1
+ import { resolveOllamaConfig, probeOllama, probeOllamaModel } from '../commands/ollama.js';
2
+ import { createOllamaChatAdapter } from '../providers/ollama-chat.js';
3
+ import { capabilityCard, engineInventory, engineError, normalizeChatResult, normalizeEmbedResult } from './contracts.js';
4
+ import { executable, fetchJson, runCommand, unsupported } from './runtime.js';
5
+
6
+ function modelNames(body) {
7
+ return Array.isArray(body?.models) ? body.models.map((row) => ({ name: row.name || row.model || '', size: row.size || null, digest: row.digest || null })).filter((row) => row.name) : [];
8
+ }
9
+
10
+ export function createOllamaEngine(options = {}) {
11
+ const env = options.env || process.env;
12
+ const fetchImpl = options.fetchImpl || fetch;
13
+ const config = resolveOllamaConfig(options, env);
14
+ return {
15
+ id: 'ollama',
16
+ async discover() {
17
+ const api = await probeOllama(config, fetchImpl);
18
+ const binary = runCommand('ollama', ['--version'], { env });
19
+ return engineInventory({
20
+ engineId: 'ollama', version: binary.ok ? String(binary.stdout || binary.stderr).trim() : null,
21
+ installed: binary.installed, reachable: api.online, endpoint: config.baseUrl,
22
+ models: api.models || [],
23
+ capabilities: { chat: api.chat_ready, embed: api.embed_ready, 'chat.streaming': false, 'chat.tools': true, 'model.unload': true },
24
+ evidence: [{ source: 'ollama', endpoint: config.baseUrl, status: api.status }],
25
+ warnings: api.error ? [api.error] : [],
26
+ });
27
+ },
28
+ async capabilities({ model } = {}) {
29
+ const probe = await probeOllamaModel(model || config.model, config, fetchImpl);
30
+ return capabilityCard({ engineId: 'ollama', model: model || config.model, status: probe.ok ? 'available' : 'unavailable', capabilities: {
31
+ chat: probe.ok, 'chat.streaming': false, 'chat.tools': probe.capabilities?.includes('tools') === true,
32
+ embed: false, 'output.json': true, 'output.json_schema': false, 'model.unload': true, 'metrics.ttft': true,
33
+ }, evidence: [{ source: 'ollama/api/show', context_window: probe.context_window, capabilities: probe.capabilities || [] }], warnings: probe.error ? [probe.error] : [] });
34
+ },
35
+ async chat(params = {}) {
36
+ const adapter = createOllamaChatAdapter({ endpoint: config.baseUrl, env, fetchImpl });
37
+ const result = await adapter.create({ ...params, modelRecord: { provider: 'ollama', provider_model_id: params.model || config.model, context_window: params.context_window || 0 } });
38
+ return normalizeChatResult({ ...result, timing: result.timing || {} }, 'ollama');
39
+ },
40
+ async embed({ model = config.embedModel, inputs = [] } = {}) {
41
+ const values = Array.isArray(inputs) ? inputs : [inputs];
42
+ const response = await fetchJson(`${config.baseUrl}/api/embed`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ model, input: values }) }, fetchImpl);
43
+ if (!response.ok) throw engineError('LOCAL_ENGINE_EMBED_FAILED', response.error || 'Ollama embedding failed', { engine_id: 'ollama' });
44
+ const embeddings = response.body?.embeddings || (response.body?.embedding ? [response.body.embedding] : []);
45
+ return normalizeEmbedResult({ model, embeddings, dimensions: embeddings[0]?.length || 0 }, 'ollama');
46
+ },
47
+ async unload({ model } = {}) {
48
+ const response = await fetchJson(`${config.baseUrl}/api/generate`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ model: model || config.model, prompt: '', keep_alive: 0 }) }, fetchImpl);
49
+ return { schema_version: 'agentsam.local-engine.v1', engine_id: 'ollama', model: model || config.model, unloaded: response.ok, status: response.ok ? 'completed' : 'unavailable', error: response.error || null };
50
+ },
51
+ };
52
+ }
53
+
54
+ function openAiEndpoint(options, defaultUrl) {
55
+ const env = options.env || process.env;
56
+ return String(options.endpoint || env[options.envKey || 'AGENTSAM_LOCAL_ENGINE_ENDPOINT'] || defaultUrl).replace(/\/$/, '');
57
+ }
58
+
59
+ function createOpenAiCompatibleEngine({ id, endpoint, command, versionArgs = ['--version'], env = process.env, capabilities = {}, options = {} }) {
60
+ const fetchImpl = options.fetchImpl || fetch;
61
+ return {
62
+ id,
63
+ async discover() {
64
+ const binary = runCommand(command, versionArgs, { env });
65
+ const health = await fetchJson(`${endpoint}/v1/models`, {}, fetchImpl);
66
+ return engineInventory({
67
+ engineId: id,
68
+ version: binary.ok ? String(binary.stdout || binary.stderr).trim() : null,
69
+ installed: binary.ok,
70
+ reachable: health.ok,
71
+ endpoint,
72
+ models: modelNames(health.body?.data ? { models: health.body.data.map((row) => ({ name: row.id })) } : health.body),
73
+ capabilities,
74
+ evidence: [
75
+ { source: 'binary-probe', command, binary: binary.binary || null, ok: binary.ok, exit_status: binary.status },
76
+ { source: 'openai-compatible', endpoint, ok: health.ok, status: health.status },
77
+ ],
78
+ warnings: health.error ? [health.error] : [],
79
+ });
80
+ },
81
+ async capabilities({ model = null } = {}) { return capabilityCard({ engineId: id, model, status: 'unknown', capabilities, evidence: [{ source: 'adapter declaration', endpoint }], warnings: ['Model-specific capabilities require a live probe.'] }); },
82
+ async chat({ model, messages = [], tools = [], responseFormat = null, onEvent, signal } = {}) {
83
+ const started = performance.now();
84
+ const response = await fetchJson(`${endpoint}/v1/chat/completions`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ model, messages, tools: tools.length ? tools : undefined, response_format: responseFormat || undefined, stream: false }), signal }, fetchImpl);
85
+ if (!response.ok) throw engineError('LOCAL_ENGINE_CHAT_FAILED', response.error || `${id} chat failed`, { engine_id: id });
86
+ const choice = response.body?.choices?.[0] || {};
87
+ const text = choice.message?.content || '';
88
+ return normalizeChatResult({ model, output_text: text, tool_calls: choice.message?.tool_calls || [], usage: response.body?.usage || {}, timing: { elapsed_ms: performance.now() - started, ttft_ms: null } }, id);
89
+ },
90
+ async embed({ model, inputs = [], signal } = {}) {
91
+ const response = await fetchJson(`${endpoint}/v1/embeddings`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ model, input: inputs }), signal }, fetchImpl);
92
+ if (!response.ok) throw engineError('LOCAL_ENGINE_EMBED_FAILED', response.error || `${id} embedding failed`, { engine_id: id });
93
+ const embeddings = (response.body?.data || []).sort((a, b) => a.index - b.index).map((row) => row.embedding);
94
+ return normalizeEmbedResult({ model, embeddings, dimensions: embeddings[0]?.length || 0, usage: response.body?.usage || {} }, id);
95
+ },
96
+ async unload({ model, signal } = {}) { return { schema_version: 'agentsam.local-engine.v1', engine_id: id, model, unloaded: false, status: 'unsupported', error: unsupported(id, 'unload').message, signal: Boolean(signal) }; },
97
+ };
98
+ }
99
+
100
+ export function createMlxLmEngine(options = {}) {
101
+ const endpoint = openAiEndpoint(options, 'http://127.0.0.1:8080');
102
+ return createOpenAiCompatibleEngine({
103
+ id: 'mlx-lm',
104
+ endpoint,
105
+ command: options.command || 'python3',
106
+ versionArgs: options.versionArgs || ['-c', 'import importlib.metadata as m; print(m.version("mlx-lm"))'],
107
+ env: options.env || process.env,
108
+ capabilities: {
109
+ chat: true,
110
+ 'chat.streaming': false,
111
+ embed: false,
112
+ 'runtime.mlx': process.platform === 'darwin' && process.arch === 'arm64',
113
+ 'runtime.metal': process.platform === 'darwin' && process.arch === 'arm64',
114
+ 'output.json': true,
115
+ },
116
+ options,
117
+ });
118
+ }
119
+
120
+ export function createLlamaCppEngine(options = {}) {
121
+ const endpoint = openAiEndpoint(options, 'http://127.0.0.1:8080');
122
+ return createOpenAiCompatibleEngine({
123
+ id: 'llama.cpp',
124
+ endpoint,
125
+ command: options.command || 'llama-server',
126
+ env: options.env || process.env,
127
+ capabilities: {
128
+ chat: true,
129
+ 'chat.streaming': false,
130
+ 'chat.tools': true,
131
+ embed: true,
132
+ 'format.gguf': true,
133
+ 'runtime.metal': process.platform === 'darwin',
134
+ 'output.grammar': true,
135
+ 'output.json_schema': true,
136
+ 'model.unload': false,
137
+ },
138
+ options,
139
+ });
140
+ }
141
+
142
+ export function defaultLocalEngines(options = {}) { return [createOllamaEngine(options), createMlxLmEngine(options.mlx || options), createLlamaCppEngine(options.llamaCpp || options)]; }
@@ -0,0 +1,18 @@
1
+ import { assertEngineContract } from './contracts.js';
2
+ import { defaultLocalEngines } from './engines.js';
3
+
4
+ export class LocalEngineRegistry {
5
+ constructor(engines = defaultLocalEngines()) { this.engines = new Map(engines.map((engine) => [engine.id, assertEngineContract(engine)])); }
6
+ register(engine) { this.engines.set(engine.id, assertEngineContract(engine)); return this; }
7
+ get(id) { const engine = this.engines.get(id); if (!engine) throw new Error(`unknown_local_engine:${id}`); return engine; }
8
+ list() { return [...this.engines.values()].map((engine) => engine.id); }
9
+ async discover() { return Promise.all([...this.engines.values()].map((engine) => engine.discover())); }
10
+ async capabilities(request = {}) { return this.get(request.engine_id || request.engineId).capabilities(request); }
11
+ }
12
+
13
+ export function createLocalEngineRegistry(options = {}) { return new LocalEngineRegistry(options.engines || defaultLocalEngines(options)); }
14
+ export * from './contracts.js';
15
+ export * from './engines.js';
16
+ export * from './audit.js';
17
+ export * from './assets.js';
18
+ export * from './benchmark.js';
@@ -0,0 +1,39 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { engineError } from './contracts.js';
3
+
4
+ export function executable(command, env = process.env) {
5
+ if (!command) return null;
6
+ const finder = process.platform === 'win32' ? 'where' : 'which';
7
+ const result = spawnSync(finder, [command], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], env });
8
+ return result.status === 0 ? String(result.stdout || '').split(/\r?\n/).map((x) => x.trim()).find(Boolean) || null : null;
9
+ }
10
+
11
+ export function runCommand(command, args = [], options = {}) {
12
+ const binary = options.binary || executable(command, options.env || process.env);
13
+ if (!binary) return { ok: false, installed: false, command, args, stdout: '', stderr: '', status: null };
14
+ const result = spawnSync(binary, args, {
15
+ encoding: 'utf8',
16
+ env: options.env || process.env,
17
+ timeout: options.timeout || 3000,
18
+ stdio: ['ignore', 'pipe', 'pipe'],
19
+ maxBuffer: options.maxBuffer || 4 * 1024 * 1024,
20
+ });
21
+ return { ok: result.status === 0, installed: true, command, args, binary, stdout: String(result.stdout || ''), stderr: String(result.stderr || ''), status: result.status, error: result.error || null };
22
+ }
23
+
24
+ export async function fetchJson(url, init = {}, fetchImpl = fetch) {
25
+ try {
26
+ const response = await fetchImpl(url, { ...init, signal: init.signal || AbortSignal.timeout(3000) });
27
+ const text = await response.text();
28
+ let body = null;
29
+ try { body = text ? JSON.parse(text) : null; } catch { body = null; }
30
+ if (!response.ok) return { ok: false, status: response.status, body, error: `HTTP ${response.status}` };
31
+ return { ok: true, status: response.status, body };
32
+ } catch (error) {
33
+ return { ok: false, status: null, body: null, error: error?.message || String(error) };
34
+ }
35
+ }
36
+
37
+ export function unsupported(engineId, operation) {
38
+ return engineError('LOCAL_ENGINE_UNSUPPORTED', `${engineId} does not support ${operation}`, { engine_id: engineId, operation });
39
+ }
@@ -0,0 +1,41 @@
1
+ import { defineSamOperation } from '../define.js';
2
+ import { auditPackages } from '../../commands/package.js';
3
+
4
+ export const packageAuditOp = defineSamOperation({
5
+ id: 'package.audit',
6
+ version: 1,
7
+ module: 'package',
8
+ action: 'audit',
9
+ summary: 'Audit AgentSam package publication intent, registry state, and structural blockers.',
10
+ purpose:
11
+ 'Establish deterministic package-distribution authority for @inneranimalmedia packages without publishing anything.',
12
+ outcome:
13
+ 'Return classified package manifests, public-distribution intent, registry state when allowed, and structural blockers.',
14
+ description:
15
+ 'Discover scoped package manifests, classify public/private intent, optionally query npm registry state, and return a bounded read-only audit.',
16
+ skill: { id: 'agentsam-progression-guard', help: true },
17
+ accepts: ['root', 'publicOnly', 'offline'],
18
+ phases: ['discover_manifests', 'classify_intent', 'resolve_registry_state', 'emit_audit'],
19
+ execution: {
20
+ lanes: ['local', 'remote', 'sandbox'],
21
+ model: 'never',
22
+ embedding: 'never',
23
+ network: 'optional',
24
+ sideEffects: 'none',
25
+ provider_spend: 'none',
26
+ },
27
+ risk: 'read_only',
28
+ capabilities: ['package.audit'],
29
+ artifacts: ['package.audit'],
30
+ cli: { command: [['package', 'audit']] },
31
+ docs: { section: 'Packages' },
32
+ status: 'stable',
33
+ async handler(input = {}, ctx = {}) {
34
+ const root = input.root || input.cwd || ctx.cwd || process.cwd();
35
+ return auditPackages({
36
+ root,
37
+ publicOnly: input.publicOnly === true || input.public === true,
38
+ offline: input.offline === true,
39
+ });
40
+ },
41
+ });
package/src/sam/seed.js CHANGED
@@ -8,6 +8,7 @@ import { codebaseindexIngestOp } from './operations/codebaseindex-ingest.js';
8
8
  import { planningAstarOp } from './operations/planning-astar.js';
9
9
  import { planningGoapOp } from './operations/planning-goap.js';
10
10
  import { decisionEvaluateOp } from './operations/decision-evaluate.js';
11
+ import { packageAuditOp } from './operations/package-audit.js';
11
12
 
12
13
  export const SEED_OPERATIONS = [
13
14
  repositoryInspect,
@@ -19,6 +20,7 @@ export const SEED_OPERATIONS = [
19
20
  planningAstarOp,
20
21
  planningGoapOp,
21
22
  decisionEvaluateOp,
23
+ packageAuditOp,
22
24
  ];
23
25
 
24
26
  let seeded = false;