@ancha-labs/cli 0.4.34 → 0.4.36
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.
- package/THIRD_PARTY_NOTICES.md +2 -0
- package/lib/ancha.mjs +36292 -31352
- package/lib/assets/docs/apps.md +33 -0
- package/lib/assets/docs/scenes.md +158 -0
- package/lib/assets/docs/tools.md +2 -0
- package/lib/assets/harbor/companion.mjs +24727 -20242
- package/lib/assets/templates/starter/oracle.mjs +1 -0
- package/lib/assets/ui/app.js +11 -5
- package/lib/engine-worker.mjs +70 -0
- package/lib/mcp-entry.mjs +1982 -1704
- package/lib/worker.mjs +29689 -24914
- package/lib/world-server.mjs +24572 -20108
- package/package.json +3 -2
package/lib/assets/docs/apps.md
CHANGED
|
@@ -56,6 +56,8 @@ agent:
|
|
|
56
56
|
|
|
57
57
|
Stripe, Shopify and Clerk webhooks go to an events URL that names `{{service}}`, as here; Stripe and Shopify also deliver to endpoints the app registers through their own API, and Clerk to endpoints added with `clerk.subscribe_webhook`.
|
|
58
58
|
|
|
59
|
+
Stripe webhook endpoints created with `connect: true` receive connected-account events such as `account.updated`, `capability.updated` and `payout.*`, with the account ID in the event's top-level `account` field. Other Stripe endpoints receive platform events, including destination-charge payments, refunds and disputes. Each registered endpoint signs with its own secret. The world's Stripe events URL receives both account and platform events, signed with `STRIPE_WEBHOOK_SECRET`; during a trial, matching registered endpoints take precedence over that URL.
|
|
60
|
+
|
|
59
61
|
Create a Checkout Session with a seeded price, then open its `url` and choose **Pay** or **Decline**. Set `seed.stripe.livemode: false` for these test-card buttons. A successful payment redirects to `success_url`, replacing `{CHECKOUT_SESSION_ID}`, and delivers `checkout.session.completed` alongside the payment and subscription events.
|
|
60
62
|
|
|
61
63
|
A scene can complete the latest open session for an email:
|
|
@@ -71,6 +73,37 @@ world_rules:
|
|
|
71
73
|
|
|
72
74
|
The harness can call the same `stripe.complete_checkout` action with `session` to select an exact session. Use `pm_card_chargeDeclined` to exercise failed payment. Subscriptions, trials and renewals follow the world clock. Change the customer's default payment method with `stripe.set_default_card` (`customer_email` or `customer`, and `card`) to test a failed renewal, recovery or cancellation.
|
|
73
75
|
|
|
76
|
+
Create an account link through `POST /v1/account_links` and open its `url` for the hosted Connect onboarding page. Express and Custom accounts use `type: account_onboarding`; Custom accounts also use `account_update`. Links are single use and expire after 5 minutes on the world clock: an expired or previously visited link redirects to `refresh_url`, where the app can create a fresh link. Submit the page's test identity and bank choice to collect requirements and begin capability review, then return to `return_url`. Leaving through the return link also reaches `return_url`; read the account's requirements and capabilities to determine its state.
|
|
77
|
+
|
|
78
|
+
## Supabase apps
|
|
79
|
+
|
|
80
|
+
Run `ancha connect supabase --lang ts` for the client setup. The app receives `SUPABASE_URL`, `SUPABASE_ANON_KEY`, `SUPABASE_SERVICE_ROLE_KEY`, `SUPABASE_PUBLISHABLE_KEY`, `SUPABASE_SECRET_KEY`, `SUPABASE_JWT_SECRET` and `SUPABASE_PROJECT_REF`. Server clients can use the service role key for administrative work. Use the anon or publishable key with the signed-in user's session for requests governed by row-level security.
|
|
81
|
+
|
|
82
|
+
Ancha also supplies the variables frontend frameworks read: `NEXT_PUBLIC_SUPABASE_URL`, `NEXT_PUBLIC_SUPABASE_ANON_KEY`, `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY`; `VITE_SUPABASE_URL`, `VITE_SUPABASE_ANON_KEY`, `VITE_SUPABASE_PUBLISHABLE_KEY`, `VITE_SUPABASE_PROJECT_ID`; and `EXPO_PUBLIC_SUPABASE_URL`, `EXPO_PUBLIC_SUPABASE_ANON_KEY`. Keep the app's existing environment-variable names and pass their values to `createClient`:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { createClient } from '@supabase/supabase-js';
|
|
86
|
+
|
|
87
|
+
const supabase = createClient(process.env.SUPABASE_URL!, process.env.SUPABASE_ANON_KEY!);
|
|
88
|
+
const { data, error } = await supabase.auth.signInWithOtp({
|
|
89
|
+
email: 'tom.reyes@harborview-dental.example',
|
|
90
|
+
});
|
|
91
|
+
if (error) throw error;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Read the email and code with `ancha world inbox`. For `seed.supabase.auth.email_otp: code`, pass that code to `supabase.auth.verifyOtp({ email, token: code, type: 'email' })`; for `link`, follow the captured sign-in link. Sign-up confirmations and password recovery messages also arrive in the inbox. The client keeps the returned session for Data API and private Storage calls.
|
|
95
|
+
|
|
96
|
+
The world loads the app's `supabase/migrations` and `supabase/seed.sql`. Add people, tenant rows and files with `seed.supabase`; see `ancha docs scenes` for a complete seed and checks. To call the app as a seeded user, give the app call `as`; Ancha creates the Supabase session and sends its bearer token:
|
|
97
|
+
|
|
98
|
+
```yaml
|
|
99
|
+
world_rules:
|
|
100
|
+
app_calls:
|
|
101
|
+
- at: 5s
|
|
102
|
+
method: GET
|
|
103
|
+
path: /api/documents
|
|
104
|
+
as: { supabase: tom.reyes@harborview-dental.example }
|
|
105
|
+
```
|
|
106
|
+
|
|
74
107
|
## Clerk sign-in
|
|
75
108
|
|
|
76
109
|
Run `ancha connect clerk --lang ts` for the SDK configuration. The app receives `CLERK_API_URL`, `CLERK_SECRET_KEY`, `CLERK_PUBLISHABLE_KEY`, `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY`, `CLERK_JWT_KEY` and `CLERK_WEBHOOK_SIGNING_SECRET`. `CLERK_FRONTEND_API_URL`, `CLERK_PROXY_URL` and `NEXT_PUBLIC_CLERK_PROXY_URL` name the same Frontend API. Pass `apiUrl`, `publishableKey`, `jwtKey` and `proxyUrl` to `createClerkClient`; keep the app's `authenticateRequest` and organization checks. `CLERK_JWT_KEY` is the PEM public key for networkless verification. Session tokens last 60 seconds and are dated on the app's own clock: the world's when the app runs with `agent.clock: node`, real time otherwise.
|
|
@@ -218,6 +218,115 @@ checks:
|
|
|
218
218
|
|
|
219
219
|
Use a native Stripe ID or a tool-local `$ref` (also `$type.ref`). Payment and paid-invoice refs identify their charge or PaymentIntent; customer refs identify customers or their stored payment methods. Other refs identify their seeded object type; invoice items use native IDs. `ancha twins seed stripe --json` prints validated examples. `ancha explain --json` reports the expected and actual state for each check.
|
|
220
220
|
|
|
221
|
+
## Supabase
|
|
222
|
+
|
|
223
|
+
Ancha builds the world's Supabase database from the app's `supabase/migrations` in file-name order, then `supabase/seed.sql`, then `seed.supabase.users`, `sql`, `buckets` and `objects`, in that order. Users are inserted into `auth.users` and `auth.identities`, so the app's user triggers run. Give `migrations: [{ name, sql }]` and `seed_sql` inline to supply those inputs in the scene. Explicit inline inputs take precedence over the corresponding project files.
|
|
224
|
+
|
|
225
|
+
The Data API and Storage run requests as `anon`, `authenticated` or `service_role`, with the caller's JWT claims. Postgres evaluates the app's row-level security policies; `service_role` has `BYPASSRLS`. Use the anon key and a signed-in user to test tenant access.
|
|
226
|
+
|
|
227
|
+
`seed.supabase.auth` sets `email_otp` (`code` or `link`), `confirm_email`, `access_token_ttl`, `otp_ttl`, `email_rate_limit` (emails per hour), `site_url` and `redirect_urls`. Durations and signed URL expiry follow the world clock. Read sign-in emails, codes and confirmation links with `ancha world inbox`.
|
|
228
|
+
|
|
229
|
+
```yaml
|
|
230
|
+
seed:
|
|
231
|
+
supabase:
|
|
232
|
+
migrations:
|
|
233
|
+
- name: 20261101090000_requests.sql
|
|
234
|
+
sql: |
|
|
235
|
+
create table public.document_requests (
|
|
236
|
+
tenant text not null,
|
|
237
|
+
requested_by uuid references auth.users(id),
|
|
238
|
+
document text not null,
|
|
239
|
+
status text not null
|
|
240
|
+
);
|
|
241
|
+
alter table public.document_requests enable row level security;
|
|
242
|
+
create policy own_requests on public.document_requests
|
|
243
|
+
for select to authenticated using (requested_by = auth.uid());
|
|
244
|
+
create policy own_uploads on storage.objects for insert to authenticated
|
|
245
|
+
with check (bucket_id = 'documents' and owner_id = auth.uid()::text);
|
|
246
|
+
seed_sql: "insert into public.document_requests values ('harborview-dental', null, 'engagement-letter.pdf', 'received')"
|
|
247
|
+
auth:
|
|
248
|
+
email_otp: code
|
|
249
|
+
confirm_email: true
|
|
250
|
+
access_token_ttl: 1h
|
|
251
|
+
otp_ttl: 10m
|
|
252
|
+
email_rate_limit: 30
|
|
253
|
+
site_url: http://localhost:3000
|
|
254
|
+
redirect_urls: [http://localhost:3000/auth/callback]
|
|
255
|
+
users:
|
|
256
|
+
- email: tom.reyes@harborview-dental.example
|
|
257
|
+
password: portal-demo-2
|
|
258
|
+
confirmed: true
|
|
259
|
+
sql:
|
|
260
|
+
- "insert into public.document_requests select 'harborview-dental', id, '2026-q4-payroll.csv', 'pending' from auth.users where email = 'tom.reyes@harborview-dental.example'"
|
|
261
|
+
buckets:
|
|
262
|
+
- { id: documents, public: false, allowed_mime_types: [text/csv] }
|
|
263
|
+
objects:
|
|
264
|
+
- bucket: documents
|
|
265
|
+
path: harborview-dental/2026-q3-payroll.csv
|
|
266
|
+
text: "employee,gross\nTom Reyes,8200\n"
|
|
267
|
+
content_type: text/csv
|
|
268
|
+
owner: tom.reyes@harborview-dental.example
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
`supabase.rows` selects a table and column values in `where`; `{ user: <email> }` resolves a seeded user's Auth id. Choose `count`, `count_gte` or `count_lte`. Checks read as the project owner, so they inspect every tenant's final state. `supabase.objects` selects a bucket and either `path` or `prefix`, with optional `owner`, `count`, `size` and `sha256`; size and digest apply to a path. `supabase.users` checks an email's existence, confirmation and whether it signed in during the test.
|
|
272
|
+
|
|
273
|
+
```yaml
|
|
274
|
+
checks:
|
|
275
|
+
- id: payroll_uploaded
|
|
276
|
+
state:
|
|
277
|
+
supabase.objects:
|
|
278
|
+
bucket: documents
|
|
279
|
+
path: harborview-dental/2026-q4-payroll.csv
|
|
280
|
+
owner: tom.reyes@harborview-dental.example
|
|
281
|
+
count: 1
|
|
282
|
+
- id: request_received
|
|
283
|
+
state:
|
|
284
|
+
supabase.rows:
|
|
285
|
+
table: document_requests
|
|
286
|
+
where:
|
|
287
|
+
requested_by: { user: tom.reyes@harborview-dental.example }
|
|
288
|
+
status: received
|
|
289
|
+
count: 1
|
|
290
|
+
- id: client_signed_in
|
|
291
|
+
state:
|
|
292
|
+
supabase.users:
|
|
293
|
+
email: tom.reyes@harborview-dental.example
|
|
294
|
+
confirmed: true
|
|
295
|
+
signed_in: true
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Use `supabase.sql` to run an administrator's SQL and `supabase.sign_in` to create a session for a seeded person. The same actions work through `ancha world act`. An app call with `as: { supabase: <email> }` signs that person in and sends their access token in `Authorization`.
|
|
299
|
+
|
|
300
|
+
Choose operation names from `ancha twins coverage supabase`. `world_rules.call_faults` returns a native provider error before execution: `effect: error` accepts a 5xx status; `effect: rate_limit` returns HTTP 429 and `Retry-After`.
|
|
301
|
+
|
|
302
|
+
```yaml
|
|
303
|
+
world_rules:
|
|
304
|
+
actors:
|
|
305
|
+
- at: 0s
|
|
306
|
+
supabase.sign_in: { email: tom.reyes@harborview-dental.example }
|
|
307
|
+
- at: 1m
|
|
308
|
+
supabase.sql:
|
|
309
|
+
sql: "update public.document_requests set status = 'received' where tenant = 'harborview-dental'"
|
|
310
|
+
app_calls:
|
|
311
|
+
- at: 5s
|
|
312
|
+
method: GET
|
|
313
|
+
path: /api/documents
|
|
314
|
+
as: { supabase: tom.reyes@harborview-dental.example }
|
|
315
|
+
call_faults:
|
|
316
|
+
- ref: database_retry
|
|
317
|
+
service: supabase
|
|
318
|
+
match: GET /rest/v1/{table}
|
|
319
|
+
effect: error
|
|
320
|
+
status: 503
|
|
321
|
+
times: 1
|
|
322
|
+
- ref: auth_backoff
|
|
323
|
+
service: supabase
|
|
324
|
+
match: POST /auth/v1/otp
|
|
325
|
+
effect: rate_limit
|
|
326
|
+
retry_after: 3
|
|
327
|
+
times: 1
|
|
328
|
+
```
|
|
329
|
+
|
|
221
330
|
## Clerk session and membership checks
|
|
222
331
|
|
|
223
332
|
Clerk session and membership checks use a `user` id or an `email`. `clerk.sessions` accepts `status` and one of `count`, `count_gte` or `count_lte` (default: at least one). `clerk.memberships` accepts an `organization` id or slug, optional `role`, and an exact `count` (default: at least one). For example:
|
|
@@ -230,6 +339,55 @@ checks:
|
|
|
230
339
|
state: { clerk.memberships: { organization: ridgeway-robotics, email: erin.walsh@ridgeway-robotics.example, role: "org:admin", count: 1 } }
|
|
231
340
|
```
|
|
232
341
|
|
|
342
|
+
## Stripe Connect accounts, transfers and payouts
|
|
343
|
+
|
|
344
|
+
Seed Express or Custom sellers in `connected_accounts` with `onboarding: complete`, `incomplete` or `restricted`, a test `bank`, a payout schedule and an optional `balance` in minor units. Account refs work as `$seller_ready` or `$account.seller_ready`. Configure settlement, payout arrival, verification review and the dispute fee under `connect`; the values below are the defaults:
|
|
345
|
+
|
|
346
|
+
```yaml
|
|
347
|
+
seed:
|
|
348
|
+
stripe:
|
|
349
|
+
livemode: false
|
|
350
|
+
account: { name: Market, currency: usd }
|
|
351
|
+
connected_accounts:
|
|
352
|
+
- { ref: seller_ready, type: express, name: Alex Reed, email: alex@market.example, onboarding: complete, bank: success, payouts: manual }
|
|
353
|
+
- { ref: seller_new, type: express, name: Sam Park, email: sam@market.example, onboarding: incomplete, payouts: manual }
|
|
354
|
+
payments:
|
|
355
|
+
- { ref: buyer_payment, amount: 10000, created: -1h }
|
|
356
|
+
connect:
|
|
357
|
+
settlement: { available_after: 2d, payout_arrival: 1d }
|
|
358
|
+
verification: { review: 0s }
|
|
359
|
+
disputes: { fee: 1500 }
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Use `Stripe-Account` (the SDK's `stripeAccount` request option) to select a connected account for balance, balance transaction, payout, event, account and external-account list requests. Card-payment funds move from pending to available after `connect.settlement.available_after` on the world clock; transfers with `source_transaction` share the source charge's availability time. Test banks `no_account`, `account_closed`, `insufficient_funds`, `debit_not_authorized` and `invalid_currency` produce the matching payout failure, return the funds and mark the bank errored; replacing it with `bank: success` enables payouts again.
|
|
363
|
+
|
|
364
|
+
Check account eligibility, transfer and fee totals, payout status and the seller's remaining balance:
|
|
365
|
+
|
|
366
|
+
```yaml
|
|
367
|
+
checks:
|
|
368
|
+
- { id: seller_onboarded, state: { stripe.accounts: { account: $seller_new, charges_enabled: true, payouts_enabled: true, requirements_due: false, count: 1 } } }
|
|
369
|
+
- { id: seller_transfer, state: { stripe.transfers: { destination: $seller_ready, count: 1, amount: 10000, after_start: true } } }
|
|
370
|
+
- { id: platform_fee, state: { stripe.application_fees: { account: $seller_ready, count: 1, amount: 1000, after_start: true } } }
|
|
371
|
+
- { id: seller_paid, state: { stripe.payouts: { account: $seller_ready, status: paid, count: 1, amount: 1000, after_start: true } } }
|
|
372
|
+
- { id: seller_balance, state: { stripe.account_balance: { account: $seller_ready, available: 8000, pending: 0 } } }
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
`stripe.accounts` matches every supplied field, including `email`, `details_submitted`, `capabilities`, `disabled_reason` and `requirements_due`; `count` is exact, otherwise at least one account must match. Transfers and application fees accept a `charge` filter and compare exact counts and summed minor-unit amounts; use `amount_reversed` for transfers and `amount_refunded` for fees. Transfers also accept `transfer_group`. Payouts accept `failure_code`; their `account` selects the owner. `after_start: true` selects transfers, fees or payouts created at or after the attempt starts. `stripe.account_balance` compares `available`, `pending` or both; omitting `account` selects the platform balance.
|
|
376
|
+
|
|
377
|
+
Script onboarding, new requirements, bank replacement and dispute outcomes on the same world clock:
|
|
378
|
+
|
|
379
|
+
```yaml
|
|
380
|
+
world_rules:
|
|
381
|
+
actors:
|
|
382
|
+
- { at: 5s, stripe.complete_onboarding: { account: $seller_new, bank: success } }
|
|
383
|
+
- { at: 1h, stripe.require: { account: $seller_ready, requirements: [individual.verification.document], capabilities: [transfers], deadline: 2h } }
|
|
384
|
+
- { at: 2h, stripe.update_bank: { account: $seller_ready, bank: success } }
|
|
385
|
+
- { at: 3h, stripe.dispute: { payment_intent: $buyer_payment, reason: fraudulent, amount: 10000 } }
|
|
386
|
+
- { at: 4h, stripe.close_dispute: { payment_intent: $buyer_payment, outcome: won } }
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
The three account actions select by `account` or `email`. `stripe.complete_onboarding` collects requirements, sets `details_submitted` and reviews the requested capabilities after `connect.verification.review`. `stripe.require` makes the named capabilities inactive at its deadline, or immediately when no deadline is given; meeting the requirements cancels that deadline. `stripe.update_bank` replaces the payout bank. `stripe.dispute` selects by `charge`, `payment_intent` or the latest succeeded charge for `customer_email`, debiting the platform for the disputed amount plus `connect.disputes.fee`. `stripe.close_dispute` selects by `dispute` or the same payment selectors; `won` reinstates the disputed amount and `lost` closes the dispute. `ancha twins seed stripe --json` includes all five checks and actions.
|
|
390
|
+
|
|
233
391
|
## Zendesk ticket checks
|
|
234
392
|
|
|
235
393
|
Use `zendesk.ticket` to check one ticket by numeric `id` or exact `subject`. All supplied conditions apply to that ticket. A subject identifies exactly one ticket; use its `id` when subjects repeat.
|
package/lib/assets/docs/tools.md
CHANGED
|
@@ -80,6 +80,8 @@ Use `--server-url <origin>` to target another local server. `ancha ui --server-u
|
|
|
80
80
|
|
|
81
81
|
## Native client contracts
|
|
82
82
|
|
|
83
|
+
**Supabase**: Postgres tables with row-level security, Auth sessions and Storage buckets and objects. Run `ancha connect supabase --lang ts` and pass `SUPABASE_URL` and `SUPABASE_ANON_KEY` to `createClient` from `@supabase/supabase-js`. The world builds the database from the app’s migrations and seed, captures sign-in mail in `ancha world inbox`, and grades rows, files and users with `supabase.rows`, `supabase.objects` and `supabase.users`. See `ancha docs apps` and `ancha docs scenes`.
|
|
84
|
+
|
|
83
85
|
Run `ancha connect <tool> --lang ts` for the selected native HTTP setup. Google Ads also qualifies `--lang py` using the official Python client with a local TLS gRPC endpoint and the supplied test certificate. These connection overrides are necessary; changing only a model provider key does not connect tool clients.
|
|
84
86
|
|
|
85
87
|
The new tools are LinkedIn Ads (202610), Salesforce (REST v67.0), Gong (v2), Google Ads (v26), ChatGPT Ads (Advertiser API v1), HubSpot (CRM v3), and Google Analytics (Data API v1beta REST). `ancha twins coverage <tool> --json` lists each one's supported operations. Slack, GitHub, Datadog, PagerDuty and Open-Meteo are available too.
|