@bnbagent/studio-cli 0.0.6-alpha.1

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 (55) hide show
  1. package/DISCLAIMER.md +48 -0
  2. package/LICENSE +201 -0
  3. package/dist/_agentcoreName-DZDWEYD3.js +7 -0
  4. package/dist/_twak-5XQMOFUC.js +25 -0
  5. package/dist/bag.js +19358 -0
  6. package/dist/chunk-7RAKL4AS.js +172 -0
  7. package/dist/chunk-M3ODFCA7.js +1053 -0
  8. package/dist/chunk-U7IDQ3K5.js +14 -0
  9. package/dist/deployCli-N6TPN6XA.js +40 -0
  10. package/package.json +64 -0
  11. package/recipes/agent/code/{{PKG}}/signing.ts.tmpl +287 -0
  12. package/recipes/agent/recipe.toml +35 -0
  13. package/recipes/providers/pieverse-llm/recipe.toml +16 -0
  14. package/recipes/providers/pieverse-llm/skills/funding-pieverse-llm.md +203 -0
  15. package/recipes/runtimes/agentcore/code/{{PKG}}/.dockerignore.tmpl +8 -0
  16. package/recipes/runtimes/agentcore/code/{{PKG}}/Dockerfile.tmpl +50 -0
  17. package/recipes/runtimes/agentcore/code/{{PKG}}/agentCard.ts.tmpl +135 -0
  18. package/recipes/runtimes/agentcore/code/{{PKG}}/dualMain.ts.tmpl +402 -0
  19. package/recipes/runtimes/agentcore/code/{{PKG}}/executor.ts.tmpl +147 -0
  20. package/recipes/runtimes/agentcore/code/{{PKG}}/main.ts.tmpl +344 -0
  21. package/recipes/runtimes/agentcore/code/{{PKG}}/mcpMain.ts.tmpl +677 -0
  22. package/recipes/runtimes/agentcore/code/{{PKG}}/model.ts.tmpl +117 -0
  23. package/recipes/runtimes/agentcore/code/{{PKG}}/sellerCore.ts.tmpl +503 -0
  24. package/recipes/runtimes/agentcore/code/{{PKG}}/tools.ts.tmpl +157 -0
  25. package/recipes/runtimes/agentcore/recipe.toml +97 -0
  26. package/recipes/runtimes/azure-foundry/code/{{PKG}}/.dockerignore.tmpl +8 -0
  27. package/recipes/runtimes/azure-foundry/code/{{PKG}}/Dockerfile.tmpl +47 -0
  28. package/recipes/runtimes/azure-foundry/code/{{PKG}}/agentCard.ts.tmpl +131 -0
  29. package/recipes/runtimes/azure-foundry/code/{{PKG}}/executor.ts.tmpl +504 -0
  30. package/recipes/runtimes/azure-foundry/code/{{PKG}}/foundryMain.ts.tmpl +300 -0
  31. package/recipes/runtimes/azure-foundry/code/{{PKG}}/main.ts.tmpl +196 -0
  32. package/recipes/runtimes/azure-foundry/code/{{PKG}}/mcpMain.ts.tmpl +562 -0
  33. package/recipes/runtimes/azure-foundry/code/{{PKG}}/model.ts.tmpl +117 -0
  34. package/recipes/runtimes/azure-foundry/code/{{PKG}}/tools.ts.tmpl +157 -0
  35. package/recipes/runtimes/azure-foundry/recipe.toml +88 -0
  36. package/recipes/tools-chain/code/{{PKG}}/chainTools.ts.tmpl +166 -0
  37. package/recipes/tools-chain/recipe.toml +11 -0
  38. package/recipes/wallet/recipe.toml +20 -0
  39. package/recipes/x402-buyer/code/{{PKG}}/x402Buyer.ts.tmpl +175 -0
  40. package/recipes/x402-buyer/recipe.toml +15 -0
  41. package/skills/bnbagent-studio.md +107 -0
  42. package/skills/references/bnbagent-studio-adding-to-project.md +241 -0
  43. package/skills/references/bnbagent-studio-buying-from-bazaar.md +169 -0
  44. package/skills/references/bnbagent-studio-buying-via-8183.md +222 -0
  45. package/skills/references/bnbagent-studio-extending-signing.md +227 -0
  46. package/skills/references/bnbagent-studio-operating.md +211 -0
  47. package/skills/references/bnbagent-studio-scaffolding-agent.md +536 -0
  48. package/skills/references/bnbagent-studio-selling-via-8183.md +271 -0
  49. package/skills/references/bnbagent-studio-selling-via-b402.md +194 -0
  50. package/skills/references/bnbagent-studio-use-aws-agentcore.md +208 -0
  51. package/skills/references/bnbagent-studio-use-azure-foundry.md +164 -0
  52. package/skills/references/bnbagent-studio-use-bnb-trial.md +92 -0
  53. package/skills/references/bnbagent-studio-using-altana-wallet.md +68 -0
  54. package/skills/references/bnbagent-studio-using-twak-wallet.md +260 -0
  55. package/skills/references/bnbagent-studio-wiring-llm-tools.md +338 -0
@@ -0,0 +1,536 @@
1
+ ---
2
+ name: bnbagent-studio-scaffolding-agent
3
+ description: When the user wants to create a brand-new blockchain SELLER from zero — a single valuable Agent on AWS Bedrock AgentCore that serves A2A by default or MCP optionally, holds the key, and signs in-process — earning $U on BNB Chain via ERC-8004 + ERC-8183 + x402. Drives the full intake → todo-list → execute flow.
4
+ ---
5
+
6
+ > **Reference file** of the `bnbagent-studio` router skill — installed at `bnbagent-studio/references/` and loaded on demand (not a standalone skill). Route here via the router's decision tree.
7
+
8
+ # bnbagent-studio-scaffolding-agent
9
+
10
+ Procedure for **greenfield** seller creation. Audience: Claude Code (or another
11
+ agent) running in an empty directory with shell + edit access.
12
+
13
+ **Different from** the `bnbagent-studio-adding-to-project.md` reference (in this same references/ directory): that one adds to an existing
14
+ repo; this one creates from zero.
15
+
16
+ ## The single seller runtime (v0.0.1 workspace layout)
17
+
18
+ `bag init` scaffolds a **blockchain seller** as a thin workspace root containing
19
+ **one sub-project** under `app/agent/`:
20
+
21
+ ```
22
+ <name>/ workspace root (thin wrapper / deploy anchor)
23
+ ├── package.json workspace root marker (private)
24
+ ├── pnpm-workspace.yaml packages: ["app/agent"]
25
+ ├── README.md 1-page pointer at app/agent/
26
+ ├── .gitignore
27
+ ├── agentcore/ AgentCore config dir (SELF-RENDERED by `bag init`;
28
+ │ │ names the deploy + drives `bag dev --container`)
29
+ │ ├── agentcore.json deploy descriptor (one native protocol + authorizerConfiguration)
30
+ │ └── aws-targets.json AWS account + region
31
+ ├── .studio/wallets/ evm-local keystore — Agent SOLE reader; at the WORKSPACE
32
+ │ root, OUTSIDE the codeLocation (no packaging path can bundle
33
+ │ it). twak instead keeps its mnemonic at ~/.twak (or
34
+ │ .studio/twak/ when project-dedicated)
35
+ └── app/
36
+ └── agent/ the single sub-project — the seller agent
37
+ ├── package.json @bnbagent/studio-runtime + @bnbagent/sdk + ai (AI SDK)
38
+ │ + protocol deps (A2A: @a2a-js/sdk + express;
39
+ │ MCP: @modelcontextprotocol/sdk)
40
+ ├── tsconfig.json builds src/ → dist/ (the deployed entrypoint is dist/*.js)
41
+ ├── studio.toml wallet / llm / budget / payments.erc8183 bounds / payments.x402 / storage
42
+ ├── .env.local TWAK_WALLET_PASSWORD (twak) / WALLET_PASSWORD (evm-local), PIEVERSE_LLM_API_KEY, STORAGE_API_URL/_KEY (IPFS pinning)
43
+ ├── Dockerfile container deploy path (twak wallet kind)
44
+ └── src/ main.ts / mcpMain.ts / dualMain.ts / sellerCore.ts / executor.ts / agentCard.ts / signing.ts / tools.ts / model.ts
45
+ ```
46
+
47
+ - **The Agent (`<name>/app/agent/`, → AWS Bedrock AgentCore).** ONE valuable agent
48
+ (memory / tools / skills / KB / LLM) that **serves the selected faces**
49
+ (A2A: `0.0.0.0:9000`; MCP: `0.0.0.0:8000/mcp`; A2A+MCP:
50
+ A2A-native `dualMain.ts` on `:9000` with `/mcp` tunneled), holds the key, and
51
+ signs **in-process**. Its outward surface is two fixed-code commerce
52
+ operations (A2A skills on `SellerAgentExecutor`, or MCP tools on the MCP
53
+ server):
54
+ - **`negotiate`** → rule-based list price CLAMPED to `[min,max]` →
55
+ `signing.ts` `signQuote` EIP-191 sign. **No LLM.**
56
+ - **`notify_funded`** → `signing.ts` `verifySignedJob` (synchronous) → delivery:
57
+ A2A ACKs then runs LLM work + `signing.ts` `submitResult` in the background
58
+ (plus a best-effort in-process sweep of other FUNDED jobs); MCP runs the work
59
+ and submit synchronously inside the tool call.
60
+
61
+ ALL signing is fixed `app/agent/src/signing.ts` code, **never** an LLM tool — the LLM
62
+ gets read-only chain tools only. The keystore lives at the **workspace root**
63
+ `.studio/wallets/` (outside the `app/agent/` codeLocation) and is injected at
64
+ deploy via AWS Secrets Manager — see Step 3 and Stage 4.
65
+
66
+ There is **no** second service, **no** keyless EC2 host, **no** `InvokeAgentRuntime`
67
+ relay, and **no** background poller. The agent is its own public surface.
68
+
69
+ v1 is **seller-only**; chat / buyer roles are deferred to v2. (A studio agent can
70
+ still *buy* other agents' 8183 services via `bag erc8183 buy/fetch/...`, but the
71
+ buyer flow is not yet productized.)
72
+
73
+ ## Preconditions
74
+
75
+ - Node.js ≥22 available.
76
+ - `bnbagent-studio` (the CLI) installed — `npm install -g @bnbagent/studio-cli`
77
+ (auto-pulls the `@bnbagent/studio-runtime` lib); for local dev use a monorepo
78
+ clone (`pnpm install` at the workspace root). `bag --version` works.
79
+ - `bag skills install` was run so this skill is loaded.
80
+ - **Bun 1.3+ (`bunx`) — needed for `bag deploy`, NOT for `bag init`.**
81
+ Deploys delegate ALL cloud execution to the pinned `@bnbagent/deploy-cli`,
82
+ run via `bunx --bun` (override with `BNBAGENT_DEPLOY_COMMAND`); `bag deploy
83
+ prepare` fails a CRITICAL check when `bunx` is missing. The npm
84
+ `@aws/agentcore` CLI is needed ONLY for `bag dev --container` (image-parity
85
+ local runs) — if installed, ensure the `agentcore` that resolves first on
86
+ PATH is that npm CLI, not the incompatible
87
+ `bedrock-agentcore-starter-toolkit` shim some environments carry.
88
+ (Node ≥22 and `bag` itself are NOT re-checked in the flow: running the CLI
89
+ already required Node, and this skill only runs because `bag` is installed.)
90
+ - **Permission prompts on `bag` calls are normal — do not try to remove them.**
91
+ The IDE asking the user to confirm each `bag` command is the expected flow;
92
+ whether to allowlist anything is the user's own decision, made in their own
93
+ settings UI/file. NEVER edit permission settings yourself, NEVER run
94
+ `claude config` (or any equivalent) to grant yourself permissions, and do
95
+ not ask the user to pre-authorize `bag` — `bag:*` includes money-spending
96
+ commands (deploy, erc8183 buy/settle), so a blanket grant is unsafe.
97
+ - Current working directory is where the project should live. The project is
98
+ created at `<cwd>/<name>/` — pick the parent before triggering this skill.
99
+
100
+ ## Stage 1 — Intake (collect ALL answers in one round, then echo back)
101
+
102
+ **Do not ask one question at a time.** Present the full form in a single
103
+ message, with defaults pre-filled. Accept the user's reply (which may be just
104
+ "go with defaults" or selective overrides), then echo a confirmation block and
105
+ proceed. This matches a shell-style prompt — one round-trip, then execute.
106
+
107
+ The fields (give the user all of them at once):
108
+
109
+ | # | Field | Options | Default |
110
+ |---|---|---|---|
111
+ | 1 | **Project name** | **Must start with a letter; ≤23 chars after sanitizing.** AgentCore runtime names are ASCII-alphanumeric-only — `bag init` **auto-sanitizes the charset** (drops `-`/`_`, so `news-agent` → `newsagent`, and prints the name it used), but it does **NOT** auto-shorten: a name whose alphanumeric form exceeds 23 chars errors out (pick a shorter one). The sanitized name becomes the dir name AND the AgentCore runtime name, so prefer a clean alphanumeric name up front. e.g. `newsagent`, `twcopywriter` | (required) |
112
+ | 2 | **Network** | `bsc-testnet` / `bsc-mainnet` | `bsc-testnet` |
113
+ | 3 | **LLM provider** | `pieverse-llm` / `openrouter` / `openai` / `anthropic` / `bedrock` | `pieverse-llm` |
114
+ | 4 | **Wallet kind** (`--wallet-kind`) | `evm-local` (encrypted local keystore at the workspace root; `bag wallet new` creates it, `--private-key` imports an existing key; CodeZip deploy) / `twak` (**fully supported, opt in with `--wallet-kind twak`** — Trust Wallet Agent Kit CLI ≥0.20.0, self-custody encrypted mnemonic in a **project-dedicated** home `.studio/twak`, isolated from your main `~/.twak`; created manually with `HOME=<ws>/.studio/twak twak wallet create`, then `bag wallet new` adopts; container deploy. Reuse an existing wallet across agents with `--twak-home <path>`) | `evm-local` |
115
+ | 5 | **Storage** | `local` (file:// on disk, offline dev only, does **NOT** survive deploy) / `ipfs` (durable, public, deploy-ready; needs your pinning service's upload endpoint + write key as `STORAGE_API_URL` / `STORAGE_API_KEY` in `.studio/.env.local` **before the first real delivery** — see Step 6b) | `local` |
116
+ | 6 | **Protocol faces** (`--protocols`) | any non-empty subset of `A2A`, `MCP`, `X402` | `A2A` |
117
+ | 7 | **LLM model** | provider catalogue; for `pieverse-llm` the default `auto/free` runs at $0/token | `auto/free` |
118
+ | 8 | **Auto-topup** | `enable` / `disable` — lets the Agent auto-pay $U from the wallet when LLM credits run low | deferred (non-interactive `bag init` records no `[budget]`; enable later with `bag budget enable`) |
119
+ | 9 | **Scaffold destination** (`--destination`) | `self` (prepare the AgentCore scaffold for **your own** AWS account; runtime material stays under your cloud-account control) / `platform` (prepare for a 48h **testnet-only** trial on the BNB Chain managed platform — runs the *same* agent in the **operator's** AWS, so a wallet key **leaves your control**; it hard-forces `[network].default = bsc-testnet`, pins runtime=`agentcore`, packages an artifact, and auth is GitHub device flow. Use a **throwaway** `bag wallet new`, never your main wallet). This is scaffold intent only; deploy still explicitly selects `--provider`. | `platform` while the trial campaign runs (bare init falls back to `self` once it ends, or when `--network bsc-mainnet` / a non-agentcore `--runtime` is passed) |
120
+
121
+ v1 is **seller-only** — there is no role to choose. `bag init` scaffolds the
122
+ single seller agent under `app/agent/` (serves the selected public faces,
123
+ sole signer).
124
+ Chat / buyer roles are deferred to v2.
125
+
126
+ **Architecture selections** (stack/runtime are fixed in v0.0.1; protocol is selected above).
127
+ **Render these as their own visible table in the intake form**, right after the
128
+ fields above — do NOT compress them to a one-line footnote: they are part of
129
+ the config the user is confirming, and "where's A2A / the runtime?" is a real
130
+ question. Each row: Field | Value | What it is.
131
+
132
+ | Field | Value | What it is |
133
+ |---|---|---|
134
+ | **Agent stack** | AI SDK (`ai`) | The library the agent's brain is built with — the emitted `src/model.ts` factory returns an AI SDK `LanguageModel`, and `src/tools.ts` wraps the chain reads as AI SDK `tool()`s. (There is no `--framework` flag: the old framework axis folded into the runtime templates.) |
135
+ | **Runtime** | `agentcore` | AWS Bedrock AgentCore — where the agent is hosted and served (`--runtime agentcore`). |
136
+ | **Protocol faces** | selected above (`A2A` default; MCP/X402 composable) | A2A hosts agent card + JSON-RPC on `:9000`; MCP-only hosts `/mcp` on `:8000`; A2A+MCP uses A2A-native `dualMain.ts` on `:9000` and tunnels buffered MCP through the platform; X402 adds `/x402`, and X402-only suppresses protocol discovery. |
137
+
138
+ **Not surfaced** (handled automatically, no need to show or ask):
139
+ - **Dependency install** — on by default (`bag init` runs the package install
140
+ for the workspace unless `--no-install`).
141
+ - **IDE skill target** — auto-detected (`--ide`), falls back to `claude-code`.
142
+
143
+ The following are auto-included by default (don't ask, just mention in the confirmation block):
144
+ - **Read-only chain tools** wired into the Agent's LLM (`app/agent/src/tools.ts`) — the LLM
145
+ can query wallet / balances / ERC-8004 / ERC-8183 state but **never signs**.
146
+ - **LLM-credit auto-renew** via the emitted `app/agent/src/model.ts` — the
147
+ Agent's `buildModel()` factory (in user-owned code) returns an AI SDK
148
+ `LanguageModel` wrapped (via `wrapLanguageModel` middleware) with an
149
+ **automatic, budget-gated auto-renew hook** that tops up the active Pieverse
150
+ key before an LLM call when the cached balance is below the floor. The
151
+ stack-neutral credit-ensurer logic lives in
152
+ `@bnbagent/studio-runtime/pieverse` (`PieverseCreditEnsurer`); the AI-SDK
153
+ shell is in the emitted `app/agent/src/model.ts`. This is the ONLY automatic
154
+ signing path outside `signing.ts`; it rides on the hardened x402 buyer
155
+ kernel (`@bnbagent/studio-runtime/x402`) but is **not an LLM tool** — the
156
+ Agent (the sole key-holder) does it transparently inside the model wrapper.
157
+ If the budget gate is off / exhausted, the hook raises
158
+ `PieverseAccountBalanceExhaustedError` pointing at `bag llm topup --amount N`.
159
+ Opt out via `[llm.auto_renew].enabled = false`.
160
+
161
+ Also collect, if natural to gather: a one-sentence description of what the
162
+ agent does (used in the agent's instruction prompt and, later, in
163
+ ERC-8004 metadata when the user runs `bag deploy verify`).
164
+
165
+ After collecting, **echo back** a confirmation block like:
166
+
167
+ ```
168
+ Will create (single seller agent):
169
+ name: newsagent (≤23 chars, alphanumeric, letter-start — AgentCore rule)
170
+ agent: app/agent/ (AgentCore, --protocols <faces>, sole signer, signs in-process)
171
+ network: bsc-testnet
172
+ llm: pieverse-llm (model: auto/free, auto-renew enabled)
173
+ wallet: evm-local — encrypted keystore at the workspace root (.studio/wallets/)
174
+ (twak is fully supported too — opt in with --wallet-kind twak)
175
+ storage: local (offline dev; switch to ipfs — needs a pinning endpoint + key — before deploy)
176
+ fixed: stack=AI SDK (model factory + tools), runtime=agentcore (AWS Bedrock AgentCore)
177
+ protocol: A2A (src/main.ts on 0.0.0.0:9000; local 127.0.0.1:9000)
178
+ or MCP (src/mcpMain.ts on 0.0.0.0:8000/mcp; local localhost:8000/mcp)
179
+ destination: platform (campaign default while the trial runs — 48h testnet on the operator's AWS; key leaves your machine, use a throwaway wallet)
180
+ or self (prepare for your own AWS Bedrock AgentCore; runtime material stays in your account — pass --destination self)
181
+ extras: read-only chain tools wired into the Agent LLM
182
+ location: /Users/.../newsagent/
183
+
184
+ Proceeding in 3 commands… (interrupt now if anything's off)
185
+ ```
186
+
187
+ Then execute Stage 2 **without further prompts** until you hit a step that
188
+ genuinely requires user action (funding the wallet).
189
+
190
+ ## Stage 2 — Generate a todo list (visible to the user)
191
+
192
+ Build a TodoWrite list. The shape depends on the `wallet kind`. The
193
+ canonical 8-step layout (evm-local default, Pieverse default LLM; plus a conditional
194
+ Step 6b when `storage=ipfs`):
195
+
196
+ > **Step 0 — Pre-flight (informational; do NOT block `bag init` on it).**
197
+ > `bag init` self-renders the `agentcore/` deploy descriptor, and deploys
198
+ > delegate to the pinned `@bnbagent/deploy-cli` run via `bunx`, so Bun is only
199
+ > needed later, at `bag deploy` time. Do **not** re-check Node or `bag` (both
200
+ > are necessarily present — running the CLI required Node, and this skill only
201
+ > loads because `bag` is installed).
202
+ > ```bash
203
+ > command -v bunx >/dev/null || echo "bunx not found — OK for init; install Bun 1.3+ before deploy: https://bun.sh"
204
+ > ```
205
+ > If Bun is missing at deploy time, **PAUSE** and have the USER install it
206
+ > (Bun 1.3+, or set `BNBAGENT_DEPLOY_COMMAND`). Likewise for `bag dev
207
+ > --container` only: the npm `@aws/agentcore` CLI must be present and must win
208
+ > on PATH over the incompatible `bedrock-agentcore-starter-toolkit` shim —
209
+ > global tools on the user's machine, so the user installs them, not you.
210
+
211
+ > **Onboarding note.** On a human TTY, `bag init` runs steps 3, 4 and 6
212
+ > automatically (it prompts once for the wallet password, runs `bag wallet
213
+ > new`, zero-deposit-activates Pieverse, and prints faucet URLs). **You (Claude
214
+ > Code) drive `bag init` non-interactively**, so that auto-flow does NOT fire —
215
+ > keep steps 3/4/6 below. Pass `--no-onboard` to `bag init` to make this
216
+ > explicit and deterministic regardless of how the shell wires stdin.
217
+
218
+ 1. `bag init <name> --llm-provider <p> --network <n> --storage-provider <s> --wallet-kind <k> --no-onboard`
219
+ — scaffold the v0.0.1 workspace. **`<name>` must start with a letter and be
220
+ ≤23 chars after sanitizing** — `bag init` auto-drops `-`/`_` for the
221
+ AgentCore name (printing what it used) but errors if the alphanumeric form
222
+ is >23 chars; prefer a clean alphanumeric name from Stage 1. Pass
223
+ `--wallet-kind evm-local` (default) or `--wallet-kind twak` (twak is fully
224
+ supported — pass the flag to opt in), and `--storage-provider local`
225
+ (default) or `ipfs`, per the Stage-1 choices; for twak, add
226
+ `--twak-home <path>` ONLY if the user wants to reuse an existing wallet
227
+ (otherwise omit — a project-dedicated `.studio/twak` is the safe default).
228
+ add `--protocols <comma-list>` when the user chose non-default or multiple
229
+ faces (omit for A2A default; `--protocol <one>` is only a legacy alias), add
230
+ `--model <m>` only if the user overrode the provider default, and
231
+ `--enable-auto-topup` / `--no-auto-topup` only if they made an explicit
232
+ choice (otherwise omit — consent stays deferred). **Destination:** while the
233
+ trial campaign runs, bare `bag init` (no `--destination`) defaults to
234
+ `platform` — so pass `--destination self` **explicitly** whenever the user
235
+ chose their own AWS, otherwise studio.toml silently records `platform` and the
236
+ confirmation block you echoed no longer matches what was written. Omit
237
+ `--destination` only when the user actually wants the `platform` 48h testnet
238
+ trial (the campaign default) — do NOT treat that default as a mistake or
239
+ re-confirm it; it is the intended behavior while the campaign is open. (Bare
240
+ init also resolves to `self` once the campaign ends, or when `--network
241
+ bsc-mainnet` / a non-agentcore `--runtime` is passed.) On the `platform` path
242
+ `bag init` hard-forces `bsc-testnet`, pins `--runtime agentcore` + packages an
243
+ artifact (a zip for the default evm-local wallet, a container for twak), and a
244
+ wallet key will later leave your machine, so pair it with a throwaway
245
+ `bag wallet new` (full flow: `docs/guides/platform-deploy.md`). Defaults
246
+ `--runtime agentcore` (the only self-deploy runtime in v0.0.1; there is no
247
+ `--framework` flag — the AI SDK model/tools story is part of the runtime
248
+ templates). Creates `<name>/` workspace root + `<name>/app/agent/` (the
249
+ single sub-project: A2A emits `src/main.ts` (the express + A2A entrypoint) +
250
+ `src/sellerCore.ts` (the protocol-neutral core; executor inherits it) +
251
+ `src/executor.ts` + `src/agentCard.ts`; MCP emits `src/mcpMain.ts`;
252
+ both include `src/signing.ts` + `src/tools.ts` + `src/model.ts` +
253
+ `Dockerfile` + own `studio.toml` + `.env.local` + `package.json` +
254
+ `tsconfig.json`) + `<name>/agentcore/` (`agentcore.json` +
255
+ `aws-targets.json`, self-rendered — no agentcore CLI needed at init). The
256
+ workspace root holds the `agentcore/` deploy descriptor, the
257
+ `.studio/wallets/` keystore, a thin `package.json` + `pnpm-workspace.yaml`,
258
+ README, and `.gitignore`. (v1 is seller-only — no `--role`.)
259
+ 2. `cd <name>`, then make sure the dependencies are installed. `bag init`
260
+ already runs the install by default (skip only if it was scaffolded with
261
+ `--no-install`); the manual equivalent from the workspace root is:
262
+ ```bash
263
+ pnpm install # npm install works too — tooling is the user's choice
264
+ ```
265
+ The sub-project's `package.json` carries its deps:
266
+ `@bnbagent/studio-runtime` (the runtime lib, pinned to the scaffolding
267
+ CLI's version range — NOT the CLI itself) + `@bnbagent/sdk` + `ai` (the AI
268
+ SDK) plus the **protocol-specific** group — A2A adds `@a2a-js/sdk` +
269
+ `express`, MCP adds `@modelcontextprotocol/sdk` instead (an A2A-only deploy
270
+ never ships the MCP SDK, and an MCP-only deploy never ships the A2A one).
271
+ For local dev against unreleased libs, `bag init` vendors local `.tgz`
272
+ tarballs and points the manifest at them automatically.
273
+ 3. **Set the wallet password** — the USER does this, NOT you.
274
+
275
+ 🔒 **SECURITY — never route the wallet password through the chat.** It
276
+ encrypts the key material that is the Agent's sole signing key. Do **NOT**
277
+ ask the user to type it into the chat, and do **NOT** run any command with
278
+ the password on the command line (`bag env set <PW_VAR> <literal>`,
279
+ `twak wallet create --password <literal>`, …) — it would land in the
280
+ session transcript, be sent to the model API, and hit shell history / `ps`.
281
+
282
+ Tell the user to set it **themselves, in their own terminal**, so it never
283
+ reaches you. The env var depends on the wallet kind:
284
+ - **twak** → `TWAK_WALLET_PASSWORD` (the twak CLI reads it itself)
285
+ - **evm-local** → `WALLET_PASSWORD`
286
+ ```bash
287
+ # In YOUR OWN terminal (not via the agent): open .studio/.env.local and
288
+ # set the line for your wallet kind:
289
+ # TWAK_WALLET_PASSWORD=<a strong password you choose> # twak
290
+ # WALLET_PASSWORD=<a strong password you choose> # evm-local
291
+ # Save it. Do not paste the password into this chat.
292
+ ```
293
+ `bag` auto-loads `.studio/.env.local` (resolved via the project root), so once
294
+ the line is set you do NOT need to `source` it or `cd` anywhere special —
295
+ `bag wallet new` / `bag llm activate` will read it. Wait for the user to
296
+ confirm they've set it before continuing.
297
+ 4. **Create / adopt the wallet** — depends on the wallet kind:
298
+ - **twak** (fully supported — opt in with `--wallet-kind twak`): `bag init` writes `[wallet].twak_home =
299
+ "../../.studio/twak"` — a **project-dedicated** wallet isolated from your
300
+ main `~/.twak`, so a deploy never pushes the main wallet's key material to
301
+ Secrets Manager. The user creates it ONCE themselves — the twak CLI forces
302
+ the password onto argv (upstream S-8), so studio never runs it — in their
303
+ own terminal:
304
+ own terminal — the 3-step `twak setup` wizard:
305
+ ```bash
306
+ HOME=<workspace>/.studio/twak twak setup
307
+ ```
308
+ **Tell the user exactly what to pick at each wizard step** — it is not
309
+ obvious and a wrong pick is dangerous:
310
+ - **Step 1 (API credentials):** paste Access ID + HMAC secret from
311
+ https://portal.trustwallet.com/dashboard/apps; WalletConnect Project ID →
312
+ leave blank, ENTER.
313
+ - **Step 2 (wire up harnesses): SELECT NONE, press ENTER** (don't press
314
+ SPACE/`a`) — never wire twak's signing MCP into Claude Code / Cursor /
315
+ etc.; studio keeps signing in fixed code, not MCP.
316
+ - **Step 3 (wallet): pick `3) Skip for now`**, then create the wallet with
317
+ the standalone command below. (`1) Create a new agent wallet` persists the
318
+ password via the OS keychain, which fails on keychain-less environments —
319
+ "OS keychain cannot persist passwords here … headless / Docker" — and
320
+ studio unlocks via `TWAK_WALLET_PASSWORD` env anyway. NEVER pick `2) Use
321
+ WalletConnect` = your main wallet.)
322
+
323
+ ```bash
324
+ HOME=<workspace>/.studio/twak twak wallet create --password <StrongPw> --no-keychain # UPPER + lower + digit
325
+ ```
326
+ Use UPPER + lower + digit; put that same password in `.studio/.env.local`
327
+ as `TWAK_WALLET_PASSWORD`. `--no-keychain` keeps the password out of the OS
328
+ keychain (no macOS prompt); studio unlocks via the env. (If you omit it and a
329
+ macOS prompt *loops*, do NOT "Reset Default Keychain" — `pkill -9 -f twak`,
330
+ then re-run with `--no-keychain`.) Full detail: the
331
+ `bnbagent-studio-using-twak-wallet.md` reference (in the router skill's `references/` directory).
332
+ Then YOU run `bag wallet new`, which **adopts** the address into
333
+ `studio.toml` (and echoes it — confirm it's the intended wallet before
334
+ funding/deploy). To reuse an EXISTING wallet across agents, scaffold with
335
+ `bag init --twak-home <path-to-its-home>` instead. Reusing your main
336
+ `~/.twak` is opt-in only (`--twak-home ~`) and discouraged. Full detail:
337
+ the `bnbagent-studio-using-twak-wallet.md` reference (in the router skill's `references/` directory).
338
+ - **evm-local** (default): `bag wallet new` creates the encrypted keystore. To import
339
+ an existing key, the user pastes it and you immediately run
340
+ `bag wallet new --private-key <pk>` (the key is written only into the
341
+ keystore, nowhere else on disk).
342
+ 5. **Fund the wallet — OPTIONAL; do NOT block on it.** The default `auto/free`
343
+ LLM model runs at $0 and AgentCore deploy consumes no wallet balance, so a
344
+ brand-new seller can scaffold, run `bag dev`, and deploy with an empty
345
+ wallet. `bag doctor` and `bag deploy` only **WARN** (never block) on zero
346
+ balance. Funding is needed later only for: a paid LLM model, on-chain
347
+ settle, or paying ERC-8183 job buys. When that time comes, the wallet uses
348
+ **TWO distinct U balances on TWO chains** (same wallet address, same private
349
+ key, different chains):
350
+
351
+ - **tBNB (gas)** on BSC testnet: https://testnet.bnbchain.org/faucet-smart
352
+ — paste address
353
+ - **BSC mainnet U** (`0xcE24439F2D9C6a2289F741120FE202248B666666`) — for
354
+ Pieverse LLM topup. Minimum **0.2 U** recommended (0.1 for activate +
355
+ slack). Pieverse runs **only on mainnet chainId=56**; testnet U cannot
356
+ pay for LLM credits. Acquire via PancakeSwap. v0.0.1 does NOT
357
+ auto-refill from wallet — keep refilling Account Balance with
358
+ `bag llm topup` as you use credits.
359
+ - **BSC testnet U** (`0xc70B8741B8B07A6d61E54fd4B20f22Fa648E5565`) — for
360
+ ERC-8183 job payments if `[network].default = bsc-testnet`. Faucet:
361
+ https://united-coin-u.github.io/u-faucet/ (paste the agent wallet
362
+ address; see also `docs/guides/U-token-testnet.md`).
363
+
364
+ Both U balances live in the **same agent wallet** — one address, same
365
+ private key — just on different chains. Verify both with
366
+ `bag wallet balance --all`.
367
+ 6. **Activate Pieverse LLM** (only if `llm=pieverse-llm`, default): `bag llm
368
+ activate` — **zero-deposit by default** (`--initial-usd` defaults to 0).
369
+ SIWE-logs in with the agent wallet (an off-chain EIP-191 signature — no gas,
370
+ no U), creates an `sk-pv-...` key with a $0 allocation, and writes
371
+ `PIEVERSE_LLM_API_KEY` to `.env.local` + `key_hash` to studio.toml. The
372
+ default model `auto/free` runs at $0/token, so **no funding is required to
373
+ start**. Only when you switch to a paid model do you fund the wallet and run
374
+ `bag llm topup --amount N` (then `[llm.auto_renew]` auto-**allocates** from
375
+ your Pieverse Account Balance to the key below the floor; v0.0.1 never
376
+ auto-spends wallet U). For non-Pieverse providers, manually set the API key
377
+ env var instead.
378
+
379
+ **Step 6b — Set the IPFS pinning credentials** (only when the user chose
380
+ `storage=ipfs`; `bag init` defaults to `local`). With `--storage-provider
381
+ ipfs` the Agent pins each deliverable to IPFS at delivery and publishes
382
+ `ipfs://CID` on-chain (durable, public, deploy-ready). Works with **any** IPFS
383
+ pinning service or a self-hosted node:
384
+
385
+ > Pick a pinning service and create a write key/JWT in its console (or run
386
+ > your own IPFS node — its `/api/v0/add` endpoint usually needs no key),
387
+ > then:
388
+ > ```bash
389
+ > bag env set STORAGE_API_URL <your-service-upload-endpoint>
390
+ > bag env set STORAGE_API_KEY <your-write-key>
391
+ > ```
392
+ > Written to `.studio/.env.local`. **OPTIONAL to start** (scaffold, `bag
393
+ > dev`, and deploy all work without them) but **required before the first
394
+ > real delivery submits on-chain** — without them the Agent can't pin to
395
+ > IPFS and delivery fails. You can also pass `--ipfs-key <key>` to `bag
396
+ > init` upfront. `bag doctor` WARNs (never blocks) while they're unset. For
397
+ > pure offline dev with no IPFS, scaffold with `--storage-provider local`
398
+ > instead (writes `STORAGE_LOCAL_PATH`, no key — but does NOT survive
399
+ > deploy: the deployed agent and your dev box don't share a filesystem).
400
+ 7. **Recipe code is already emitted by `bag init`** — the `app/agent/`
401
+ sub-project plus its `studio.toml` is written by step 1, so **skip manual
402
+ recipe emission**. To re-emit or inspect a recipe later, `bag recipe code
403
+ agent` / `bag recipe code runtimes/agentcore` (emits under `{{PKG}}` = the
404
+ agent's `src/` dir; pass `--pkg <name>` to override). The real work is
405
+ editing the Agent's `runWork` hook in `app/agent/src/sellerCore.ts` (A2A) /
406
+ `app/agent/src/mcpMain.ts` (MCP) (see `bnbagent-studio-selling-via-8183.md` in this same directory).
407
+ 8. **Verify**: `bag doctor` — confirms the scaffold + Pieverse key activation
408
+ (if applicable) + config. Zero BNB / U are **WARN only** (not failures) —
409
+ funding is optional (see step 5), so do NOT refuse to continue on a balance
410
+ warning. Only refuse on real FAILs (missing keystore, unparseable config,
411
+ etc.).
412
+
413
+ **Do not** register ERC-8004 identity at this stage — it needs the deployed
414
+ agent's public AgentCore endpoint, so it happens **last** at deploy time
415
+ (`bag deploy verify`). Telling the user upfront:
416
+
417
+ > ERC-8004 on-chain identity registers at deploy time with your agent's public
418
+ > AgentCore endpoint (A2A card URL or MCP `/mcp` URL + access metadata). Skipped
419
+ > now so you don't burn gas before you know whether you'll ship this seller.
420
+
421
+ ERC-8183 service publishing is also a deploy-time concern — defer it.
422
+
423
+ Present the todo list to the user; ask "is this OK or do you want me to add/remove steps?"
424
+ **only if** the wallet kind is unusual (e.g. `evm-local` with a key import, or
425
+ `twak`). For the `evm-local` default, skip the confirmation and execute.
426
+
427
+ ## Stage 3 — Execute step by step
428
+
429
+ For each todo item:
430
+
431
+ - Mark `in_progress` before running
432
+ - Run the command via shell (or Edit/Write for code changes)
433
+ - Show the user the output
434
+ - Mark `completed` when done
435
+
436
+ **Stop and ask the user** at:
437
+
438
+ - Step 3 (password): the USER sets it **themselves, in their own terminal** —
439
+ never through the chat or on a command line (see Step 3's security note). They
440
+ edit `.studio/.env.local` and set `TWAK_WALLET_PASSWORD` (twak) or
441
+ `WALLET_PASSWORD` (evm-local). `bag` auto-loads that file, so once it's set
442
+ `bag wallet new` / `bag llm activate` pick it up — no `source`/`cd` needed.
443
+ Wait for the user to confirm before continuing.
444
+ - Step 5 (funding): OPTIONAL — only stop here if the user explicitly wants a paid LLM model, on-chain settle, or to pay ERC-8183 buys now. Otherwise skip; the `auto/free` default needs no funds.
445
+ - Step 6 (Pieverse activation): zero-deposit, so it just works — no funding precheck needed. If `bag llm activate` fails on connectivity, retry once.
446
+ - Step 6b (IPFS credentials): only when `storage=ipfs`. OPTIONAL now — do NOT block; the user picks a pinning service and runs `bag env set STORAGE_API_URL <url>` + `bag env set STORAGE_API_KEY <key>` themselves. Remind them they're required before the first real delivery (and `bag doctor` will keep WARNing until set). Skip entirely if they chose `local` storage.
447
+ - Business-logic step: ask the user what the Agent should produce when it delivers a job — the `runWork` hook in `app/agent/src/sellerCore.ts` (A2A) / `app/agent/src/mcpMain.ts` (MCP) is the developer hook. Leave the generic LLM passthrough stub if they don't know yet
448
+
449
+ **Never** ask the user to `echo "KEY=VALUE" >> .env.local`. Always call
450
+ `bag env set KEY VALUE` — it replaces the existing line if present, otherwise
451
+ appends, so it's safe to run repeatedly.
452
+
453
+ ## Stage 4 — Summary
454
+
455
+ After step 8 passes (doctor clean — Pieverse key activated; balances may be
456
+ 0 and that's fine), print:
457
+
458
+ ```
459
+ ✅ <name> ready for local development (single seller agent).
460
+
461
+ Wallet: <0x...>
462
+ Network: bsc-testnet
463
+ BNB bal: <X> tBNB
464
+ U bal: <Y> U
465
+
466
+ Local dev (from workspace root <name>/):
467
+ bag dev # A2A: local :9000; MCP: local :8000/mcp (same for any destination)
468
+ # (no Cognito env locally)
469
+ # For A2A, test with curl/A2A DataPart, NOT the
470
+ # AgentCore inspector chat box (it can't send a
471
+ # seller's skills). For MCP, use an MCP client.
472
+
473
+ When ready to deploy:
474
+ bag deploy provision-cognito # emit the Cognito CDK app — you run `cdk deploy`,
475
+ # then its discoveryUrl/clientId wire into the OAuth2 authorizer
476
+ bag deploy prepare # readiness sweep
477
+ bag deploy --provider aws # ship the Agent to AgentCore (selected faces);
478
+ # keystore injected via Secrets Manager (never in the CodeZip)
479
+ bag deploy verify --provider aws --endpoint <url> # delegated status + reconcile ERC-8004
480
+
481
+ Edit (from workspace root):
482
+ app/agent/src/sellerCore.ts or mcpMain.ts # the VALUE — implement the runWork hook (your work product)
483
+ app/agent/src/signing.ts # fixed signing code (clamp + sign); NOT LLM tools
484
+ app/agent/src/tools.ts # read-only chain tools the LLM may call
485
+ app/agent/src/agentCard.ts # A2A only: advertised card (2 skills + OAuth2 scheme)
486
+ app/agent/studio.toml # Agent config (LLM, [payments.erc8183] price clamp, [budget])
487
+ ```
488
+
489
+ ## Gotchas
490
+
491
+ - **U is 18 decimals** (not 6 like USDC). The `@bnbagent/studio-runtime/networks`
492
+ `toRaw`/`fromRaw` helpers handle this.
493
+ - **`buy_workflow`'s `deadline_minutes`** is the seller's *submission* window. The
494
+ on-chain job lifetime is automatically `deadline_minutes + 24h dispute_window`.
495
+ - **`bag init` runs wallet onboarding only on a human TTY** (evm-local: prompts
496
+ for the password and runs `bag wallet new`; twak: adopts the existing twak
497
+ wallet — never creates one, since `twak wallet create` puts the password on
498
+ argv). When **Claude Code** runs `bag init` (non-interactively, via the shell
499
+ tool) that auto-flow does NOT fire, so this skill drives Step 3/4 explicitly —
500
+ use `--no-onboard` to make the behavior deterministic. This skill bridges the
501
+ gap by collecting the wallet kind upfront and calling the right form.
502
+ - **The agent is the sole key-holder; the key material never enters the deploy
503
+ package.** For **evm-local** the encrypted keystore lives at the **workspace
504
+ root** `.studio/wallets/` (outside the `app/agent/` codeLocation, so no
505
+ packaging path can bundle it); for **twak**
506
+ the mnemonic lives at `~/.twak` (or `.studio/twak/`), never in the repo. Either
507
+ way it is injected at deploy via AWS Secrets Manager (default
508
+ `--secrets-mode secretsmanager`) — `WALLET_KEYSTORE_JSON` / `WALLET_PASSWORD`
509
+ for evm-local, `TWAK_WALLET_JSON` / `TWAK_CREDENTIALS_JSON` /
510
+ `TWAK_WALLET_PASSWORD` for twak — reconstructed at cold start, never in the
511
+ package; the testnet-only `--secrets-mode envvars` fallback is refused on
512
+ mainnet.
513
+ - **AgentCore seller endpoints are never anonymous.** With no authorizer the runtime defaults
514
+ to IAM/SigV4 (owner-only, NOT open); to serve **external** buyers configure the
515
+ Cognito OAuth2 authorizer — `bag deploy provision-cognito` emits a CDK app the
516
+ user `cdk deploy --outputs-file`s, then `provision-cognito --wire` patches
517
+ `agentcore.json` + the card env. `bag deploy prepare` warns (W9) if unset but
518
+ does NOT block. Locally, `bag dev` runs without Cognito env, so the card omits
519
+ the scheme and is reachable without a token.
520
+ - **ERC-8183 does NOT require ERC-8004** at the protocol level (commerce contract
521
+ doesn't check the identity registry). Local two-agent dev can run end-to-end
522
+ without ever touching 8004. Use 8004 only when you actually want discoverable
523
+ identity.
524
+ - **Seller code that needs `ERC8183JobOps` directly** should import the public
525
+ `import { ERC8183JobOps } from "@bnbagent/sdk/erc8183"` — the headless
526
+ funded-job lifecycle ops. `getPendingJobs()` returns FUNDED jobs assigned to
527
+ this provider (the basis for the executor's best-effort sweep).
528
+
529
+ ## Reference
530
+
531
+ - the `bnbagent-studio-using-twak-wallet.md` reference (in this same references/ directory) (the fully-supported `twak` wallet kind, opt in with `--wallet-kind twak`: setup / funding / SIWE / container deploy)
532
+ - `docs/design/single-seller-agent.md` (the v1 deploy model)
533
+ - `docs/design/erc8183-buyer-push.md` (negotiate → fund → notify_funded, the sweep)
534
+ - `docs/design/decisions.md` (single seller runtime + protocol faces; CLI vs skill responsibilities)
535
+ - `docs/design/architecture.md` §2.5 / §2.7 (the single seller runtime + workspace layout)
536
+ - `docs/guides/U-token-testnet.md` (how to obtain testnet U tokens)