@ancha-labs/cli 0.4.33 → 0.4.34
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/lib/ancha.mjs +2298 -1444
- package/lib/assets/docs/apps.md +33 -2
- package/lib/assets/docs/cloud.md +1 -0
- package/lib/assets/docs/scenes.md +12 -0
- package/lib/assets/harbor/companion.mjs +1509 -803
- package/lib/assets/ui/app.js +1 -1
- package/lib/mcp-entry.mjs +263 -231
- package/lib/worker.mjs +1760 -1006
- package/lib/world-server.mjs +1484 -778
- package/package.json +1 -1
package/lib/assets/docs/apps.md
CHANGED
|
@@ -54,7 +54,7 @@ agent:
|
|
|
54
54
|
PORT: "{{agent.port}}"
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
Stripe and
|
|
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
59
|
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
60
|
|
|
@@ -71,6 +71,37 @@ world_rules:
|
|
|
71
71
|
|
|
72
72
|
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
73
|
|
|
74
|
+
## Clerk sign-in
|
|
75
|
+
|
|
76
|
+
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.
|
|
77
|
+
|
|
78
|
+
The harness can POST an `identifier` to `CLERK_FRONTEND_API_URL/v1/client/sign_ins`, then POST `{ "strategy": "email_code" }` to `/v1/client/sign_ins/{id}/prepare_first_factor`. Read the six-digit code with `ancha world inbox`, and POST `{ "strategy": "email_code", "code": "<code>" }` to `/v1/client/sign_ins/{id}/attempt_first_factor`. Retain the response cookies or its `Authorization` header between Frontend API calls. Use the resulting `__session`, `__client_uat` and `__clerk_db_jwt` cookies when calling the app, or obtain a bearer token from `/v1/client/sessions/{id}/tokens`.
|
|
79
|
+
|
|
80
|
+
A scene actor can sign the person in directly:
|
|
81
|
+
|
|
82
|
+
```yaml
|
|
83
|
+
world_rules:
|
|
84
|
+
actors:
|
|
85
|
+
- at: 0s
|
|
86
|
+
clerk.sign_in:
|
|
87
|
+
email: erin.walsh@ridgeway-robotics.example
|
|
88
|
+
organization: ridgeway-robotics
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
To call the app as a signed-in person, give an app call `as`. The call carries a fresh session token in `Authorization`, from the person's latest active session (or a new one). `organization` sets the session's active organization while they are a member and clears it once they are not:
|
|
92
|
+
|
|
93
|
+
```yaml
|
|
94
|
+
world_rules:
|
|
95
|
+
app_calls:
|
|
96
|
+
- at: 5s
|
|
97
|
+
method: POST
|
|
98
|
+
path: /api/notes
|
|
99
|
+
as: { clerk: erin.walsh@ridgeway-robotics.example, organization: ridgeway-robotics }
|
|
100
|
+
body: { text: Dock 4 is open }
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The same `clerk.sign_in` action works through `ancha world act`; its result includes the session token, app cookies and client credential for refreshing tokens. Organization invitations appear in the inbox with an acceptance link carrying `__clerk_ticket`. Submit that ticket with the `ticket` strategy to sign in or sign up. Use `clerk.sessions` and `clerk.memberships` checks to assert the result. Route Clerk events to the app's webhook endpoint with `{{service}}` and verify their Svix headers and raw body with `CLERK_WEBHOOK_SIGNING_SECRET`. In a world started with `ancha world up`, add the endpoint as you would in Clerk's dashboard: `ancha world act clerk.subscribe_webhook --env <id> --args '{"url":"http://127.0.0.1:3000/api/webhooks/clerk"}'`, with `events` to take only the listed types.
|
|
104
|
+
|
|
74
105
|
## ancha.yaml
|
|
75
106
|
|
|
76
107
|
```yaml
|
|
@@ -144,7 +175,7 @@ checks:
|
|
|
144
175
|
trace: { not_called: "* /api/chat.delete" }
|
|
145
176
|
```
|
|
146
177
|
|
|
147
|
-
- `app_calls` take `at`, `method` (default GET), `path`, `headers` and `body`; they go to the origin of `ready_url`.
|
|
178
|
+
- `app_calls` take `at`, `method` (default GET), `path`, `headers` and `body`; they go to the origin of `ready_url`. With `as: { clerk: <email or user id>, organization: <id or slug> }` the call is made as that signed-in person: it carries a fresh Clerk session token in `Authorization`.
|
|
148
179
|
- `gmail.send` takes `from`, `to`, `cc`, `subject`, `body`, `in_reply_to` and `ref`. The `gmail.thread` check takes `of` (a message ref), `label` with `present`, `drafts_gte`, `drafts_lte` and `messages_gte`.
|
|
149
180
|
- People who answer like a person go in the test's `people:` (`ancha schema scene` lists every field). One with a Gmail account reads the mail delivered to that mailbox, which must be in `seed.gmail.mailboxes`, and replies in the thread: `{ ref: tom, name: Tom, role: a client who answers email himself within a day or two, accounts: { gmail: tom@client.example }, replies_after: 1d..2d }`. People call a model with your `OPENROUTER_API_KEY`, or `ANCHA_PEOPLE_BASE_URL` and `ANCHA_PEOPLE_API_KEY` (`ancha docs cloud`). `ancha twins seed <tool> --json` prints each tool's seed fields and checks.
|
|
150
181
|
- Make every check able to fail. Run a test once against a build with the feature broken, or also check the state in between (the label the app should have removed). A check can pass for the wrong reason: a reminder that never comes because the scheduled call ran too early proves nothing.
|
package/lib/assets/docs/cloud.md
CHANGED
|
@@ -90,6 +90,7 @@ ancha run --on cloud
|
|
|
90
90
|
- A workspace runs 3 attempts at once and up to 150 in a run (a workspace with hosted runs: 10 at once); an attempt has 15 minutes and a run 2 hours. Cloud runs count toward the workspace's machine hours. The summary's `caps` and the run's last lines name the caps it ran under.
|
|
91
91
|
- Without a path, the run takes every test `scenes:` in `ancha.yaml` names (by default `scenes/**/scene.yaml`, so the tests your traces made too).
|
|
92
92
|
- The project goes up as one bundle: the agent's files, without hidden directories, dependencies or credential-like files, and the tests with their worlds and checks. Those stay with the grader: the agent never sees them.
|
|
93
|
+
Keep the agent's start script outside `ancha/` and the test folders, and point `agent.start` to that file.
|
|
93
94
|
- The first attempt runs ahead, and the others start once its agent has started.
|
|
94
95
|
- When every attempt ended before the agent did anything (it exited with an error within 5 seconds without a call, or its command could not start), the run's last lines say that first: "Your agent didn't run: it exited with code 1 within 96 ms in all 3 attempts", the end of its log from the cloud machine, the likely fix read from that log, and the commands to run again. The checks that failed because of it are one line; `ancha explain <run id> --all` lists them. With `--json`, `run_finished` carries the same as `agentNeverRan`.
|
|
95
96
|
- The agent gets Ancha's and the tools' variables, `agent.env`, and the workspace's secrets for the names in `agent.pass_env`, as they were when the run was accepted. Its model providers are `openrouter.ai`, `api.openai.com` and `api.anthropic.com`, or the ones `agent.execution.modelHosts` names.
|
|
@@ -218,6 +218,18 @@ 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
|
+
## Clerk session and membership checks
|
|
222
|
+
|
|
223
|
+
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:
|
|
224
|
+
|
|
225
|
+
```yaml
|
|
226
|
+
checks:
|
|
227
|
+
- id: signed_in
|
|
228
|
+
state: { clerk.sessions: { email: erin.walsh@ridgeway-robotics.example, status: active, count_gte: 1 } }
|
|
229
|
+
- id: organization_admin
|
|
230
|
+
state: { clerk.memberships: { organization: ridgeway-robotics, email: erin.walsh@ridgeway-robotics.example, role: "org:admin", count: 1 } }
|
|
231
|
+
```
|
|
232
|
+
|
|
221
233
|
## Zendesk ticket checks
|
|
222
234
|
|
|
223
235
|
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.
|