@inneranimalmedia/agentsam-sdk 2.4.1 → 2.5.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 (158) hide show
  1. package/README.md +7 -6
  2. package/docs/AGENTSAM_WORKBENCH.md +30 -0
  3. package/docs/AUTH_IDENTITY_CONTRACT.md +52 -0
  4. package/docs/CAPABILITIES.md +5 -3
  5. package/docs/CLI_SHELL.md +57 -80
  6. package/docs/CMS_STUDIO.md +101 -0
  7. package/docs/CONTEXT.md +170 -0
  8. package/docs/LOCAL_OLLAMA.md +58 -0
  9. package/docs/MERKLE.md +19 -19
  10. package/docs/PORTABLE_CONTEXT.md +4 -3
  11. package/docs/PROJECT_CONFIG.md +72 -0
  12. package/docs/RELEASES.md +26 -2
  13. package/docs/REPOSITORY_INTELLIGENCE.md +1 -1
  14. package/docs/REPOSITORY_KNOWLEDGE.md +114 -0
  15. package/docs/SDK_WORKER.md +86 -0
  16. package/docs/SECURITY.md +59 -22
  17. package/docs/client-cms-editor.md +15 -0
  18. package/docs/local-studio/WORKMODE_DONOR_NOTES.md +485 -0
  19. package/package.json +17 -4
  20. package/packages/identity/package.json +11 -2
  21. package/packages/identity/src/contracts/auth-config.js +98 -0
  22. package/packages/identity/src/index.js +1 -0
  23. package/packages/identity/src/oauth/README.md +2 -2
  24. package/packages/identity/src/oauth/credentials.js +11 -4
  25. package/packages/identity/src/oauth/iam-platform.js +3 -3
  26. package/packages/identity/src/providers/iam/index.js +7 -7
  27. package/packages/identity/src/providers/iam/oauth.js +6 -4
  28. package/packages/identity/src/providers/iam/profile.js +5 -5
  29. package/packages/identity/tests/auth-config.test.mjs +57 -0
  30. package/packages/identity/tests/oauth-credentials.test.mjs +13 -2
  31. package/protocol/FILEMETA_V1.md +95 -0
  32. package/protocol/INSPECT_VIEWS_V1.md +40 -0
  33. package/protocol/MERKLE_PERSISTENCE_V1.md +50 -0
  34. package/protocol/MERKLE_V1.md +3 -1
  35. package/protocol/capabilities/manifest.json +32 -3
  36. package/protocol/capabilities/repository-snapshot.schema.json +1 -0
  37. package/protocol/context/context-budget.schema.json +41 -0
  38. package/protocol/context/context-item.schema.json +20 -0
  39. package/protocol/context/resolved-context-pack.schema.json +42 -0
  40. package/protocol/context/result-policy.schema.json +17 -0
  41. package/protocol/knowledge/context-pack.schema.json +33 -0
  42. package/protocol/knowledge/retrieval-query.schema.json +68 -13
  43. package/python/README.md +15 -7
  44. package/python/agentsam_sdk/cli.py +0 -21
  45. package/python/agentsam_sdk/tui/README.md +17 -12
  46. package/python/agentsam_sdk/tui/bootstrap.py +2 -2
  47. package/python/agentsam_sdk/tui/demo.py +25 -10
  48. package/python/agentsam_sdk/tui/onboarding.py +208 -0
  49. package/python/tests/test_tui_cli.py +7 -6
  50. package/skills/README.md +21 -0
  51. package/skills/agentsam-app-fundamentals/SKILL.md +165 -0
  52. package/skills/agentsam-app-fundamentals/references/graphs-contracts-ast-merkle.md +89 -0
  53. package/skills/agentsam-app-fundamentals/references/trust-credentials-and-destinations.md +99 -0
  54. package/skills/agentsam-jr-dev/SKILL.md +232 -0
  55. package/skills/agentsam-jr-dev/references/real-application-logic.md +156 -0
  56. package/skills/agentsam-jr-dev/references/web-application-fundamentals.md +240 -0
  57. package/skills/agentsam-progression-guard/SKILL.md +197 -0
  58. package/skills/agentsam-progression-guard/references/checkpoint-chain.md +111 -0
  59. package/skills/agentsam-progression-guard/references/hooks-operational-io.md +96 -0
  60. package/skills/catalog.json +53 -0
  61. package/src/capabilities/index.js +7 -0
  62. package/src/capabilities/repository-snapshot-view.js +238 -0
  63. package/src/capabilities/repository-snapshot.js +28 -14
  64. package/src/cli.js +108 -56
  65. package/src/commands/context.js +14 -2
  66. package/src/commands/db.js +4 -7
  67. package/src/commands/deploy.js +17 -31
  68. package/src/commands/interactive.js +21 -0
  69. package/src/commands/knowledge.js +27 -4
  70. package/src/commands/merkle-persist.js +118 -0
  71. package/src/commands/merkle.js +32 -17
  72. package/src/commands/models.js +107 -0
  73. package/src/commands/ollama.js +259 -0
  74. package/src/commands/preferences.js +102 -0
  75. package/src/commands/product.js +86 -16
  76. package/src/commands/security.js +3 -3
  77. package/src/commands/shell.js +71 -27
  78. package/src/commands/skills.js +66 -0
  79. package/src/commands/start-local.js +1 -1
  80. package/src/commands/tunnel.js +5 -4
  81. package/src/context/budget.js +58 -0
  82. package/src/context/compact.js +28 -0
  83. package/src/context/index.js +5 -0
  84. package/src/context/resolve.js +84 -0
  85. package/src/context/result-policy.js +66 -0
  86. package/src/index.js +16 -0
  87. package/src/indexing/execution-boundary.js +144 -0
  88. package/src/indexing/index.js +8 -0
  89. package/src/indexing/provider.js +41 -0
  90. package/src/knowledge/config.js +2 -2
  91. package/src/knowledge/context-pack.js +12 -1
  92. package/src/knowledge/contracts.js +9 -4
  93. package/src/knowledge/engine.js +7 -3
  94. package/src/knowledge/service/server.js +1 -1
  95. package/src/lib/bridge-client.js +7 -5
  96. package/src/lib/cli-preferences.js +74 -0
  97. package/src/lib/core-client.js +8 -8
  98. package/src/lib/deploy-receipt/index.js +5 -2
  99. package/src/lib/detect-context.js +6 -5
  100. package/src/lib/identity-scaffold.js +1 -1
  101. package/src/lib/local-scaffold.js +35 -33
  102. package/src/lib/local-status.js +9 -17
  103. package/src/lib/merkle/cloudflare-persistence.js +321 -0
  104. package/src/lib/merkle/filemeta.js +43 -0
  105. package/src/lib/merkle/git-ignore.js +24 -0
  106. package/src/lib/merkle/hash.js +1 -0
  107. package/src/lib/merkle/index.js +22 -0
  108. package/src/lib/merkle/persistence.js +72 -0
  109. package/src/lib/merkle/semantic.js +359 -0
  110. package/src/lib/merkle/snapshot.js +9 -3
  111. package/src/lib/merkle/tree.js +11 -6
  112. package/src/lib/project-config.js +227 -0
  113. package/src/lib/project-rules.js +68 -0
  114. package/src/lib/save-sdk-token.js +1 -1
  115. package/src/lib/slash-commands.js +2 -1
  116. package/src/lib/tools.js +11 -5
  117. package/src/security/index.js +1 -0
  118. package/src/security/inventory.js +4 -1
  119. package/src/security/render.js +27 -5
  120. package/src/security/scan.js +24 -9
  121. package/src/security/trust-boundary.js +24 -0
  122. package/src/skills/index.js +64 -0
  123. package/src/tools/index.js +1 -0
  124. package/src/tools/search.js +70 -0
  125. package/src/ui/ansi.js +1 -1
  126. package/src/ui/boot.js +56 -0
  127. package/src/ui/merkle/render.js +1 -0
  128. package/src/ui/runtime-activity.js +192 -0
  129. package/src/ui/theme.js +19 -18
  130. package/test/app-building-skills.test.mjs +61 -0
  131. package/test/apps-scaffold-contract.test.mjs +56 -0
  132. package/test/capabilities.test.mjs +53 -4
  133. package/test/cli-preferences.test.mjs +25 -0
  134. package/test/context.test.mjs +95 -0
  135. package/test/indexing-provider.test.mjs +29 -0
  136. package/test/jr-dev-skill.test.mjs +26 -0
  137. package/test/knowledge-context-pack.test.mjs +19 -0
  138. package/test/knowledge.test.mjs +1 -1
  139. package/test/merkle-persistence.test.mjs +91 -0
  140. package/test/merkle.test.mjs +77 -3
  141. package/test/models.test.mjs +37 -0
  142. package/test/ollama.test.mjs +94 -0
  143. package/test/project-config.test.mjs +81 -0
  144. package/test/project-rules.test.mjs +44 -0
  145. package/test/release-hygiene.test.mjs +34 -0
  146. package/test/repository-snapshot-view.test.mjs +112 -0
  147. package/test/runtime-activity.test.mjs +98 -0
  148. package/test/sdk-worker-contract.test.mjs +68 -0
  149. package/test/security.test.mjs +46 -0
  150. package/test/shell.test.mjs +8 -1
  151. package/test/skills.test.mjs +22 -0
  152. package/test/smoke.mjs +2 -2
  153. package/test/theme-portability.test.mjs +14 -0
  154. package/test/tools-search.test.mjs +27 -0
  155. package/examples/agentsam-tui-ansi.mjs +0 -149
  156. package/src/commands/tui.js +0 -120
  157. package/src/ui/splash-xterm.js +0 -290
  158. package/src/ui/splash.js +0 -426
package/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  A deterministic-first application and agent toolkit: reusable repository, knowledge, integrity,
4
4
  security, identity, scaffolding, and delivery capabilities with optional AgentSam/LLM composition.
5
- CLI/TUI surfaces make those same primitives easy to use without making a model part of the implementation.
5
+ The interactive CLI makes those same primitives easy to use without making a model part of the implementation.
6
6
 
7
7
  **npm:** `@inneranimalmedia/agentsam-sdk` · **Source:** [GitHub](https://github.com/SamPrimeaux/agentsam-sdk)
8
8
 
9
9
  Node 22.5+ is required. Docker is optional for container commands. Python 3.10+ is required
10
- for the bundled Python repository tools; Rich is optional for the richer terminal UI.
11
- See the [2.0 release guide](docs/sdk-2.0-release.md) for publication status and migration notes.
10
+ for the bundled Python repository tools. Rich is optional for the contributor-only terminal renderer lab.
11
+ See [release receipts](docs/RELEASES.md) for publication status.
12
12
 
13
13
  ## Install
14
14
 
@@ -71,17 +71,18 @@ read-only `repository.snapshot` composition primitive. See [Capabilities and pre
71
71
  | Capability | Entry point | Guide |
72
72
  | --- | --- | --- |
73
73
  | Capability registry + presets | `agentsam capabilities`, `/capabilities`, `/presets` | [Capabilities](docs/CAPABILITIES.md) |
74
+ | Portable AgentSam skills | `agentsam skills`; `/skills` | [Skills](skills/README.md) |
74
75
  | Canonical repository snapshot | `agentsam inspect --json`; `/repository` | [Capabilities](docs/CAPABILITIES.md) |
75
76
  | Git context and bridge client | `agentsam context --json`; `/git-context`, `/bridge-client` | [Portable context](docs/PORTABLE_CONTEXT.md) |
76
77
  | Identity contracts and adapters | `/identity`; `agentsam identity init` | [Identity](packages/identity/README.md) |
77
78
  | Repository knowledge | `agentsam index`, `search`, `repo`; `/knowledge` | [Knowledge](docs/portable-knowledge.md) |
78
79
  | File integrity | `agentsam merkle`; `/merkle` | [Merkle](docs/MERKLE.md) |
79
- | Dependency health and repair | `agentsam security`; `/security` | [Security](docs/SECURITY.md) |
80
+ | Security, trust-boundary scan, and repair | `agentsam security`; `/security` | [Security](docs/SECURITY.md) |
80
81
  | Mini prototypes | `agentsam mini`; `/mini` | [Mini](docs/MINI.md) |
81
82
  | Recon bounded-worker packets | `agentsam recon pack\|validate` | [Recon](docs/RECON.md) |
82
83
  | Local containers | `agentsam dockerize`; `/dockerize` | [Dockerize](docs/DOCKERIZE.md) |
83
84
  | Background indexing service | Docker `knowledge_service`; `/knowledge-service-client` | [Knowledge service](docs/knowledge-service.md) |
84
- | Local status, DB, terminal UI | `agentsam status`, `db`, `tui`, `start-local` | [Terminal UI](docs/CLI_SHELL.md) |
85
+ | Interactive Agent Sam + local runtime | `agentsam`, `agentsam status`, `db`, `models`, `start-local` | [CLI shell](docs/CLI_SHELL.md) |
85
86
 
86
87
  Export suffixes such as `/identity` mean imports from
87
88
  `@inneranimalmedia/agentsam-sdk/identity`. Use `agentsam <command> --help` where supported.
@@ -123,7 +124,7 @@ npm run verify:release
123
124
 
124
125
  Release verification runs Node/identity tests, bootstrap and package checks, installed
125
126
  tarball fixtures in unrelated repositories, Python tests, and a complete dependency scan.
126
- [Development](DEVELOPMENT.md) · [Release guide](docs/sdk-2.0-release.md) ·
127
+ [Development](DEVELOPMENT.md) · [Release receipts](docs/RELEASES.md) ·
127
128
  [Branch archive](docs/branch-archive-2026-09-02.md).
128
129
 
129
130
  License: MIT. Optional visual experiments and host-specific integrations retain their
@@ -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,106 @@
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, Rich, 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 the first run for a project, Agent Sam opens keyboard-driven setup for the project, runtime, terminal, and model preference. On later runs it shows a short project-aware boot transition and enters the Agent Sam prompt.
12
12
 
13
- ```bash
14
- agentsam tui rich
15
- agentsam tui rich --install
16
- ```
13
+ ```text
14
+ $ agentsam
17
15
 
18
- Runs the optional Python Rich renderer. `--install` creates an isolated `.agentsam/tui-venv` and installs Rich there; system Python is left alone.
16
+ Agent Sam
17
+ my-project · main · qwen2.5-coder
19
18
 
20
- ```bash
21
- agentsam shell
19
+ ✓ project
20
+ ✓ runtime
21
+ ✓ model
22
+
23
+ username ~/path/to/project >
22
24
  ```
23
25
 
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.
26
+ The model stored by the CLI is a **preference only**. It does not replace the connected host/runtime as model-routing authority.
27
+
28
+ Live terminal scenes are automatic product behavior. When Agent Sam is actively handling an `/agent` request, the installed CLI renders the compact thinking/activity panel itself; users never run a renderer or preview command. The same shipped activity seam accepts model, tool, and context-compaction lifecycle events from richer hosts. Pipes and CI remain plain/deterministic.
29
+
30
+ Use `/settings` inside Agent Sam to revisit the keyboard choices and `/models` to inspect providers and locally available models.
25
31
 
26
- Do not type `/help` directly at a PowerShell/bash prompt; enter `agentsam shell` first.
32
+ ## One-shot commands
27
33
 
28
- For scripts and regression tests, a single slash command can be dispatched without opening the REPL:
34
+ Normal commands remain deterministic and scriptable:
29
35
 
30
36
  ```bash
31
- agentsam shell --command /help
37
+ agentsam status
38
+ agentsam models
39
+ agentsam inspect --json
40
+ agentsam deploy
41
+ agentsam --help
32
42
  ```
33
43
 
34
- ## Architecture
44
+ `agentsam shell` remains an explicit/secondary way to enter the slash-command shell. Bare `agentsam` is the normal interactive entrypoint.
35
45
 
36
- ```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
44
-
45
- Capabilities underneath presentation:
46
+ For regression tests, one slash command can still be dispatched without opening an interactive terminal:
46
47
 
47
- Git context
48
- Local SQLite
49
- Local PTY
50
- Agent/tool execution
51
- Logs/events
52
- Deploy adapters
48
+ ```bash
49
+ agentsam shell --command /help
53
50
  ```
54
51
 
55
- Presentation consumes state. It does not authorize tools, decide policy, own databases, or execute cloud operations by itself.
56
-
57
- ## Local project contract
52
+ ## Internal UI engine
58
53
 
59
- `agentsam init` creates:
54
+ The renderer is implementation detail:
60
55
 
61
56
  ```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
57
+ Agent Sam lifecycle/state
58
+ |
59
+ +--> ANSI / picocolors semantic color + cursor control
60
+ +--> Rich renderer high-fidelity live render experiments
61
+ +--> Clack prompts arrow-key selects / confirms / text input
62
+ +--> node-pty real shell/process/filesystem
72
63
  ```
73
64
 
74
- There is no Worker requirement in this contract.
65
+ SDK developers can preview render experiments from this repository without exposing renderer names as product commands:
75
66
 
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.
77
-
78
- ## TUI ownership
79
-
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 |
67
+ ```bash
68
+ npm run ui:preview -- tour
69
+ npm run ui:preview -- boot
70
+ npm run ui:preview -- setup
71
+ npm run ui:preview -- thinking
72
+ npm run ui:preview -- ready
73
+ npm run ui:preview -- ansi
74
+ ```
86
75
 
87
- Gorilla is intentionally not scaffolded by default.
76
+ These preview commands are a design lab, not part of the installed user vocabulary.
88
77
 
89
- ## Commands
78
+ ## Slash commands
90
79
 
91
80
  ```text
92
81
  /help show commands
93
82
  /status local project / DB / Git / PTY health
94
83
  /context current repository + revision
95
84
  /pwd working directory
96
- /cd change directory
85
+ /cd change working directory
97
86
  /git Git operations
98
87
  /db local SQLite
99
88
  /agent invoke configured Agent Sam
89
+ /models inspect available providers and local models
90
+ /settings choose project/runtime/terminal/model preference
100
91
  /logs local execution events
101
- /tui terminal presentation
102
92
  /deploy intentionally add a cloud adapter
103
- /exit exit Agent Sam shell and return to the host terminal
93
+ /exit exit Agent Sam and return to the host terminal
104
94
  ```
105
95
 
106
- Provider-specific commands such as `/claude` or `/codex` are not part of the generic shell contract. Model routing belongs behind Agent Sam.
107
-
108
- Workspace switching is not required for local tooling. Authenticated user/session identity is the security boundary; workspace/project labels are organizational metadata.
109
-
110
- ## Cloud graduation
96
+ Provider-specific commands such as `/claude` or `/codex` are not part of the generic shell contract. Model execution/routing belongs behind Agent Sam.
111
97
 
112
- Cloud infrastructure is generated when requested, not during local init.
98
+ ## Local project contract
113
99
 
114
- ```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
123
- ```
100
+ `agentsam init` creates a local project with Git, `.env`, `.agentsam/config.json`, a committed `.agentsamrules` project-instruction file, local SQLite, and the project runtime files. The setup wizard uses keyboard-driven Clack prompts in an interactive terminal; flags keep non-interactive creation deterministic.
124
101
 
125
- The same `src/agent.js` remains application authority.
102
+ Local development requires no Worker or cloud account. Cloud infrastructure is added intentionally at deploy time.
126
103
 
127
104
  ## Design rule
128
105
 
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).
106
+ A CLI operation must remain understandable in plain text and deterministic in CI/pipes. Interactive terminals may enhance that state with color, cursor redraw, prompts, progress, and animation. Presentation does not authorize tools, own execution policy, or silently become model-routing authority.
@@ -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.
@@ -0,0 +1,170 @@
1
+ # Agent Sam context contracts
2
+
3
+ Agent Sam treats context as a bounded evidence pack, not as a place to dump every available index, tool, file, or prior message.
4
+
5
+ ## Project rules
6
+
7
+ Generated projects include a committed `.agentsamrules` file. It is the repository-level instruction surface, similar in spirit to `.cursorrules`.
8
+
9
+ ```text
10
+ repo/
11
+ ├── .agentsam/config.json portable project identity/defaults
12
+ ├── .agentsamrules committed project instructions
13
+ └── .agentsam/cli.json machine/user preferences; gitignored
14
+ ```
15
+
16
+ `loadProjectRules()` searches upward from the active cwd, hashes the source, and bounds loaded content before it can enter system context. The portable default ceiling is 24,000 characters; a host may choose a lower ceiling through its context budget.
17
+
18
+ `.agentsamrules` is for durable repository instructions and conventions. It is not a place for secrets, account IDs, active runs, task state, model history, terminal sessions, or Merkle roots.
19
+
20
+ ## Result policy
21
+
22
+ Every result-producing capability should have a result policy. Absence of a custom policy means the bounded SDK default:
23
+
24
+ ```json
25
+ {
26
+ "max_items": 8,
27
+ "max_chars": 24000,
28
+ "detail": "excerpt"
29
+ }
30
+ ```
31
+
32
+ A caller may request less. Asking for more items, more characters, or a higher detail class requires the explicit `higher-detail` operation.
33
+
34
+ Progressive detail is ordered as:
35
+
36
+ ```text
37
+ metadata
38
+ ↓
39
+ card
40
+ ↓
41
+ excerpt
42
+ ↓
43
+ range
44
+ ↓
45
+ full
46
+ ```
47
+
48
+ `normalizeResultPolicy()` enforces the ceiling. Built-in SDK tool cards inherit the bounded default rather than silently behaving as unlimited.
49
+
50
+ ## Context budget
51
+
52
+ `createContextBudget()` derives per-class ceilings from the selected model's context window. The default operating ratios are:
53
+
54
+ ```text
55
+ target active input 60%
56
+ emergency hard line 85%
57
+ ```
58
+
59
+ The remaining window is deliberate headroom for additional retrieval, tool iterations, reasoning, user input, and output.
60
+
61
+ A budget owns separate ceilings for:
62
+
63
+ ```text
64
+ system / project rules
65
+ tool schemas
66
+ retrieved evidence
67
+ single file reads
68
+ cumulative file reads per turn
69
+ tool results
70
+ ```
71
+
72
+ For example:
73
+
74
+ ```js
75
+ import { createContextBudget } from '@inneranimalmedia/agentsam-sdk/context';
76
+
77
+ const budget = createContextBudget({
78
+ windowTokens: 250_000,
79
+ });
80
+ ```
81
+
82
+ The resulting budget tracks both tokens and deterministic character ceilings.
83
+
84
+ ## Context items
85
+
86
+ Portable context evidence uses the following shape:
87
+
88
+ ```ts
89
+ interface ContextItem {
90
+ ref: string;
91
+ kind: 'file' | 'symbol' | 'memory' | 'tool_result' | 'repo' | 'artifact';
92
+ chars: number;
93
+ hash?: string;
94
+ priority: number;
95
+ content?: string;
96
+ }
97
+ ```
98
+
99
+ `resolveContext()` sorts candidate evidence by priority, applies kind-specific and cumulative limits, and returns only the selected items.
100
+
101
+ `resolveProjectContext()` does the same while automatically loading `.agentsamrules` within the system-context ceiling.
102
+
103
+ Every resolved pack includes a receipt:
104
+
105
+ ```json
106
+ {
107
+ "chars": 18422,
108
+ "evidence_chars": 17769,
109
+ "system_chars": 653,
110
+ "estimated_tokens": 4606,
111
+ "sources_considered": 73,
112
+ "sources_included": 6,
113
+ "sources_deferred": 67,
114
+ "deferred_refs": []
115
+ }
116
+ ```
117
+
118
+ The existing knowledge `ContextPack` now uses the same receipt vocabulary for retrieval hits.
119
+
120
+ ### Consumed tool results
121
+
122
+ `compactConsumedToolResult()` defaults to 4,000 characters for evidence that has already had its high-fidelity pass. It preserves the item ref/hash/priority so later turns can expand the source again instead of replaying the original dump.
123
+
124
+ ## Index law
125
+
126
+ > An index is a retrieval substrate, never prompt content.
127
+
128
+ The active prompt should receive a compact repository/index status plus selected evidence references. It should not receive an entire repository tree, symbol graph, embedding set, tool catalog, or hundreds of search results.
129
+
130
+ Prefer evidence in this order whenever possible:
131
+
132
+ ```text
133
+ exact structural evidence
134
+ ↓
135
+ bounded lexical/search evidence
136
+ ↓
137
+ semantic retrieval
138
+ ↓
139
+ explicit larger range/full object only when required
140
+ ```
141
+
142
+ ## Tool discovery
143
+
144
+ `searchToolCards()` supports cards-first discovery. It accepts a host/tool catalog and returns compact cards without full input schemas:
145
+
146
+ ```json
147
+ {
148
+ "tool": "code.retrieve",
149
+ "summary": "Find symbols, callers, and semantic code matches.",
150
+ "risk": "read",
151
+ "required": ["query"],
152
+ "result_class": "bounded_evidence"
153
+ }
154
+ ```
155
+
156
+ A host can hydrate the selected tool's full schema only after selection. This keeps the portable contract compatible with small local catalogs and large hosted catalogs without injecting all schemas at turn zero.
157
+
158
+ ## Subagent handoff law
159
+
160
+ A child agent should return a compact work receipt rather than its entire prompt/tool history:
161
+
162
+ ```text
163
+ conclusion
164
+ evidence refs
165
+ changed files
166
+ commands/tests
167
+ uncertainty
168
+ ```
169
+
170
+ The parent can expand an evidence ref when needed.