@inneranimalmedia/agentsam-sdk 2.4.1 → 2.6.0

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 (233) hide show
  1. package/AGENTSAM.md +55 -0
  2. package/README.md +17 -12
  3. package/bin/agentsam +2 -0
  4. package/docs/AGENTSAM_ASTRA_OPENAI_INTEGRATION.md +1363 -0
  5. package/docs/AGENTSAM_WORKBENCH.md +30 -0
  6. package/docs/AUTH_IDENTITY_CONTRACT.md +52 -0
  7. package/docs/CAPABILITIES.md +5 -3
  8. package/docs/CLI_SHELL.md +167 -80
  9. package/docs/CMS_STUDIO.md +101 -0
  10. package/docs/CONTEXT.md +170 -0
  11. package/docs/LOCAL_OLLAMA.md +58 -0
  12. package/docs/MERKLE.md +19 -19
  13. package/docs/PORTABLE_CONTEXT.md +4 -3
  14. package/docs/PROJECT_CONFIG.md +72 -0
  15. package/docs/RELEASES.md +35 -2
  16. package/docs/REPOSITORY_INTELLIGENCE.md +1 -1
  17. package/docs/REPOSITORY_KNOWLEDGE.md +114 -0
  18. package/docs/SDK_WORKER.md +86 -0
  19. package/docs/SECURITY.md +59 -22
  20. package/docs/client-cms-editor.md +15 -0
  21. package/docs/local-studio/WORKMODE_DONOR_NOTES.md +485 -0
  22. package/package.json +35 -10
  23. package/packages/connectors/cloudflare/package.json +10 -0
  24. package/packages/connectors/cloudflare/src/index.js +127 -0
  25. package/packages/connectors/cloudflare/src/owner.js +76 -0
  26. package/packages/connectors/cloudflare/src/routes.js +223 -0
  27. package/packages/connectors/cloudflare/src/vault.js +80 -0
  28. package/packages/connectors/cloudflare/tests/connector.test.mjs +44 -0
  29. package/packages/identity/package.json +10 -1
  30. package/packages/identity/src/contracts/auth-config.js +109 -0
  31. package/packages/identity/src/index.js +1 -0
  32. package/packages/identity/src/oauth/README.md +2 -2
  33. package/packages/identity/src/oauth/credentials.js +11 -4
  34. package/packages/identity/src/oauth/iam-platform.js +3 -3
  35. package/packages/identity/src/providers/iam/index.js +7 -7
  36. package/packages/identity/src/providers/iam/oauth.js +6 -4
  37. package/packages/identity/src/providers/iam/profile.js +5 -5
  38. package/packages/identity/tests/auth-config.test.mjs +61 -0
  39. package/packages/identity/tests/oauth-credentials.test.mjs +13 -2
  40. package/protocol/FILEMETA_V1.md +95 -0
  41. package/protocol/INSPECT_VIEWS_V1.md +40 -0
  42. package/protocol/MERKLE_PERSISTENCE_V1.md +50 -0
  43. package/protocol/MERKLE_V1.md +3 -1
  44. package/protocol/README.md +1 -0
  45. package/protocol/capabilities/cloudflare-cpu-audit-input.schema.json +19 -0
  46. package/protocol/capabilities/cloudflare-cpu-profile-input.schema.json +13 -0
  47. package/protocol/capabilities/cloudflare-wrangler-native-input.schema.json +19 -0
  48. package/protocol/capabilities/manifest.json +79 -3
  49. package/protocol/capabilities/repository-snapshot.schema.json +1 -0
  50. package/protocol/context/context-budget.schema.json +36 -0
  51. package/protocol/context/context-item.schema.json +19 -0
  52. package/protocol/context/resolved-context-pack.schema.json +47 -0
  53. package/protocol/context/result-policy.schema.json +17 -0
  54. package/protocol/knowledge/context-pack.schema.json +33 -0
  55. package/protocol/knowledge/retrieval-query.schema.json +68 -13
  56. package/protocol/models/README.md +373 -0
  57. package/protocol/models/model-inventory-v2.schema.json +212 -0
  58. package/python/README.md +15 -7
  59. package/python/agentsam_sdk/cli.py +0 -21
  60. package/python/agentsam_sdk/tui/README.md +17 -12
  61. package/python/agentsam_sdk/tui/bootstrap.py +2 -2
  62. package/python/agentsam_sdk/tui/demo.py +25 -10
  63. package/python/agentsam_sdk/tui/onboarding.py +208 -0
  64. package/python/tests/test_tui_cli.py +7 -6
  65. package/skills/README.md +21 -0
  66. package/skills/agentsam-app-fundamentals/SKILL.md +165 -0
  67. package/skills/agentsam-app-fundamentals/references/graphs-contracts-ast-merkle.md +89 -0
  68. package/skills/agentsam-app-fundamentals/references/trust-credentials-and-destinations.md +99 -0
  69. package/skills/agentsam-cloudflare-workers/SKILL.md +53 -0
  70. package/skills/agentsam-cloudflare-workers/references/cpu-profiling.md +16 -0
  71. package/skills/agentsam-cloudflare-workers/references/errors-and-observability.md +29 -0
  72. package/skills/agentsam-cloudflare-workers/references/wrangler-native-map.md +28 -0
  73. package/skills/agentsam-jr-dev/SKILL.md +232 -0
  74. package/skills/agentsam-jr-dev/references/real-application-logic.md +156 -0
  75. package/skills/agentsam-jr-dev/references/web-application-fundamentals.md +240 -0
  76. package/skills/agentsam-progression-guard/SKILL.md +197 -0
  77. package/skills/agentsam-progression-guard/references/checkpoint-chain.md +111 -0
  78. package/skills/agentsam-progression-guard/references/hooks-operational-io.md +96 -0
  79. package/skills/catalog.json +71 -0
  80. package/src/agent/capability-adapter.js +25 -13
  81. package/src/agent/index.js +1 -0
  82. package/src/agent/responses-runner.js +325 -0
  83. package/src/capabilities/index.js +7 -0
  84. package/src/capabilities/repository-snapshot-view.js +238 -0
  85. package/src/capabilities/repository-snapshot.js +28 -14
  86. package/src/cli.js +198 -76
  87. package/src/cloudflare/cpu-profile.js +115 -0
  88. package/src/cloudflare/index.js +14 -0
  89. package/src/cloudflare/wrangler.js +132 -0
  90. package/src/commands/account-auth.js +47 -0
  91. package/src/commands/cloudflare.js +58 -0
  92. package/src/commands/connections.js +93 -0
  93. package/src/commands/context-economics.js +114 -0
  94. package/src/commands/context.js +14 -2
  95. package/src/commands/db.js +4 -7
  96. package/src/commands/deploy.js +54 -32
  97. package/src/commands/eval.js +63 -0
  98. package/src/commands/interactive.js +18 -0
  99. package/src/commands/knowledge.js +27 -4
  100. package/src/commands/merkle-persist.js +118 -0
  101. package/src/commands/merkle.js +32 -17
  102. package/src/commands/models.js +152 -0
  103. package/src/commands/ollama.js +259 -0
  104. package/src/commands/preferences.js +144 -0
  105. package/src/commands/product.js +86 -16
  106. package/src/commands/resume.js +67 -0
  107. package/src/commands/security.js +8 -6
  108. package/src/commands/shell.js +405 -100
  109. package/src/commands/skills.js +66 -0
  110. package/src/commands/start-local.js +1 -1
  111. package/src/commands/tunnel.js +5 -4
  112. package/src/commands/whoami.js +86 -0
  113. package/src/context/budget.js +120 -0
  114. package/src/context/compact.js +28 -0
  115. package/src/context/index.js +7 -0
  116. package/src/context/rehydrate.js +35 -0
  117. package/src/context/resolve.js +116 -0
  118. package/src/context/result-policy.js +66 -0
  119. package/src/errors/diagnostic.js +160 -0
  120. package/src/errors/index.js +9 -0
  121. package/src/eval/context.js +191 -0
  122. package/src/eval/index.js +1 -0
  123. package/src/index.js +70 -0
  124. package/src/indexing/execution-boundary.js +144 -0
  125. package/src/indexing/index.js +8 -0
  126. package/src/indexing/provider.js +41 -0
  127. package/src/knowledge/config.js +2 -2
  128. package/src/knowledge/context-pack.js +12 -1
  129. package/src/knowledge/contracts.js +9 -4
  130. package/src/knowledge/engine.js +7 -3
  131. package/src/knowledge/service/server.js +1 -1
  132. package/src/lib/account-session.js +98 -0
  133. package/src/lib/agent-instructions.js +73 -0
  134. package/src/lib/auth.js +4 -0
  135. package/src/lib/bridge-client.js +7 -5
  136. package/src/lib/cli-preferences.js +78 -0
  137. package/src/lib/core-client.js +8 -8
  138. package/src/lib/deploy/git-guard.js +69 -0
  139. package/src/lib/deploy/health.js +57 -0
  140. package/src/lib/deploy/local-studio.js +283 -0
  141. package/src/lib/deploy/secret-scan.js +65 -0
  142. package/src/lib/deploy-receipt/index.js +5 -2
  143. package/src/lib/detect-context.js +6 -5
  144. package/src/lib/execution-approvals.js +59 -0
  145. package/src/lib/identity-scaffold.js +1 -1
  146. package/src/lib/local-scaffold.js +35 -33
  147. package/src/lib/local-sessions.js +127 -0
  148. package/src/lib/local-status.js +9 -17
  149. package/src/lib/merkle/cloudflare-persistence.js +321 -0
  150. package/src/lib/merkle/filemeta.js +43 -0
  151. package/src/lib/merkle/git-ignore.js +24 -0
  152. package/src/lib/merkle/hash.js +1 -0
  153. package/src/lib/merkle/index.js +22 -0
  154. package/src/lib/merkle/persistence.js +72 -0
  155. package/src/lib/merkle/semantic.js +359 -0
  156. package/src/lib/merkle/snapshot.js +9 -3
  157. package/src/lib/merkle/tree.js +11 -6
  158. package/src/lib/project-config.js +227 -0
  159. package/src/lib/project-rules.js +68 -0
  160. package/src/lib/provider-credentials.js +83 -0
  161. package/src/lib/save-sdk-token.js +1 -1
  162. package/src/lib/scaffold/templates/worker-api/index.js +101 -20
  163. package/src/lib/scaffold/wizards/worker-api.js +27 -11
  164. package/src/lib/slash-commands.js +22 -15
  165. package/src/lib/tools.js +11 -5
  166. package/src/models/catalog.js +135 -0
  167. package/src/models/index.js +7 -0
  168. package/src/providers/index.js +5 -0
  169. package/src/providers/openai-responses.js +275 -0
  170. package/src/security/index.js +1 -0
  171. package/src/security/inventory.js +4 -1
  172. package/src/security/process.js +35 -9
  173. package/src/security/render.js +27 -5
  174. package/src/security/scan.js +24 -9
  175. package/src/security/trust-boundary.js +24 -0
  176. package/src/skills/index.js +64 -0
  177. package/src/telemetry/contracts.js +203 -0
  178. package/src/telemetry/events.js +48 -0
  179. package/src/telemetry/index.js +8 -0
  180. package/src/tools/hydrate.js +35 -0
  181. package/src/tools/index.js +2 -0
  182. package/src/tools/search.js +70 -0
  183. package/src/ui/ansi.js +1 -1
  184. package/src/ui/boot.js +54 -0
  185. package/src/ui/merkle/render.js +1 -0
  186. package/src/ui/runtime-activity.js +192 -0
  187. package/src/ui/theme.js +19 -18
  188. package/test/account-session.test.mjs +36 -0
  189. package/test/app-building-skills.test.mjs +61 -0
  190. package/test/apps-scaffold-contract.test.mjs +56 -0
  191. package/test/capabilities.test.mjs +53 -4
  192. package/test/cli-preferences.test.mjs +46 -0
  193. package/test/cloudflare-connector.test.mjs +96 -0
  194. package/test/cloudflare-runtime.test.mjs +75 -0
  195. package/test/context.test.mjs +144 -0
  196. package/test/deploy-health-scan.test.mjs +67 -0
  197. package/test/error-diagnostics.test.mjs +59 -0
  198. package/test/eval-context.test.mjs +37 -0
  199. package/test/execution-approvals.test.mjs +27 -0
  200. package/test/indexing-provider.test.mjs +29 -0
  201. package/test/jr-dev-skill.test.mjs +26 -0
  202. package/test/knowledge-context-pack.test.mjs +19 -0
  203. package/test/knowledge.test.mjs +1 -1
  204. package/test/local-sessions.test.mjs +42 -0
  205. package/test/local-studio-deploy.test.mjs +83 -0
  206. package/test/merkle-persistence.test.mjs +91 -0
  207. package/test/merkle.test.mjs +77 -3
  208. package/test/model-catalog.test.mjs +43 -0
  209. package/test/models.test.mjs +51 -0
  210. package/test/npm10-lock.test.mjs +29 -0
  211. package/test/ollama.test.mjs +94 -0
  212. package/test/openai-responses.test.mjs +95 -0
  213. package/test/project-config.test.mjs +81 -0
  214. package/test/project-rules.test.mjs +44 -0
  215. package/test/provider-credentials.test.mjs +52 -0
  216. package/test/rehydrate.test.mjs +25 -0
  217. package/test/release-hygiene.test.mjs +34 -0
  218. package/test/repository-snapshot-view.test.mjs +112 -0
  219. package/test/responses-runner.test.mjs +148 -0
  220. package/test/runtime-activity.test.mjs +98 -0
  221. package/test/sdk-worker-contract.test.mjs +68 -0
  222. package/test/security.test.mjs +46 -0
  223. package/test/shell.test.mjs +55 -21
  224. package/test/skills.test.mjs +22 -0
  225. package/test/smoke.mjs +5 -2
  226. package/test/telemetry.test.mjs +79 -0
  227. package/test/theme-portability.test.mjs +14 -0
  228. package/test/tools-search.test.mjs +40 -0
  229. package/test/whoami-resume.test.mjs +56 -0
  230. package/examples/agentsam-tui-ansi.mjs +0 -149
  231. package/src/commands/tui.js +0 -120
  232. package/src/ui/splash-xterm.js +0 -290
  233. package/src/ui/splash.js +0 -426
@@ -0,0 +1,30 @@
1
+ # AgentSam shared workbench boundary
2
+
3
+ The SDK has one shared AgentSam interaction layer for product applications:
4
+
5
+ ```text
6
+ packages/agentsam-contracts pure TypeScript, no React
7
+ ↑
8
+ packages/agentsam-workbench reusable React/browser workbench
9
+ ↑
10
+ ┌───────┼────────┐
11
+ │ │ │
12
+ Local CAD CMS
13
+ Studio Studio Studio
14
+ ```
15
+
16
+ `apps/*` are development products and remain independent workspace roots. They may consume the shared packages, but shared packages must never import an app.
17
+
18
+ ## Contracts
19
+
20
+ `@inneranimalmedia/agentsam-contracts` owns messages, runs, events, tools/capabilities, artifacts/attachments, model options, explicit context, and runtime adapter interfaces. Context is supplied by the host through an explicit `AgentContextProvider`; the workbench does not scrape app state implicitly.
21
+
22
+ ## Workbench
23
+
24
+ `@inneranimalmedia/agentsam-workbench` owns reusable controlled UI primitives. Product-specific state stores, route trees, auth implementations, repo/CAD/CMS schemas, and deployment wiring remain outside it.
25
+
26
+ Local Studio is the first proof consumer. CAD and CMS should consume this layer through domain adapters rather than cloning Local Studio components.
27
+
28
+ ## Authentication and execution
29
+
30
+ The workbench does not own identity authority. Identity establishes an authenticated principal first; application authorization then creates any optional browser/container/terminal execution session. Cache and execution bindings are never account/session authority.
@@ -0,0 +1,52 @@
1
+ # AgentSam identity/auth configuration contract
2
+
3
+ The `agentsam-sdk` package owns the portable public configuration contract. Consuming applications implement storage, authorization, and host routes against this contract instead of defining competing environment names.
4
+
5
+ ## Canonical variables
6
+
7
+ | Variable | Meaning |
8
+ | --- | --- |
9
+ | `IAM_ORIGIN` | Canonical IAM authority and browser/OAuth/API origin. |
10
+ | `IAM_CLIENT_ID` | OAuth client id for an application using IAM identity. |
11
+ | `IAM_CLIENT_SECRET` | OAuth client secret. Keep it server-side. |
12
+ | `AGENTSAM_SDK_KEY` | Account/delegated SDK bearer. Raw values use the `sdk_` prefix and are sent as `Authorization: Bearer …`. |
13
+ | `AGENTSAM_BRIDGE_KEY` | Machine/integration credential. It is never a substitute for user SDK authentication. |
14
+
15
+ The host-side durable verifier for SDK credentials is `agentsam_sdk_tokens`. The SDK defines the public credential semantics; the host owns the database and authorization implementation.
16
+
17
+ `AGENTSAM_BRIDGE_KEY` remains the direct machine-secret environment variable. A host may additionally resolve a hashed credential from `agentsam_sdk_tokens` when that row has `token_type='integration'`. That does not turn the bridge credential into user authentication.
18
+
19
+ ## Migration compatibility
20
+
21
+ The current migration window accepts two deprecated read fallbacks:
22
+
23
+ ```text
24
+ IAM_ORIGIN
25
+ fallback: IAM_OAUTH_ISSUER
26
+
27
+ AGENTSAM_SDK_KEY
28
+ fallback: AGENTSAM_SDK_TOKEN
29
+ ```
30
+
31
+ Canonical names always win when both are present. New scaffolds, docs, and writes emit only the canonical names. Compatibility aliases are intentionally not a permanent parallel configuration surface.
32
+
33
+ Older platform-base aliases (`IAM_CORE_URL`, `AGENTSAM_CORE_URL`, `AGENTSAM_BASE_URL`) are compatibility-only. SDK clients prefer `IAM_ORIGIN`.
34
+
35
+ ## Credential boundaries
36
+
37
+ ```text
38
+ human/account SDK lane
39
+ AGENTSAM_SDK_KEY
40
+ -> sdk_* bearer
41
+ -> Authorization: Bearer <sdk_*>
42
+ -> account/delegated authority
43
+ -> agentsam_sdk_tokens
44
+
45
+ machine/integration lane
46
+ AGENTSAM_BRIDGE_KEY
47
+ -> machine principal
48
+ -> no user/workspace identity injection
49
+ -> host env secret OR agentsam_sdk_tokens(token_type='integration')
50
+ ```
51
+
52
+ Browser OAuth uses `IAM_ORIGIN` together with `IAM_CLIENT_ID` and `IAM_CLIENT_SECRET`. Repository identity, workspace labels, or machine trust do not prove account authority.
@@ -18,7 +18,7 @@ agentsam capabilities
18
18
  agentsam capabilities repository.snapshot --json
19
19
  ```
20
20
 
21
- This registry is intended to drive CLI/TUI discovery, AgentSam/MCP tool selection, docs, verification, and workflow capability resolution. It is deliberately not a second hosted tools database.
21
+ This registry is intended to drive CLI/terminal UI discovery, AgentSam/MCP tool selection, docs, verification, and workflow capability resolution. It is deliberately not a second hosted tools database.
22
22
 
23
23
  ## repository.snapshot
24
24
 
@@ -26,7 +26,8 @@ This registry is intended to drive CLI/TUI discovery, AgentSam/MCP tool selectio
26
26
 
27
27
  - Git resource identity and revision
28
28
  - Python repository intelligence
29
- - Merkle root and tree statistics
29
+ - Merkle root, semantic metadata root, execution-domain facts, and tree statistics
30
+ - deterministic client/server trust-boundary contradictions derived from the Merkle-bound AST graph
30
31
  - package/manifests
31
32
  - local knowledge/index generation when configured
32
33
  - last trusted local deployment receipt when available
@@ -36,6 +37,7 @@ It does **not** call an LLM, mutate source, index the repository, provision clou
36
37
 
37
38
  ```sh
38
39
  agentsam inspect --json
40
+ agentsam inspect --execution-domain browser --view files --json
39
41
  ```
40
42
 
41
43
  ```js
@@ -43,7 +45,7 @@ import { repositorySnapshot } from '@inneranimalmedia/agentsam-sdk/repository';
43
45
  const snapshot = await repositorySnapshot({ cwd: process.cwd() });
44
46
  ```
45
47
 
46
- The timestamp is not included in the content hash, so unchanged evidence produces the same `content_hash` and `snapshot_id`.
48
+ The timestamp is not included in the content hash, so unchanged evidence produces the same `content_hash` and `snapshot_id`. The default bounded index view carries a compact `analysis.trust_boundary` summary (up to 20 contradiction cards) while the canonical full snapshot retains all deterministic findings. `agentsam security scan` consumes the same analyzer rather than maintaining a separate architecture model.
47
49
 
48
50
  ## Optional AgentSam/LLM composition
49
51
 
package/docs/CLI_SHELL.md CHANGED
@@ -1,129 +1,216 @@
1
1
  # Agent Sam SDK — terminal experience
2
2
 
3
- The Agent Sam terminal is a presentation layer over real local capabilities. It is not a second execution engine and it is not tied to Gorilla, Cloudflare, or a particular model provider.
3
+ `agentsam` is the product entrypoint. Users do not choose a renderer or need to know whether a screen is implemented with ANSI, Clack, or another terminal library.
4
4
 
5
- ## Default experience
5
+ ## Product entrypoint
6
6
 
7
7
  ```bash
8
- agentsam tui
8
+ agentsam
9
9
  ```
10
10
 
11
- Runs the bundled zero-dependency Node/ANSI renderer. This is the default because it is available anywhere the npm CLI runs.
11
+ On first use in a project, Agent Sam asks whether the directory is trusted before project-local instructions, hooks, or execution policy can load. The setup flow then uses keyboard-driven selectors for runtime and model policy.
12
12
 
13
- ```bash
14
- agentsam tui rich
15
- agentsam tui rich --install
13
+ Model policy is explicit and is governed by the normative model-selection SSOT contract in `protocol/models/README.md`:
14
+
15
+ 1. **Provider** — the explicit provider lane selected by the user.
16
+ 2. **Model** — the exact provider-verified model; provider-level pseudo-models such as `automatic` or `default` are not substitutes for exact selection.
17
+ 3. **Reasoning level** — one of the reasoning efforts declared by that model.
18
+ 4. **Processing** — Standard, Fast, Flex, or another tier only when that model declares it.
19
+
20
+ `/models`, `agentsam models`, exact `-m <model_id>` selection, runtime execution, and usage receipts must all resolve through that same inventory/selection authority. AgentSam may curate and rank a useful first page, but provider availability, capabilities, limits, and pricing retain provider-authoritative provenance.
21
+
22
+ For models with materially different pricing by reasoning, service tier, or context size, these controls are user-visible policy. They are not hidden prompt hints.
23
+
24
+ After setup, bare text is an Agent Sam request. Slash commands control the runtime.
25
+
26
+ ```text
27
+ sam ~/project > Find why OAuth callback state is failing
28
+
29
+ Model request
30
+ model openai:gpt-6-astra
31
+ reasoning high
32
+ processing default
33
+ context ~18,240 input tokens
34
+ max call $... conservative ceiling
35
+
36
+ Send this request? Yes / No
16
37
  ```
17
38
 
18
- Runs the optional Python Rich renderer. `--install` creates an isolated `.agentsam/tui-venv` and installs Rich there; system Python is left alone.
39
+ The model preflight is shown before the first paid request in a session, and again if a later request raises the previously approved conservative cost ceiling. Current active context remains distinct from cumulative session usage.
19
40
 
20
- ```bash
21
- agentsam shell
41
+ ## Command picker
42
+
43
+ Typing `/` opens the scrollable command picker in an interactive terminal. The picker is generated from the implemented command catalog; commands should not be advertised before a handler exists.
44
+
45
+ Current controls include:
46
+
47
+ ```text
48
+ /model exact model + reasoning + processing selectors
49
+ /reasoning change the selected model's reasoning effort
50
+ /fast request the model's Fast processing tier
51
+ /flex request Flex processing when supported
52
+ /standard return to Standard processing
53
+ /context context economics and current active-context information
54
+ /models safe credential/provider/model inventory
55
+ /whoami authenticated IAM identity + safe credential status
56
+ /session current cumulative token/cost/resume receipt
57
+ /cf bounded Cloudflare/Workers operations
58
+ /status local project / DB / Git / PTY health
59
+ /settings project/runtime/terminal/model preferences
60
+ /pwd working directory
61
+ /cd change working directory
62
+ /git Git operations
63
+ /diff Git diff
64
+ /db local SQLite
65
+ /agent local Agent Sam dev-server request
66
+ /logs local execution events
67
+ /deploy intentional deployment flow
68
+ /clear clear the terminal
69
+ /help show commands
70
+ /exit save/pause the session and return to the host terminal
22
71
  ```
23
72
 
24
- Starts the interactive Agent Sam slash-command shell. Once the `agentsam>` prompt is visible, commands such as `/help`, `/status`, `/pwd`, and `/git` are handled by Agent Sam instead of the host shell (PowerShell, bash, or zsh). Use `/exit` to return to the host terminal.
73
+ Provider-brand commands such as `/claude` or `/codex` are not the generic shell contract. Model execution stays behind Agent Sam.
25
74
 
26
- Do not type `/help` directly at a PowerShell/bash prompt; enter `agentsam shell` first.
75
+ ## Credentials and identity
27
76
 
28
- For scripts and regression tests, a single slash command can be dispatched without opening the REPL:
77
+ A user should not need to manually `source` and `unset` provider keys for every Agent Sam command.
78
+
79
+ Agent Sam resolves credentials in this order:
80
+
81
+ 1. an explicitly supplied credential where a command contract permits one;
82
+ 2. the current process environment;
83
+ 3. the user's secure Agent Sam provider files under `~/.agentsam/env.d/`.
84
+
85
+ Provider files are machine-local and must not be group/world-readable on POSIX systems. Agent Sam parses the expected variable from the file rather than evaluating the file as shell code.
86
+
87
+ `agentsam models` uses the credential internally for safe provider discovery but never returns the secret. Its public status reports only safe facts such as provider, configured state, source class, and provider-verified model availability.
88
+
89
+ IAM login is also machine-local rather than repository state. A successful browser authentication may persist the `sdk_` bearer under `~/.agentsam/auth/session.json` with restrictive permissions. `agentsam whoami`, deploy, tunnel, and context detection can reuse that validated session. Project `.agentsam/config.json` remains portable and must not become a second identity database.
29
90
 
30
91
  ```bash
31
- agentsam shell --command /help
92
+ agentsam whoami
93
+ agentsam whoami --json
32
94
  ```
33
95
 
34
- ## Architecture
96
+ `whoami` can show safe identity/account information and whether provider credentials are available. It never prints API-key or SDK-bearer values.
97
+
98
+ ## Execution approval
99
+
100
+ Model reasoning does not itself authorize host execution.
101
+
102
+ Read-only/no-side-effect capabilities may execute under the current trusted runtime policy. A model-selected capability with declared side effects must pass a runtime-owned approval boundary before its handler is invoked.
35
103
 
36
104
  ```text
37
- CLI command / execution state
38
- |
39
- +--> Node ANSI renderer default, zero extra dependencies
40
- |
41
- +--> Python Rich renderer optional high-fidelity live presentation
42
- |
43
- +--> browser shell-kit reusable React components, separate surface
105
+ Agent Sam needs execution permission
106
+
107
+ action cloudflare.wrangler.native:whoami
108
+ target local runtime · ~/project
109
+ effect local_process
110
+ input {"command":"whoami"}
44
111
 
45
- Capabilities underneath presentation:
112
+ secrets remain runtime-owned and are not included in the model-visible result.
46
113
 
47
- Git context
48
- Local SQLite
49
- Local PTY
50
- Agent/tool execution
51
- Logs/events
52
- Deploy adapters
114
+ ? Allow cloudflare.wrangler.native:whoami?
115
+ Allow once
116
+ Always allow cloudflare.wrangler.native:whoami in this project
117
+ Deny
53
118
  ```
54
119
 
55
- Presentation consumes state. It does not authorize tools, decide policy, own databases, or execute cloud operations by itself.
120
+ Persistent approvals are exact-operation and exact-project grants. Approving `wrangler whoami` does not authorize another Wrangler operation or another repository.
56
121
 
57
- ## Local project contract
122
+ Commands whose purpose is to disclose a credential, such as `wrangler auth token`, are not model-visible capabilities. Safe identity/authorization probes are preferred.
123
+
124
+ ## Sessions and resume
58
125
 
59
- `agentsam init` creates:
126
+ Every interactive Agent Sam run receives a provider-neutral session identifier:
60
127
 
61
128
  ```text
62
- .git/
63
- .env
64
- .env.example
65
- agentsam.config.js
66
- .agentsam/config.json
67
- .agentsam/data/agentsam.sqlite
68
- db/schema.sql
69
- src/agent.js
70
- src/dev-server.js
71
- scripts/smoke.mjs
129
+ asess_<uuid>
72
130
  ```
73
131
 
74
- There is no Worker requirement in this contract.
132
+ Provider response IDs live beneath the Agent Sam session and are not the public session identity. Session files are machine-local under `~/.agentsam/sessions/` and use restrictive permissions.
75
133
 
76
- `src/agent.js` is runtime-neutral. The Node development adapter injects local SQLite. A cloud adapter may later inject D1 or another compatible store.
134
+ The session retains enough runtime state to continue a compatible provider conversation, including selected model policy, provider continuation reference, current usage snapshot, cumulative usage, accumulated catalog-calculated cost, last safe error receipt, cwd, and the last substantive user request/command used as the session title.
77
135
 
78
- ## TUI ownership
136
+ Housekeeping actions such as `/exit`, `/help`, and `/session` do not replace that human-readable title.
79
137
 
80
- | Surface | Location | Role |
81
- |---|---|---|
82
- | ANSI | `examples/agentsam-tui-ansi.mjs` | npm-native default terminal renderer |
83
- | Rich | `python/agentsam_sdk/tui/` | optional richer cards, progress, events, logs |
84
- | shell-kit | `packages/agentsam-shell-kit/` | reusable React/browser work-surface components |
85
- | Gorilla | `templates/gorilla-shell/` | visual/theme experiment only |
138
+ On Ctrl+C or normal exit, Agent Sam saves the session and prints a compact receipt:
86
139
 
87
- Gorilla is intentionally not scaffolded by default.
140
+ ```text
141
+ Token usage: total=21,463 input=21,244 (+ 60,544 cached) output=219 reasoning=...
142
+ Cost: $... · openai:gpt-6-astra · fast
143
+ Active context: ... tokens
88
144
 
89
- ## Commands
145
+ To continue this session, run:
146
+ agentsam resume asess_...
90
147
 
91
- ```text
92
- /help show commands
93
- /status local project / DB / Git / PTY health
94
- /context current repository + revision
95
- /pwd working directory
96
- /cd change directory
97
- /git Git operations
98
- /db local SQLite
99
- /agent invoke configured Agent Sam
100
- /logs local execution events
101
- /tui terminal presentation
102
- /deploy intentionally add a cloud adapter
103
- /exit exit Agent Sam shell and return to the host terminal
148
+ Or run:
149
+ agentsam resume
150
+
151
+ and select:
152
+ Run wrangler whoami
153
+ ```
154
+
155
+ Provider-reported token usage is authoritative when available. Cached input is reported separately rather than added to normal input. Cost is calculated from Agent Sam's active model/pricing authority and is not presented as a provider invoice unless the provider supplied one.
156
+
157
+ Resume commands:
158
+
159
+ ```bash
160
+ agentsam resume asess_...
161
+ agentsam resume # scrollable recent-session picker in a TTY
162
+ agentsam resume --list
163
+ agentsam resume --json
104
164
  ```
105
165
 
106
- Provider-specific commands such as `/claude` or `/codex` are not part of the generic shell contract. Model routing belongs behind Agent Sam.
166
+ Changing model, reasoning effort, or processing tier breaks provider-continuation compatibility for the next turn; Agent Sam starts a fresh provider continuation while retaining cumulative Agent Sam session accounting.
167
+
168
+ ## Error presentation
107
169
 
108
- Workspace switching is not required for local tooling. Authenticated user/session identity is the security boundary; workspace/project labels are organizational metadata.
170
+ Errors preserve machine identity instead of becoming generic prose. Where available the terminal should surface HTTP status, provider error type/code, request or Ray ID, retry metadata, requested/resolved service tier, and retry classification. Secrets and authorization headers are redacted before an error receipt enters model-visible output or a persisted session.
109
171
 
110
- ## Cloud graduation
172
+ ## One-shot commands
111
173
 
112
- Cloud infrastructure is generated when requested, not during local init.
174
+ Normal commands remain deterministic and scriptable:
175
+
176
+ ```bash
177
+ agentsam status
178
+ agentsam models
179
+ agentsam whoami --json
180
+ agentsam inspect --match oauth --view files --json
181
+ agentsam deploy
182
+ agentsam --help
183
+ ```
184
+
185
+ `agentsam shell` remains an explicit/secondary way to enter the same shell. Bare `agentsam` is the normal interactive entrypoint.
186
+
187
+ For regression tests, a slash command can be dispatched without creating interactive-session clutter:
188
+
189
+ ```bash
190
+ agentsam shell --command /help
191
+ ```
192
+
193
+ ## Internal UI engine
194
+
195
+ Presentation is implementation detail:
113
196
 
114
197
  ```text
115
- local project
116
- |
117
- +--> agentsam deploy --target cloudflare
118
- |
119
- +--> src/cloudflare-worker.js
120
- +--> wrangler.toml
121
- +--> migrations/0001_agentsam_core.sql
122
- +--> provisioned account bindings
198
+ Agent Sam lifecycle/state
199
+ |
200
+ +--> ANSI / picocolors semantic color + cursor control
201
+ +--> Clack prompts arrow-key selects / confirms / text input
202
+ +--> runtime activity thinking/tool/context lifecycle
203
+ +--> node-pty / host runtime real process/filesystem boundary
123
204
  ```
124
205
 
125
- The same `src/agent.js` remains application authority.
206
+ SDK developers can preview rendering experiments from this repository, but those are design-lab commands rather than installed product vocabulary.
207
+
208
+ ## Local project contract
209
+
210
+ `agentsam init` owns portable repository/project setup. User identity, provider secrets, session history, execution approvals, and provider continuation state are machine/account runtime state and must not be written into portable project configuration.
211
+
212
+ Local development does not require a cloud account. Cloud infrastructure is added intentionally.
126
213
 
127
214
  ## Design rule
128
215
 
129
- A CLI operation should be understandable in plain text first, then enhanced by ANSI/Rich presentation. CI and agent capture must always have a deterministic non-interactive path (`--check`, JSON receipts where applicable).
216
+ A CLI operation must remain understandable in plain text and deterministic in CI/pipes. Interactive terminals may enhance state with color, cursor redraw, selectors, confirmation, progress, and animation. Presentation does not authorize tools, own credentials, or silently become model-routing authority. Runtime contracts do.
@@ -0,0 +1,101 @@
1
+ # AgentSam CMS Studio architecture
2
+
3
+ The SDK treats CMS authoring and the public website as separate deployment products that share publication contracts.
4
+
5
+ ```text
6
+ apps/client-cms-editor/ authenticated authoring/control app
7
+ │
8
+ ├─ pages / sections / themes / assets
9
+ ├─ AgentSam workbench
10
+ ├─ preview
11
+ └─ publish
12
+ ↓
13
+ structured publication snapshot
14
+ ┌──┴──┐
15
+ │ │
16
+ D1 R2 WEBSITE_ASSETS
17
+ metadata content/media/theme artifacts
18
+ │ │
19
+ └──┬──┘
20
+ ↓
21
+ small public CMS runtime
22
+ ```
23
+
24
+ The public runtime must not inherit the full authoring dependency graph. Monaco, terminal, browser automation, authenticated admin UI, and the AgentSam workbench stay in the authoring application unless a public feature explicitly requires them.
25
+
26
+ ## Shared AgentSam platform
27
+
28
+ CMS consumes `@inneranimalmedia/agentsam-contracts` and `@inneranimalmedia/agentsam-workbench`, the same product-neutral layer proven first by Local Studio. `CmsAgentSurface` supplies explicit CMS context to the shared `AgentWorkbenchAdapter`; it does not scrape editor state or invent a CMS-specific chat transport.
29
+
30
+ Identity is resolved before AgentSam execution:
31
+
32
+ ```text
33
+ IAM
34
+ ↓
35
+ authenticated principal (accountId + authUserId)
36
+ ↓
37
+ application authorization
38
+ ↓
39
+ CMS context / capabilities
40
+ ↓
41
+ optional browser or container runtime
42
+ ```
43
+
44
+ `SESSION_CACHE` is an optional cache only. `MY_CONTAINER` and `MYBROWSER` are execution infrastructure only. None may become identity/session authority.
45
+
46
+ ## Cloudflare capability contract
47
+
48
+ Baseline `cms-cloud` requires `DB` and `WEBSITE_ASSETS`. Other bindings are capability-driven:
49
+
50
+ - `iam` → `IAM_CLIENT_ID`, `IAM_CLIENT_SECRET`, `IAM_ORIGIN`
51
+ - `workers-ai` → `AGENTSAM_WAI`
52
+ - `browser` → `MYBROWSER`
53
+ - `container` → `MY_CONTAINER`
54
+ - `encrypted-secrets` → `SECRETS_ENCRYPTION_KEY`
55
+ - `acp` → `ACP_CLIENT_ID`, `ACP_CLIENT_SECRET`
56
+
57
+ `IAM_ORIGIN` means the canonical IAM issuer/auth service. It must not silently mean the current website origin.
58
+
59
+ ## Routes
60
+
61
+ The intended ownership boundary is:
62
+
63
+ ```text
64
+ /* public CMS
65
+ /auth/* identity
66
+ /dashboard/* authenticated application
67
+ /dashboard/agentsam authenticated AgentSam product
68
+ /dashboard/cms authenticated CMS Studio
69
+ /api/public/* visitor-safe CMS APIs
70
+ /api/auth/* identity/session
71
+ /api/cms/* authenticated editor/publishing APIs
72
+ /api/agentsam/* authenticated AgentSam APIs
73
+ ```
74
+
75
+ ## Publication data
76
+
77
+ Prefer versioned structured sections such as:
78
+
79
+ ```json
80
+ {
81
+ "publicationId": "pub_example",
82
+ "route": "/about",
83
+ "revision": 18,
84
+ "theme": "iam-classy",
85
+ "sections": [
86
+ {
87
+ "type": "hero",
88
+ "props": {
89
+ "title": "About us",
90
+ "imageAsset": "asset_example"
91
+ }
92
+ }
93
+ ]
94
+ }
95
+ ```
96
+
97
+ The renderer may produce sanitized HTML/static snapshots from this data. Arbitrary executable HTML from the editor is not the public-content authority.
98
+
99
+ ## Current server authority
100
+
101
+ The imported app contains only the portable CMS API/routing/preview bridge. The current full CMS domain remains in `inneranimalmedia/src/core/agentsam/cms/` at the import provenance revision. The next server-side extraction should create reusable `packages/agentsam-cms-*` packages rather than copy that domain into this app.