@inneranimalmedia/agentsam-sdk 2.6.7 → 2.6.8

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 (318) hide show
  1. package/README.md +37 -0
  2. package/docs/REPO_FILE_MAP.txt +132 -0
  3. package/migrations/d1/0018_goap_control_plane_remaster.sql +40 -0
  4. package/migrations/d1/0019_agentsam_agent_run_plan_todo.sql +14 -0
  5. package/migrations/d1/README_PORTABLE_CONTROL_PLANE.md +20 -9
  6. package/migrations/runtime/0002_goap_blackboard_v1.sql +15 -0
  7. package/migrations/runtime/0004_agent_run_plan_linkage.sql +8 -0
  8. package/native/agentsam-machine/cli/Cargo.toml +8 -1
  9. package/native/agentsam-machine/cli/README.md +21 -0
  10. package/native/agentsam-machine/core/Cargo.toml +7 -0
  11. package/native/agentsam-machine/core/README.md +14 -0
  12. package/native/agentsam-machine/core/build.rs +33 -0
  13. package/native/agentsam-machine/core/contracts/source-types.v1.json +353 -0
  14. package/native/agentsam-machine/core/src/lib.rs +6 -0
  15. package/native/agentsam-machine/core/src/source_types.rs +2 -2
  16. package/package.json +16 -6
  17. package/packages/agentsam-errors/package.json +1 -1
  18. package/packages/agentsam-errors/src/index.js +1 -0
  19. package/packages/agentsam-errors/src/tool.js +56 -0
  20. package/packages/agentsam-errors/test/tool.test.mjs +58 -0
  21. package/packages/agentsam-goap/README.md +52 -0
  22. package/packages/agentsam-goap/package.json +37 -0
  23. package/packages/agentsam-goap/src/adapters/d1-sqlite.js +570 -0
  24. package/packages/agentsam-goap/src/adapters/memory.js +199 -0
  25. package/packages/agentsam-goap/src/contracts.js +226 -0
  26. package/packages/agentsam-goap/src/control-plane.js +112 -0
  27. package/packages/agentsam-goap/src/errors.js +157 -0
  28. package/packages/agentsam-goap/src/index.js +5 -0
  29. package/packages/agentsam-goap/src/world.js +202 -0
  30. package/packages/agentsam-goap/test/goap-control-plane.test.mjs +245 -0
  31. package/packages/agentsam-goap/test/world.test.mjs +79 -0
  32. package/packages/agentsam-nav/dist/Nav.d.ts +43 -0
  33. package/packages/agentsam-nav/dist/NavCollapsible.d.ts +10 -0
  34. package/packages/agentsam-nav/dist/NavContent.d.ts +2 -0
  35. package/packages/agentsam-nav/dist/NavFooter.d.ts +2 -0
  36. package/packages/agentsam-nav/dist/NavGroup.d.ts +3 -0
  37. package/packages/agentsam-nav/dist/NavHeader.d.ts +2 -0
  38. package/packages/agentsam-nav/dist/NavMenu.d.ts +22 -0
  39. package/packages/agentsam-nav/dist/NavProvider.d.ts +35 -0
  40. package/packages/agentsam-nav/dist/NavTrigger.d.ts +2 -0
  41. package/packages/agentsam-nav/dist/Surfaces.d.ts +41 -0
  42. package/packages/agentsam-nav/dist/browser.d.ts +11 -0
  43. package/packages/agentsam-nav/dist/browser.global.js +135 -0
  44. package/packages/agentsam-nav/dist/browser.js +7290 -0
  45. package/packages/agentsam-nav/dist/contracts.d.ts +76 -0
  46. package/packages/agentsam-nav/dist/index.d.ts +11 -0
  47. package/packages/agentsam-nav/dist/index.js +7291 -0
  48. package/packages/agentsam-nav/dist/legacy.css +83 -0
  49. package/packages/agentsam-nav/dist/shell.css +113 -0
  50. package/packages/agentsam-nav/dist/theme.css +113 -0
  51. package/packages/agentsam-nav/dist/utils.d.ts +1 -0
  52. package/packages/agentsam-repository/src/goap.js +13 -14
  53. package/packages/agentsam-repository/src/goap.js.bak-20260922011251 +670 -0
  54. package/packages/agentsam-repository/src/tickets.js +15 -22
  55. package/packages/agentsam-repository/test/goap-tickets-workspace-state.test.mjs +19 -8
  56. package/packages/connectors/cloudflare/package.json +3 -1
  57. package/packages/identity/tests/lane1-packed-consumer.test.mjs +1 -1
  58. package/python/agentsam_sdk/repository/intelligence/discovery.py +27 -2
  59. package/python/agentsam_sdk/repository/intelligence/git.py +4 -0
  60. package/python/tests/test_repository_intelligence.py +30 -0
  61. package/src/cli/command-catalog.js +2 -1
  62. package/src/cli.js +10 -1
  63. package/src/commands/goap-world.js +134 -0
  64. package/src/commands/goap.js +11 -4
  65. package/src/commands/machine-binary.js +33 -27
  66. package/src/commands/machine-runtime.js +266 -0
  67. package/src/commands/machine.js +122 -51
  68. package/src/commands/package.js +530 -0
  69. package/src/commands/plan-ledger.js +370 -0
  70. package/src/commands/plan.js +183 -0
  71. package/src/commands/skill.js +78 -17
  72. package/src/knowledge/source.js +1 -1
  73. package/src/lib/slash-commands.js +1 -1
  74. package/src/local/runtime-store.js +24 -2
  75. package/src/local/sqlite.js +17 -0
  76. package/src/sam/operations/package-audit.js +41 -0
  77. package/src/sam/seed.js +2 -0
  78. package/skills/grok-auth/SKILL.md +0 -110
  79. package/skills/grok-auth/agentsam.skill.json +0 -25
  80. package/skills/grok-auth/references/grok-identity.md +0 -64
  81. package/skills/grok-auth/references/per-user-data.md +0 -49
  82. package/skills/grok-auth/references/prewired-and-env.md +0 -54
  83. package/skills/grok-auth/references/session-ui.md +0 -133
  84. package/skills/grok-auth/references/sign-in-methods.md +0 -55
  85. package/skills/grok-auth/references/wiring.md +0 -71
  86. package/skills/grok-building-games/SKILL.md +0 -213
  87. package/skills/grok-building-games/agentsam.skill.json +0 -25
  88. package/skills/grok-building-games/references/3d-libs.md +0 -64
  89. package/skills/grok-building-games/references/ai-pathfinding.md +0 -122
  90. package/skills/grok-building-games/references/audio.md +0 -129
  91. package/skills/grok-building-games/references/babylon.md +0 -202
  92. package/skills/grok-building-games/references/collision-physics.md +0 -122
  93. package/skills/grok-building-games/references/ecs-architecture.md +0 -111
  94. package/skills/grok-building-games/references/game-feel-juice.md +0 -110
  95. package/skills/grok-building-games/references/genres/board-card-chess.md +0 -89
  96. package/skills/grok-building-games/references/genres/endless-runner.md +0 -83
  97. package/skills/grok-building-games/references/genres/fps.md +0 -105
  98. package/skills/grok-building-games/references/genres/platformer-2d.md +0 -97
  99. package/skills/grok-building-games/references/genres/puzzle-match3-tetris.md +0 -131
  100. package/skills/grok-building-games/references/genres/racing-kart.md +0 -106
  101. package/skills/grok-building-games/references/genres/topdown-twin-stick.md +0 -97
  102. package/skills/grok-building-games/references/genres/tower-defense.md +0 -84
  103. package/skills/grok-building-games/references/genres/voxel-minecraft.md +0 -89
  104. package/skills/grok-building-games/references/input.md +0 -139
  105. package/skills/grok-building-games/references/phaser.md +0 -277
  106. package/skills/grok-building-games/references/procedural-generation.md +0 -141
  107. package/skills/grok-building-games/references/save-persistence.md +0 -108
  108. package/skills/grok-building-games/references/threejs-foundational.md +0 -148
  109. package/skills/grok-controls/SKILL.md +0 -274
  110. package/skills/grok-controls/agentsam.skill.json +0 -25
  111. package/skills/grok-design-ui/SKILL.md +0 -122
  112. package/skills/grok-design-ui/agentsam.skill.json +0 -25
  113. package/skills/grok-design-ui/references/animations.md +0 -379
  114. package/skills/grok-design-ui/references/performance.md +0 -88
  115. package/skills/grok-design-ui/references/refined-ui.md +0 -384
  116. package/skills/grok-design-ui/references/surfaces.md +0 -247
  117. package/skills/grok-design-ui/references/typography.md +0 -123
  118. package/skills/grok-game-animation-frames/SKILL.md +0 -84
  119. package/skills/grok-game-animation-frames/agentsam.skill.json +0 -25
  120. package/skills/grok-game-asset-core/SKILL.md +0 -69
  121. package/skills/grok-game-asset-core/agentsam.skill.json +0 -25
  122. package/skills/grok-game-character-consistency/SKILL.md +0 -69
  123. package/skills/grok-game-character-consistency/agentsam.skill.json +0 -25
  124. package/skills/grok-game-tilesets/SKILL.md +0 -65
  125. package/skills/grok-game-tilesets/agentsam.skill.json +0 -25
  126. package/skills/grok-game-ui-icons/SKILL.md +0 -56
  127. package/skills/grok-game-ui-icons/agentsam.skill.json +0 -25
  128. package/skills/grok-generate2dmap/LICENSE +0 -21
  129. package/skills/grok-generate2dmap/SKILL.md +0 -120
  130. package/skills/grok-generate2dmap/SOURCE.md +0 -6
  131. package/skills/grok-generate2dmap/agentsam.skill.json +0 -25
  132. package/skills/grok-generate2dmap/references/deliverables.md +0 -101
  133. package/skills/grok-generate2dmap/references/layered-map-contract.md +0 -209
  134. package/skills/grok-generate2dmap/references/map-strategies.md +0 -341
  135. package/skills/grok-generate2dmap/references/object-production-gate.md +0 -24
  136. package/skills/grok-generate2dmap/references/pipeline.md +0 -149
  137. package/skills/grok-generate2dmap/references/prop-pack-contract.md +0 -174
  138. package/skills/grok-generate2dmap/references/side-scroll-stages.md +0 -29
  139. package/skills/grok-generate2dmap/scripts/compose_layered_preview.py +0 -157
  140. package/skills/grok-generate2dmap/scripts/extract_prop_pack.py +0 -369
  141. package/skills/grok-generate2dsprite/LICENSE +0 -21
  142. package/skills/grok-generate2dsprite/SKILL.md +0 -313
  143. package/skills/grok-generate2dsprite/SOURCE.md +0 -6
  144. package/skills/grok-generate2dsprite/agentsam.skill.json +0 -25
  145. package/skills/grok-generate2dsprite/references/modes.md +0 -124
  146. package/skills/grok-generate2dsprite/references/prompt-rules.md +0 -315
  147. package/skills/grok-generate2dsprite/scripts/generate2dsprite.py +0 -1031
  148. package/skills/grok-generate2dsprite/scripts/make_layout_guide.py +0 -109
  149. package/skills/grok-imagine/SKILL.md +0 -201
  150. package/skills/grok-imagine/agentsam.skill.json +0 -25
  151. package/skills/grok-multiplayer-p2p/SKILL.md +0 -111
  152. package/skills/grok-multiplayer-p2p/agentsam.skill.json +0 -25
  153. package/skills/grok-multiplayer-p2p/references/react-binding.md +0 -144
  154. package/skills/grok-multiplayer-p2p/references/signaling-relay.md +0 -269
  155. package/skills/grok-neon/SKILL.md +0 -157
  156. package/skills/grok-neon/agentsam.skill.json +0 -25
  157. package/skills/grok-og/SKILL.md +0 -102
  158. package/skills/grok-og/agentsam.skill.json +0 -25
  159. package/skills/grok-og/references/brand-pass.md +0 -53
  160. package/skills/grok-og/references/custom-card.md +0 -107
  161. package/skills/grok-og/references/favicon-and-icons.md +0 -48
  162. package/skills/grok-og/references/og-type-contract.md +0 -18
  163. package/skills/grok-og/references/placeholder-card.md +0 -21
  164. package/skills/grok-og/references/x-banner.md +0 -41
  165. package/skills/grok-threejs/SKILL.md +0 -67
  166. package/skills/grok-threejs/agentsam.skill.json +0 -25
  167. package/skills/grok-threejs/references/llms-full.txt +0 -2780
  168. package/skills/grok-video2dsprite/LICENSE +0 -21
  169. package/skills/grok-video2dsprite/SKILL.md +0 -236
  170. package/skills/grok-video2dsprite/SOURCE.md +0 -6
  171. package/skills/grok-video2dsprite/agentsam.skill.json +0 -25
  172. package/skills/grok-video2dsprite/references/pipeline.md +0 -90
  173. package/skills/grok-video2dsprite/references/prompt-rules.md +0 -63
  174. package/skills/grok-video2dsprite/scripts/video2dsprite.py +0 -490
  175. package/skills/grok-xai-api/SKILL.md +0 -152
  176. package/skills/grok-xai-api/agentsam.skill.json +0 -25
  177. package/test/account-session.test.mjs +0 -101
  178. package/test/agent-capabilities.test.mjs +0 -67
  179. package/test/app-authority-context.test.mjs +0 -32
  180. package/test/app-building-skills.test.mjs +0 -61
  181. package/test/apps-scaffold-contract.test.mjs +0 -115
  182. package/test/blender-cad.test.mjs +0 -146
  183. package/test/cad-docker.test.mjs +0 -96
  184. package/test/capabilities.test.mjs +0 -133
  185. package/test/cli/api-key-env-whoami.test.mjs +0 -129
  186. package/test/cli/catalog-authority.test.mjs +0 -64
  187. package/test/cli/codebaseindex-plan-ux.test.mjs +0 -37
  188. package/test/cli/eval-live.test.mjs +0 -219
  189. package/test/cli/go.test.mjs +0 -128
  190. package/test/cli/local-vault-and-provider-setup.test.mjs +0 -268
  191. package/test/cli/machine-command.test.mjs +0 -34
  192. package/test/cli/mcp-client.test.mjs +0 -256
  193. package/test/cli/preferences-runtime.test.mjs +0 -11
  194. package/test/cli/runtime-persist.test.mjs +0 -56
  195. package/test/cli/runtime-ui.test.mjs +0 -141
  196. package/test/cli/rust-command.test.mjs +0 -21
  197. package/test/cli/skill-npm-and-env.test.mjs +0 -52
  198. package/test/cli/status-actions.test.mjs +0 -88
  199. package/test/cli/wireframes-go-registry.test.mjs +0 -139
  200. package/test/cli-preferences.test.mjs +0 -46
  201. package/test/cloudflare-connector.test.mjs +0 -93
  202. package/test/cloudflare-runtime.test.mjs +0 -82
  203. package/test/context.test.mjs +0 -159
  204. package/test/credentials-audit.test.mjs +0 -113
  205. package/test/deploy-health-scan.test.mjs +0 -95
  206. package/test/deploy-receipt.test.mjs +0 -91
  207. package/test/dockerize.test.mjs +0 -93
  208. package/test/error-diagnostics.test.mjs +0 -124
  209. package/test/eval-context.test.mjs +0 -37
  210. package/test/execution-approvals.test.mjs +0 -27
  211. package/test/fixtures/cad/courtyard-house.json +0 -208
  212. package/test/fixtures/knowledge-rpc-worker.mjs +0 -16
  213. package/test/fixtures/project-authority/customer-app/.agentsam/app.json +0 -5
  214. package/test/fixtures/project-authority/customer-app/apps/my-product/index.ts +0 -1
  215. package/test/fixtures/project-authority/customer-app/wrangler.toml +0 -17
  216. package/test/gcloud-auth.test.mjs +0 -111
  217. package/test/go/build-source-identity.test.mjs +0 -31
  218. package/test/go/cloudflare-probe.test.mjs +0 -317
  219. package/test/go/distribution.test.mjs +0 -28
  220. package/test/google-cloud-connection.test.mjs +0 -83
  221. package/test/google-cloud-inventory.test.mjs +0 -64
  222. package/test/indexing-provider.test.mjs +0 -29
  223. package/test/init-options.test.mjs +0 -35
  224. package/test/integration/ai-access-onboarding.test.mjs +0 -47
  225. package/test/integration/app-command.test.mjs +0 -85
  226. package/test/integration/autorag-project-authority.integration.test.mjs +0 -51
  227. package/test/integration/autorag-runtime-discovery.test.mjs +0 -107
  228. package/test/integration/cad-discovery.test.mjs +0 -158
  229. package/test/integration/cad-docker-executor.test.mjs +0 -249
  230. package/test/integration/cad-execution.test.mjs +0 -184
  231. package/test/integration/cad-project-app.test.mjs +0 -31
  232. package/test/integration/cad-project-d1.test.mjs +0 -25
  233. package/test/integration/cad-project-native.test.mjs +0 -24
  234. package/test/integration/cad-project-workflow.test.mjs +0 -9
  235. package/test/integration/cad-project.test.mjs +0 -85
  236. package/test/integration/cli-help.test.mjs +0 -41
  237. package/test/integration/cms-app-scaffold.test.mjs +0 -77
  238. package/test/integration/cms-site-tenancy-contract.test.mjs +0 -268
  239. package/test/integration/codebaseindex-ingest.test.mjs +0 -255
  240. package/test/integration/core-client.integration.test.mjs +0 -55
  241. package/test/integration/database-hosted-honesty.test.mjs +0 -49
  242. package/test/integration/desktop-keychain-boundary.test.mjs +0 -45
  243. package/test/integration/error-runtime-rpc.test.mjs +0 -71
  244. package/test/integration/features-resolve.test.mjs +0 -147
  245. package/test/integration/hosted-work-host-authority.test.mjs +0 -47
  246. package/test/integration/icon-registry.test.mjs +0 -67
  247. package/test/integration/ingest-discover-models.test.mjs +0 -30
  248. package/test/integration/inspect-path-cli.test.mjs +0 -46
  249. package/test/integration/install-script.test.mjs +0 -110
  250. package/test/integration/inventory-core.test.mjs +0 -53
  251. package/test/integration/inventory-eligibility.test.mjs +0 -59
  252. package/test/integration/inventory-evidence.test.mjs +0 -125
  253. package/test/integration/knowledge-rpc.test.mjs +0 -112
  254. package/test/integration/local-fs.test.mjs +0 -113
  255. package/test/integration/local-provider-bridge.test.mjs +0 -65
  256. package/test/integration/local-studio-settings-production.test.mjs +0 -40
  257. package/test/integration/lockfile-sync.test.mjs +0 -26
  258. package/test/integration/merkle-cli.test.mjs +0 -61
  259. package/test/integration/merkle-persistence-identity.test.mjs +0 -48
  260. package/test/integration/plugins-cloudflare.integration.test.mjs +0 -28
  261. package/test/integration/provider-env-cli.test.mjs +0 -60
  262. package/test/integration/provider-factory.test.mjs +0 -197
  263. package/test/integration/repository-company-graph.test.mjs +0 -90
  264. package/test/integration/runtime-migrations.test.mjs +0 -87
  265. package/test/integration/runtime-status.integration.test.mjs +0 -227
  266. package/test/integration/sam-activity-recovery.test.mjs +0 -147
  267. package/test/integration/sam-decision.test.mjs +0 -584
  268. package/test/integration/sam-kernel.test.mjs +0 -99
  269. package/test/integration/sam-planning-astar.test.mjs +0 -279
  270. package/test/integration/scaffold-cloudflare.test.mjs +0 -46
  271. package/test/integration/skill-runtime.test.mjs +0 -240
  272. package/test/integration/storage-architecture.test.mjs +0 -154
  273. package/test/integration/store-discovery.test.mjs +0 -44
  274. package/test/integration/studio-fs-pty-e2e.test.mjs +0 -294
  275. package/test/integration/terminal-exec.integration.test.mjs +0 -86
  276. package/test/integration/theme-package-registry.test.mjs +0 -31
  277. package/test/integration/tool-runtime.test.mjs +0 -124
  278. package/test/integration/tool-schema.test.mjs +0 -59
  279. package/test/jr-dev-skill.test.mjs +0 -26
  280. package/test/knowledge-context-pack.test.mjs +0 -19
  281. package/test/knowledge-postgres.test.mjs +0 -40
  282. package/test/knowledge-service.test.mjs +0 -110
  283. package/test/knowledge.test.mjs +0 -206
  284. package/test/live/terminal-transport.live.test.mjs +0 -24
  285. package/test/local-sessions.test.mjs +0 -57
  286. package/test/local-studio-deploy.test.mjs +0 -83
  287. package/test/loopback-oauth.test.mjs +0 -53
  288. package/test/merkle-render.test.mjs +0 -31
  289. package/test/mini.test.mjs +0 -140
  290. package/test/model-catalog.test.mjs +0 -70
  291. package/test/models.test.mjs +0 -309
  292. package/test/npm10-lock.test.mjs +0 -29
  293. package/test/ollama.test.mjs +0 -137
  294. package/test/open-url.test.mjs +0 -64
  295. package/test/openai-responses.test.mjs +0 -155
  296. package/test/portable-context.test.mjs +0 -94
  297. package/test/project-config.test.mjs +0 -81
  298. package/test/project-rules.test.mjs +0 -44
  299. package/test/provider-credentials.test.mjs +0 -106
  300. package/test/rehydrate.test.mjs +0 -25
  301. package/test/release-hygiene.test.mjs +0 -42
  302. package/test/repository-snapshot-view.test.mjs +0 -112
  303. package/test/responses-runner.test.mjs +0 -465
  304. package/test/runtime-activity.test.mjs +0 -98
  305. package/test/sdk-worker-contract.test.mjs +0 -72
  306. package/test/security.test.mjs +0 -266
  307. package/test/setup-planner.test.mjs +0 -74
  308. package/test/setup-runtime.test.mjs +0 -51
  309. package/test/shell.test.mjs +0 -281
  310. package/test/skills.test.mjs +0 -22
  311. package/test/smoke.mjs +0 -122
  312. package/test/telemetry.test.mjs +0 -79
  313. package/test/terminal/local-pty.mock.test.mjs +0 -153
  314. package/test/terminal-machine-identity.test.mjs +0 -88
  315. package/test/theme-portability.test.mjs +0 -14
  316. package/test/tools-search.test.mjs +0 -73
  317. package/test/unit/website-assets-bindings.test.mjs +0 -60
  318. package/test/whoami-resume.test.mjs +0 -157
@@ -1,281 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import fs from 'node:fs';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import { spawnSync } from 'node:child_process';
6
- import test from 'node:test';
7
- import { dispatchShellLine, installPasteCollapse, renderCollapsedPaste, renderShellCatalog, renderShellPrompt, shouldCollapsePaste, tokenizeShellLine } from '../src/commands/shell.js';
8
- import { readCliPreferences, writeCliPreferences } from '../src/lib/cli-preferences.js';
9
-
10
- const repoRoot = path.resolve(new URL('..', import.meta.url).pathname);
11
-
12
- test('shell tokenizer preserves Windows paths and quoted arguments', () => {
13
- assert.deepEqual(tokenizeShellLine('/cd C:\\Users\\conno\\fuelnreetime'), ['/cd', 'C:\\Users\\conno\\fuelnreetime']);
14
- assert.deepEqual(tokenizeShellLine('/cd "C:\\Users\\Connor Smith\\repo"'), ['/cd', 'C:\\Users\\Connor Smith\\repo']);
15
- assert.deepEqual(tokenizeShellLine('/agent "inspect this repo"'), ['/agent', 'inspect this repo']);
16
- });
17
-
18
- test('interactive prompt derives username and cwd instead of hardcoding Agent Sam identity', () => {
19
- const env = { USER: 'alice', HOME: '/Users/alice' };
20
- assert.equal(renderShellPrompt('/Users/alice/code/demo', env), 'alice ~/code/demo > ');
21
- assert.equal(renderShellPrompt('/Users/alice', env), 'alice ~ > ');
22
- assert.equal(renderShellPrompt('/tmp/demo', env), 'alice /tmp/demo > ');
23
- });
24
-
25
- test('shell startup stays quiet and points to the picker', () => {
26
- const catalog = renderShellCatalog();
27
- for (const command of ['/model', '/usage', '/help', '/exit']) {
28
- assert.match(catalog, new RegExp(command.replace('/', '\\/')));
29
- }
30
- assert.match(catalog, /command picker/);
31
- assert.match(catalog, /Type normally to work with the selected model/);
32
- assert.doesNotMatch(catalog, /Slash commands \(/);
33
- assert.doesNotMatch(catalog, /\/reasoning\s+Set reasoning/);
34
- });
35
-
36
- test('dispatch handles help, menu fallback, pwd, cd, and exit without falling through to host shell', async () => {
37
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-shell-'));
38
- const child = path.join(root, 'child folder');
39
- fs.mkdirSync(child);
40
- let output = '';
41
- const state = { cwd: root, write: (text) => { output += text; }, interactive: false };
42
- let result = await dispatchShellLine('/help', state);
43
- assert.equal(result.handled, true);
44
- assert.match(output, /SAM = Systematic Autonomous Machinery/);
45
- assert.match(output, /agentsam help <topic>/);
46
- output = '';
47
- await dispatchShellLine('/', state);
48
- assert.match(output, /command picker/);
49
- output = '';
50
- await dispatchShellLine('/pwd', state);
51
- assert.equal(output.trim(), root);
52
- output = '';
53
- await dispatchShellLine('/cd "child folder"', state);
54
- assert.equal(state.cwd, child);
55
- assert.equal(output.trim(), child);
56
- result = await dispatchShellLine('/exit', state);
57
- assert.equal(result.exit, true);
58
- });
59
-
60
- const stripAnsi = (text) => String(text || '').replace(/\x1B\[[0-9;]*[a-zA-Z]/g, '');
61
-
62
- test('/usage renders the current session receipt without ending the session', async () => {
63
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-shell-usage-'));
64
- let output = '';
65
- const state = {
66
- cwd: root, interactive: false, write: (text) => { output += text; },
67
- session: {
68
- id: 'asess_00000000-0000-4000-8000-000000000001', title: 'Usage test', model_key: 'openai:gpt-6-astra',
69
- cumulative_usage: { input_tokens: 21_244, cached_input_tokens: 60_544, output_tokens: 219 },
70
- total_cost_usd: 0.42, cost_breakdown_usd: { input: 0.2, cached_input: 0.02, output: 0.2 },
71
- },
72
- };
73
- const result = await dispatchShellLine('/usage', state);
74
- assert.equal(result.exit, false);
75
- const clean = stripAnsi(output);
76
- assert.match(clean, /AgentSam · Usage/);
77
- assert.match(clean, /input\s+21\.2k/);
78
- assert.match(clean, /output\s+219/);
79
- assert.match(clean, /cached\s+60\.5k/);
80
- assert.match(clean, /cost\s+\$0\.420/);
81
- assert.match(clean, /agentsam resume asess_00000000-0000-4000-8000-000000000001/);
82
- });
83
-
84
- test('/logout signs out locally and emits the same resumable usage receipt', async () => {
85
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-shell-logout-'));
86
- const home = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-shell-home-'));
87
- let output = '';
88
- const state = {
89
- cwd: root, home, interactive: false, write: (text) => { output += text; },
90
- session: {
91
- id: 'asess_00000000-0000-4000-8000-000000000002', title: 'Logout test', model_key: 'openai:gpt-6-astra',
92
- cumulative_usage: { input_tokens: 100, cached_input_tokens: 50, output_tokens: 25 },
93
- total_cost_usd: 0.0125, cost_breakdown_usd: { input: 0.005, cached_input: 0.0025, output: 0.005 },
94
- },
95
- };
96
- const result = await dispatchShellLine('/logout', state);
97
- assert.equal(result.exit, false);
98
- assert.match(output, /No local Agent Sam IAM session was stored/);
99
- assert.match(output, /Token usage: total=125 input=100 \(\+ 50 cached\) output=25/);
100
- assert.match(output, /Spent: \$0\.0125/);
101
- assert.match(output, /agentsam resume asess_00000000-0000-4000-8000-000000000002/);
102
- });
103
-
104
- test('reasoning and service-tier commands persist only supported controls for an exact model', async () => {
105
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-shell-model-'));
106
- fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ name: 'model-demo' }));
107
- writeCliPreferences(root, { trustedDirectory: true, modelPreference: 'openai:gpt-6-astra', reasoningEffort: 'low', serviceTier: 'default' });
108
- let output = '';
109
- const state = { cwd: root, write: (text) => { output += text; }, interactive: false };
110
- await dispatchShellLine('/reasoning high', state);
111
- assert.equal(readCliPreferences(root).reasoningEffort, 'high');
112
- await dispatchShellLine('/fast', state);
113
- assert.equal(readCliPreferences(root).serviceTier, 'fast');
114
- await dispatchShellLine('/flex', state);
115
- assert.equal(readCliPreferences(root).serviceTier, 'flex');
116
- await dispatchShellLine('/standard', state);
117
- assert.equal(readCliPreferences(root).serviceTier, 'default');
118
- assert.match(output, /reasoning → high/);
119
- assert.match(output, /Fast is a paid latency choice/);
120
- assert.match(output, /Flex trades latency/);
121
- });
122
-
123
- test('stale provider snapshots hydrate GPT-6 reasoning controls from the current catalog', async () => {
124
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-shell-stale-model-'));
125
- fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ name: 'stale-model-demo' }));
126
- writeCliPreferences(root, {
127
- trustedDirectory: true,
128
- modelPreference: 'openai:gpt-6-luna',
129
- reasoningEffort: 'auto',
130
- serviceTier: 'default',
131
- modelSnapshot: {
132
- model_key: 'openai:gpt-6-luna',
133
- provider: 'openai',
134
- provider_model_id: 'gpt-6-luna',
135
- label: 'gpt-6-luna',
136
- availability: 'available',
137
- availability_source: 'provider_api',
138
- context_window: null,
139
- context_window_source: 'unknown',
140
- max_output_tokens: null,
141
- max_output_tokens_source: 'unknown',
142
- reasoning_efforts: ['auto'],
143
- service_tiers: ['default'],
144
- capabilities: { responses: true },
145
- },
146
- });
147
-
148
- let output = '';
149
- const state = { cwd: root, write: (text) => { output += text; }, interactive: false };
150
- await dispatchShellLine('/reasoning', state);
151
- assert.match(output, /auto \| none \| low \| medium \| high \| xhigh \| max/);
152
- assert.match(output, /provider default: medium/);
153
-
154
- output = '';
155
- await dispatchShellLine('/reasoning high', state);
156
- assert.equal(readCliPreferences(root).reasoningEffort, 'high');
157
- assert.match(output, /reasoning → high/);
158
-
159
- output = '';
160
- await dispatchShellLine('/context', state);
161
- assert.match(output, /1,050,000/);
162
- });
163
-
164
- test('bare /context shows truthful economics without inventing active token usage', async () => {
165
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-shell-context-'));
166
- fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ name: 'context-demo' }));
167
- writeCliPreferences(root, { trustedDirectory: true, modelPreference: 'openai:gpt-6-astra', reasoningEffort: 'medium', serviceTier: 'default' });
168
- let output = '';
169
- await dispatchShellLine('/context', { cwd: root, write: (text) => { output += text; }, interactive: false });
170
- assert.match(output, /1,050,000/);
171
- assert.match(output, /272,000/);
172
- assert.match(output, /180,000/);
173
- assert.match(output, /unavailable · no provider\/local usage snapshot yet/);
174
- assert.match(output, /Batch is a separate asynchronous execution lane/);
175
- });
176
-
177
- test('CLI supports a deterministic one-shot slash command for regression tests', () => {
178
- const result = spawnSync(process.execPath, ['src/cli.js', 'shell', '--command', '/help'], { cwd: repoRoot, encoding: 'utf8' });
179
- assert.equal(result.status, 0, result.stderr);
180
- assert.match(result.stdout, /SAM = Systematic Autonomous Machinery/);
181
- assert.match(result.stdout, /agentsam help <topic>/);
182
- assert.match(result.stdout, /command picker/);
183
- });
184
-
185
- test('large pastes collapse into a single confirmation line', () => {
186
- const pasted = ['one', 'two', 'three', 'four', 'five', 'six'].join('\n');
187
- assert.equal(shouldCollapsePaste('short'), false);
188
- assert.equal(shouldCollapsePaste(pasted), true);
189
- assert.equal(shouldCollapsePaste('x'.repeat(301)), true);
190
- assert.equal(renderCollapsedPaste(pasted), '[Pasted 6 lines — Enter to run, Backspace to clear]');
191
-
192
- const writes = [];
193
- const rl = {
194
- terminal: true,
195
- line: '',
196
- cursor: 0,
197
- _refreshLine() { writes.push(this.line); },
198
- _ttyWrite(s) { this.line += s || ''; this.cursor = this.line.length; },
199
- };
200
- const restore = installPasteCollapse(rl);
201
- rl._ttyWrite(pasted);
202
- assert.equal(rl.line, '[Pasted 6 lines — Enter to run, Backspace to clear]');
203
- rl._ttyWrite('', { name: 'backspace' });
204
- assert.equal(rl.line, '');
205
- restore();
206
- });
207
-
208
- test('dispatchShellLine accepts "agentsam <cmd>" and bare common verbs without slash prefix', async () => {
209
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-shell-verb-'));
210
- let output = '';
211
- const state = { cwd: root, write: (text) => { output += text; }, interactive: false };
212
-
213
- const r1 = await dispatchShellLine('agentsam help', state);
214
- assert.equal(r1.handled, true);
215
- assert.match(output, /SAM = Systematic Autonomous Machinery/);
216
-
217
- output = '';
218
- const r2 = await dispatchShellLine('help', state);
219
- assert.equal(r2.handled, true);
220
- assert.match(output, /SAM = Systematic Autonomous Machinery/);
221
-
222
- const r3 = await dispatchShellLine('exit', state);
223
- assert.equal(r3.exit, true);
224
- });
225
-
226
- test('/compact is discoverable, invokes native compaction, persists exact continuation and usage across resume', async () => {
227
- const { SLASH_COMMANDS } = await import('../src/lib/slash-commands.js');
228
- const { createLocalSession, loadLocalSession, loadSessionContinuation } = await import('../src/lib/local-sessions.js');
229
- const { runResponsesAgent } = await import('../src/agent/responses-runner.js');
230
- const { createOpenAIResponsesAdapter } = await import('../src/providers/openai-responses.js');
231
- assert.ok(SLASH_COMMANDS.some(row => row.cmd === '/compact'));
232
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-compact-'));
233
- fs.writeFileSync(path.join(root, 'package.json'), '{"name":"compact-test"}');
234
- writeCliPreferences(root, { modelPreference: 'openai:gpt-6-astra', reasoningEffort: 'low', serviceTier: 'default' });
235
- const session = createLocalSession({ cwd: root, project_root: root, model_key: 'openai:gpt-6-astra', reasoning_effort: 'low', requested_service_tier: 'default', provider_state: { provider: 'openai', previous_response_id: 'resp_prior' }, cumulative_usage: { input_tokens: 10 } });
236
- const output = [{ type: 'message', role: 'user', content: [{ type: 'input_text', text: 'Keep the selected architecture' }] }, { type: 'compaction', id: 'cmp_item', encrypted_content: 'opaque+/==exact' }];
237
- const oldKey = process.env.OPENAI_API_KEY;
238
- process.env.OPENAI_API_KEY = 'fixture-key';
239
- let rendered = '', calls = 0;
240
- const state = { cwd: root, projectRoot: root, interactive: false, session, write: text => { rendered += text; }, providerFetchImpl: async (url, init) => {
241
- calls++;
242
- assert.match(url, /responses\/compact$/);
243
- assert.equal(JSON.parse(init.body).previous_response_id, 'resp_prior');
244
- return { ok: true, status: 200, json: async () => ({ id: 'cmp_test', output, usage: { input_tokens: 1000, output_tokens: 100, input_tokens_details: { cached_tokens: 100 } } }) };
245
- } };
246
- try { await dispatchShellLine('/compact', state); }
247
- finally { if (oldKey === undefined) delete process.env.OPENAI_API_KEY; else process.env.OPENAI_API_KEY = oldKey; }
248
- assert.equal(calls, 1);
249
- assert.match(rendered, /continuation saved/);
250
- const resumed = loadLocalSession(session.id, { projectRoot: root });
251
- assert.equal(resumed.cumulative_usage.input_tokens, 1010);
252
- assert.equal(resumed.cumulative_usage.cached_input_tokens, 100);
253
- assert.ok(resumed.total_cost_usd > 0);
254
- assert.equal(resumed.latest_compaction.compaction_id, 'cmp_test');
255
- const continuation = loadSessionContinuation(resumed);
256
- assert.deepEqual(continuation.compacted_input, output);
257
- assert.equal(resumed.provider_state.previous_response_id, undefined);
258
- const adapter = createOpenAIResponsesAdapter({ apiKey: 'test', fetchImpl: async (_, init) => {
259
- const body = JSON.parse(init.body);
260
- assert.deepEqual(body.input.slice(0, output.length), output);
261
- assert.equal(body.previous_response_id, undefined);
262
- return { ok: true, status: 200, json: async () => ({ id: 'resp_next', output_text: 'done', output: [], usage: { input_tokens: 120, output_tokens: 10 } }) };
263
- } });
264
- await runResponsesAgent({ provider: adapter, capabilityAdapter: { toolDescriptors: () => [] }, model: 'gpt-6-astra', prompt: 'continue', cwd: root, instructions: '', previousProviderState: continuation, previousUsageSnapshot: resumed.usage_snapshot });
265
- rendered = '';
266
- await dispatchShellLine('/compact status', state);
267
- assert.match(rendered, /180000/);
268
- assert.match(rendered, /cmp_test/);
269
- await dispatchShellLine('/session', state);
270
- assert.match(rendered, /Latest compaction: cmp_test/);
271
- });
272
-
273
- test('/compact fails closed for unsupported provider without an HTTP request', async () => {
274
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-compact-unsupported-'));
275
- fs.writeFileSync(path.join(root, 'package.json'), '{"name":"unsupported"}');
276
- writeCliPreferences(root, { modelPreference: 'gemini:test', modelSnapshot: { provider: 'gemini', model_key: 'gemini:test', provider_model_id: 'test', context_window: 128000, capabilities: {} } });
277
- let rendered = '', calls = 0;
278
- await dispatchShellLine('/compact', { cwd: root, interactive: false, write: text => { rendered += text; }, providerFetchImpl: async () => { calls++; } });
279
- assert.equal(calls, 0);
280
- assert.match(rendered, /native_compaction_unavailable:gemini/);
281
- });
@@ -1,22 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import test from 'node:test';
3
- import { getSkill, listSkills, loadSkill } from '../src/skills/index.js';
4
-
5
- test('portable skill registry exposes AgentSam Jr Dev by id and alias', () => {
6
- const listed = listSkills();
7
- assert.ok(listed.some((skill) => skill.id === 'agentsam-jr-dev'));
8
-
9
- assert.equal(getSkill('agentsam_jr_dev')?.id, 'agentsam-jr-dev');
10
- assert.equal(getSkill('jr-dev')?.id, 'agentsam-jr-dev');
11
- });
12
-
13
- test('AgentSam Jr Dev loads compact instructions and references on demand', () => {
14
- const compact = loadSkill('agentsam-jr-dev');
15
- assert.match(compact.instructions, /# AgentSam Jr Dev/);
16
- assert.equal('references' in compact, false);
17
-
18
- const full = loadSkill('agentsam_jr_dev', { references: true });
19
- assert.equal(full.references.length, 2);
20
- assert.match(full.references[0].content, /## HTTP/);
21
- assert.match(full.references[1].content, /# Real Application Logic/);
22
- });
package/test/smoke.mjs DELETED
@@ -1,122 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import fs from 'node:fs';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import { fileURLToPath } from 'node:url';
6
- import { AgentSam, routeIntent, getToolCatalog } from '../src/index.js';
7
- import { buildLocalScaffoldMeta, sdkDependencySpec } from '../src/lib/local-scaffold.js';
8
- import { writeScaffoldFiles } from '../src/lib/write-files.js';
9
- import { initializeLocalSqlite, createLocalSqliteDatabase } from '../src/local/sqlite.js';
10
- import { printContextSummary, missingForInit } from '../src/lib/detect-context.js';
11
-
12
- const app = new AgentSam({ project: 'smoke', lane: 'cms', agent: 'cms' });
13
- let res = await app.handle(new Request('https://example.com/api/health'));
14
- assert.equal(res.status, 200);
15
- assert.equal((await res.json()).ok, true);
16
-
17
- res = await app.handle(new Request('https://example.com/api/agentsam/info'));
18
- const info = await res.json();
19
- assert.equal(info.agent, 'cms');
20
- assert.ok(info.capabilities.includes('page'));
21
-
22
- res = await app.handle(new Request('https://example.com/api/agentsam/message', {
23
- method: 'POST',
24
- body: JSON.stringify({ message: 'create an analytics page in the cms' }),
25
- }));
26
- const message = await res.json();
27
- assert.equal(message.agent, 'cms');
28
- assert.equal(message.intent, 'cms_build');
29
-
30
- assert.equal(routeIntent({ message: 'drop table users' }).requires_approval, true);
31
- assert.ok(getToolCatalog('Data Solutions').some((tool) => tool.name === 'query'));
32
-
33
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-sdk-test-'));
34
- const dir = writeScaffoldFiles(path.join(tmp, 'demo-project'), [
35
- { path: 'src/agent.js', content: 'export function createAgent() {}\n' },
36
- { path: 'db/schema.sql', content: 'CREATE TABLE cms_pages (id TEXT PRIMARY KEY);\n' },
37
- { path: '.env.example', content: 'AGENTSAM_DB=.agentsam/data/agentsam.sqlite\n' },
38
- ]);
39
- assert.ok(fs.existsSync(path.join(dir, 'src/agent.js')));
40
- assert.ok(fs.readFileSync(path.join(dir, 'db/schema.sql'), 'utf8').includes('cms_pages'));
41
- assert.ok(fs.readFileSync(path.join(dir, '.env.example'), 'utf8').includes('AGENTSAM_DB'));
42
-
43
- import { SLASH_COMMANDS, listSlashCommands } from '../src/lib/slash-commands.js';
44
- import { createIdentityClient, AUTH_COOKIE_NAME } from '../src/index.js';
45
- import { finalizeInboundOAuth } from '../packages/identity/src/oauth/callback.js';
46
- assert.equal(AUTH_COOKIE_NAME, 'session');
47
- assert.equal(createIdentityClient().providers.google()?.id, 'google');
48
- const { GoogleProvider } = await import('@inneranimalmedia/agentsam-sdk/identity/providers/google');
49
- assert.equal(GoogleProvider.id, 'google');
50
- const { handleIdentityWorkerRequest } = await import('@inneranimalmedia/agentsam-sdk/identity/server/worker-router');
51
- assert.equal(typeof handleIdentityWorkerRequest, 'function');
52
- const { buildIdentityAppScaffold } = await import('../src/lib/identity-scaffold.js');
53
- assert.ok(buildIdentityAppScaffold({ projectName: 'x' })['backend/src/index.js']);
54
- await assert.rejects(() => finalizeInboundOAuth({}, new Request('https://x'), {}), /adapter/);
55
- assert.ok(SLASH_COMMANDS.some((c) => c.cmd === '/deploy'));
56
- assert.ok(SLASH_COMMANDS.some((c) => c.cmd === '/db'));
57
- assert.ok(SLASH_COMMANDS.some((c) => c.cmd === '/agent'));
58
- assert.ok(SLASH_COMMANDS.some((c) => c.cmd === '/model'));
59
- assert.ok(SLASH_COMMANDS.some((c) => c.cmd === '/providers'));
60
- assert.ok(SLASH_COMMANDS.some((c) => c.cmd === '/reasoning'));
61
- assert.ok(SLASH_COMMANDS.some((c) => c.cmd === '/fast'));
62
- assert.deepEqual(
63
- listSlashCommands({ lane: 'deploy' }).map(({ cmd }) => cmd),
64
- ['/settings', '/deploy', '/help', '/exit'],
65
- 'deploy lane keeps global shell controls and excludes commands from other lanes',
66
- );
67
-
68
- printContextSummary({
69
- iam: { ready: true, source: 'api_key', detail: 'AGENTSAM_API_KEY' },
70
- gcp: { source: 'vm-metadata', email: 'execos@project.iam.gserviceaccount.com' },
71
- gcp_vm: true,
72
- github: { source: 'gh-cli', account: 'user@example.com' },
73
- cloudflare: { source: 'wrangler', account: 'user@cloudflare.test' },
74
- });
75
- assert.deepEqual(missingForInit({ iam: { ready: false } }, '', { runTarget: 'local' }), []);
76
- assert.deepEqual(missingForInit({ iam: { ready: false } }, '', { runTarget: 'cloudflare' }), ['iam']);
77
-
78
- assert.equal(sdkDependencySpec('2.0.0-alpha.identity.12'), '2.0.0-alpha.identity.12');
79
- assert.equal(sdkDependencySpec('2.1.3'), '^2.1.3');
80
- const prereleaseMeta = buildLocalScaffoldMeta(
81
- { projectName: 'alpha-demo', lane: 'fullstack', runTarget: 'local' },
82
- '2.0.0-alpha.identity.12',
83
- );
84
- const prereleasePackage = JSON.parse(prereleaseMeta.files.find((f) => f.path === 'package.json').content);
85
- assert.equal(
86
- prereleasePackage.dependencies['@inneranimalmedia/agentsam-sdk'],
87
- '2.0.0-alpha.identity.12',
88
- );
89
-
90
- const localMeta = buildLocalScaffoldMeta({ projectName: 'demo', lane: 'cms', runTarget: 'local' });
91
- assert.equal(localMeta.laneKey, 'cms');
92
- assert.ok(localMeta.files.some((f) => f.path === '.agentsam/start-local.md'));
93
- assert.ok(localMeta.files.some((f) => f.path === 'db/schema.sql'));
94
- assert.ok(localMeta.files.some((f) => f.path === '.env'));
95
- assert.ok(localMeta.files.some((f) => f.path === '.env.example'));
96
- assert.ok(localMeta.files.some((f) => f.path === 'src/agent.js'));
97
- assert.ok(!localMeta.files.some((f) => f.path === 'wrangler.toml'));
98
- assert.ok(!localMeta.files.some((f) => f.path.startsWith('gorilla/')));
99
- assert.ok(!localMeta.files.some((f) => f.path.includes('execos')));
100
-
101
- const localDir = path.join(tmp, 'local-project');
102
- writeScaffoldFiles(localDir, localMeta.files);
103
- const localDb = await initializeLocalSqlite({
104
- dbPath: path.join(localDir, '.agentsam', 'data', 'agentsam.sqlite'),
105
- schemaPath: path.join(localDir, 'db', 'schema.sql'),
106
- });
107
- assert.ok(localDb.tables.includes('agent_sessions'));
108
- const d1Like = await createLocalSqliteDatabase(localDb.dbPath);
109
- await d1Like.prepare('INSERT INTO agent_sessions (id, agent, lane, status) VALUES (?, ?, ?, ?)').bind(
110
- 'sess_test', 'cms', 'cms', 'created',
111
- ).run();
112
- const persisted = await d1Like.prepare('SELECT id FROM agent_sessions WHERE id = ?').bind('sess_test').first();
113
- assert.equal(persisted.id, 'sess_test');
114
- d1Like.close();
115
-
116
- const tunnelPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'src', 'commands', 'tunnel.js');
117
- const tunnelSrc = fs.readFileSync(tunnelPath, 'utf8');
118
- assert.ok(tunnelSrc.includes('parseWranglerTunnelList'));
119
- assert.ok(tunnelSrc.includes('wrangler'));
120
- assert.ok(fs.existsSync(tunnelPath));
121
-
122
- console.log('SDK smoke tests passed');
@@ -1,79 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import test from 'node:test';
3
- import { createAgentEvent, createUsageSnapshot } from '../src/telemetry/index.js';
4
-
5
- test('AgentEvent is compact serializable provider-neutral telemetry', () => {
6
- const event = createAgentEvent('context.compaction.completed', { before: 181_000, after: 72_000 }, {
7
- runId: 'run_test', sequence: 4, timestamp: '2026-09-12T00:00:00.000Z',
8
- });
9
- assert.equal(event.type, 'context.compaction.completed');
10
- assert.equal(event.run_id, 'run_test');
11
- assert.doesNotThrow(() => JSON.stringify(event));
12
- });
13
-
14
- test('current active context and cumulative run usage are different metrics', () => {
15
- const usage = createUsageSnapshot({
16
- current_context: { input_tokens: 48_000, window_tokens: 1_050_000 },
17
- cumulative: { input_tokens: 310_000, output_tokens: 22_000, cached_input_tokens: 120_000, cache_write_tokens: 12_000, reasoning_tokens: 8_000 },
18
- estimate_kind: 'provider',
19
- });
20
- assert.equal(usage.current_context.input_tokens, 48_000);
21
- assert.equal(usage.cumulative.input_tokens, 310_000);
22
- assert.equal(usage.provider_authoritative, true);
23
- });
24
-
25
- import {
26
- createRunReceipt,
27
- createUsageReceipt,
28
- createApprovalReceipt,
29
- createTerminalJobReceipt,
30
- } from '../src/telemetry/index.js';
31
-
32
- test('runtime receipts are account-owned and emit no tenant/workspace/user ownership aliases', () => {
33
- const run = createRunReceipt({
34
- id: 'arun_1', account_id: 'au_1', mode: 'agent', status: 'running',
35
- source_client: 'cli', surface: 'cli', reasoning_effort: 'high', requested_service_tier: 'fast',
36
- });
37
- assert.equal(run.account_id, 'au_1');
38
- assert.equal(run.source_client, 'cli');
39
- assert.equal(run.requested_service_tier, 'fast');
40
- assert.equal('user_id' in run, false);
41
- assert.equal('tenant_id' in run, false);
42
- assert.equal('workspace_id' in run, false);
43
- });
44
-
45
- test('usage receipt models exactly one provider call and keeps cache/reasoning economics', () => {
46
- const usage = createUsageReceipt({
47
- id: 'ue_1', account_id: 'au_1', agent_run_id: 'arun_1', provider: 'openai', model_key: 'gpt-6-astra',
48
- model_call_index: 2, provider_request_id: 'resp_1', input_tokens: 1000, cached_input_tokens: 600,
49
- cache_write_tokens: 20, output_tokens: 100, reasoning_tokens: 40, cost_usd: 0.12, cost_basis: 'provider',
50
- });
51
- assert.equal(usage.total_tokens, 1100);
52
- assert.equal(usage.cached_input_tokens, 600);
53
- assert.equal(usage.reasoning_tokens, 40);
54
- assert.equal(usage.model_call_index, 2);
55
- });
56
-
57
- test('approval and terminal receipts preserve lineage without turning D1 into transcript storage', () => {
58
- const approval = createApprovalReceipt({
59
- id: 'appr_1', account_id: 'au_1', agent_run_id: 'arun_1', tool_call_id: 'call_1', terminal_job_id: 'tjob_1',
60
- action_summary: 'Deploy worker', sanitizedInput: { worker: 'api' }, risk_level: 'high',
61
- });
62
- assert.equal(approval.terminal_job_id, 'tjob_1');
63
- assert.match(approval.sanitized_input_json, /worker/);
64
-
65
- const job = createTerminalJobReceipt({
66
- id: 'tjob_1', account_id: 'au_1', instance_id: 'tinst_1', connection_id: 'conn_1',
67
- execos_run_id: 'xrun_1', status: 'running', idempotency_key: 'idem_1', max_attempts: 1,
68
- });
69
- assert.equal(job.execos_run_id, 'xrun_1');
70
- assert.equal(job.max_attempts, 1);
71
- assert.equal('stdout' in job, false);
72
- assert.equal('stderr' in job, false);
73
- assert.equal('command' in job, false);
74
- });
75
-
76
- test('runtime receipts refuse model-invented account identity', () => {
77
- assert.throws(() => createRunReceipt({ id: 'arun_1' }), /account_id is required/);
78
- assert.throws(() => createUsageReceipt({ id: 'ue_1', provider: 'openai', model_key: 'gpt-6-astra' }), /account_id is required/);
79
- });
@@ -1,153 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { EventEmitter } from 'node:events';
3
- import fs from 'node:fs';
4
- import os from 'node:os';
5
- import path from 'node:path';
6
- import test from 'node:test';
7
- import { pathToFileURL } from 'node:url';
8
- import {
9
- attachLocalPtySession,
10
- ensureNodePtySpawnHelperExecutable,
11
- startLocalPtyServer,
12
- } from '../../src/local-pty/server.js';
13
-
14
- function fakeTransports() {
15
- const writes = [];
16
- const resizes = [];
17
- let killed = 0;
18
- let dataHandler = null;
19
- let exitHandler = null;
20
-
21
- const pty = {
22
- spawn(shell, args, options) {
23
- assert.equal(Array.isArray(args), true);
24
- assert.equal(options.env.AGENTSAM_LOCAL_PTY, '1');
25
- return {
26
- write(value) { writes.push(value); },
27
- resize(cols, rows) { resizes.push([cols, rows]); },
28
- kill() { killed += 1; },
29
- onData(fn) { dataHandler = fn; },
30
- onExit(fn) { exitHandler = fn; },
31
- };
32
- },
33
- };
34
-
35
- class FakeWs extends EventEmitter {
36
- OPEN = 1;
37
- readyState = 1;
38
- sent = [];
39
- send(value) { this.sent.push(String(value)); }
40
- close() {
41
- if (this.readyState !== this.OPEN) return;
42
- this.readyState = 3;
43
- this.emit('close');
44
- }
45
- }
46
-
47
- const ws = new FakeWs();
48
- return {
49
- pty,
50
- ws,
51
- writes,
52
- resizes,
53
- killed: () => killed,
54
- emitData(value) { dataHandler?.(value); },
55
- emitExit() { exitHandler?.(); },
56
- };
57
- }
58
-
59
- test('macOS node-pty helper is made executable before runtime import', (t) => {
60
- const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsam-node-pty-helper-'));
61
- t.after(() => fs.rmSync(root, { recursive: true, force: true }));
62
- const libDir = path.join(root, 'lib');
63
- const helperDir = path.join(root, 'prebuilds', 'darwin-arm64');
64
- fs.mkdirSync(libDir, { recursive: true });
65
- fs.mkdirSync(helperDir, { recursive: true });
66
- fs.writeFileSync(path.join(libDir, 'index.js'), '');
67
- const helper = path.join(helperDir, 'spawn-helper');
68
- fs.writeFileSync(helper, 'fake');
69
- fs.chmodSync(helper, 0o644);
70
-
71
- const result = ensureNodePtySpawnHelperExecutable({
72
- platform: 'darwin',
73
- arch: 'arm64',
74
- resolveModule: () => pathToFileURL(path.join(libDir, 'index.js')).href,
75
- });
76
-
77
- assert.equal(result.checked, true);
78
- assert.equal(result.changed, true);
79
- assert.equal(result.path, helper);
80
- assert.notEqual(fs.statSync(helper).mode & 0o111, 0);
81
-
82
- const second = ensureNodePtySpawnHelperExecutable({
83
- platform: 'darwin',
84
- arch: 'arm64',
85
- resolveModule: () => pathToFileURL(path.join(libDir, 'index.js')).href,
86
- });
87
- assert.equal(second.changed, false);
88
- });
89
-
90
- test('local PTY wire protocol is release-testable entirely in memory', () => {
91
- const transport = fakeTransports();
92
- const session = attachLocalPtySession({
93
- ws: transport.ws,
94
- pty: transport.pty,
95
- shell: '/bin/test-shell',
96
- cwd: '/tmp/test-project',
97
- cols: 80,
98
- rows: 24,
99
- env: {},
100
- sessionId: 'local_test',
101
- });
102
-
103
- assert.equal(session.session_id, 'local_test');
104
- assert.deepEqual(JSON.parse(transport.ws.sent[0]), {
105
- type: 'session_id',
106
- session_id: 'local_test',
107
- });
108
-
109
- transport.ws.emit('message', Buffer.from(JSON.stringify({ type: 'resize', cols: 120, rows: 40 })));
110
- transport.ws.emit('message', Buffer.from(JSON.stringify({ type: 'slash', line: '/pwd' })));
111
- transport.ws.emit('message', Buffer.from('raw input'));
112
-
113
- assert.deepEqual(transport.resizes, [[120, 40]]);
114
- assert.deepEqual(transport.writes, ['/pwd\r', 'raw input']);
115
-
116
- transport.emitData('terminal output');
117
- assert.equal(transport.ws.sent.at(-1), 'terminal output');
118
-
119
- transport.ws.close();
120
- assert.equal(transport.killed(), 1);
121
-
122
- // Cleanup is idempotent even when transport error/close paths race.
123
- transport.ws.emit('error', new Error('synthetic transport close'));
124
- session.cleanup();
125
- assert.equal(transport.killed(), 1);
126
- });
127
-
128
- test('local PTY server health check uses an ephemeral local port and no ExecOS tunnel', async () => {
129
- const transport = fakeTransports();
130
- const server = await startLocalPtyServer({
131
- cwd: process.cwd(),
132
- host: '127.0.0.1',
133
- port: 0,
134
- pty: transport.pty,
135
- });
136
-
137
- try {
138
- const health = await fetch(server.healthUrl);
139
- assert.equal(health.status, 200);
140
- const body = await health.json();
141
- assert.equal(body.ok, true);
142
- assert.equal(body.service, 'agentsam.local.runtime');
143
- assert.equal(body.plane, 'local');
144
- assert.equal(body.service_legacy, 'agentsam-local-pty');
145
- assert.equal(body.port, server.port);
146
- assert.equal(server.port > 0, true);
147
- } finally {
148
- await server.close();
149
- }
150
-
151
- // No WebSocket session was opened, so the PTY process was never spawned.
152
- assert.equal(transport.killed(), 0);
153
- });