sil-openclaw 0.5.2 → 0.7.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 (45) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +27 -26
  3. package/SECURITY.md +3 -4
  4. package/dist/index.js +1 -1
  5. package/dist/lib/shopping-call.js +7 -4
  6. package/dist/lib/sil-client.js +36 -66
  7. package/dist/lib/tool-result.js +1 -1
  8. package/dist/tools/catalog.js +83 -242
  9. package/dist/tools/identity.js +74 -87
  10. package/openclaw.plugin.json +12 -7
  11. package/package.json +1 -1
  12. package/schema/PROVENANCE.md +7 -4
  13. package/schema/shopping-brief-read-response.schema.json +1 -1
  14. package/schema/shopping-brief-write-request.schema.json +225 -0
  15. package/schema/{shopping-brief-create-response.schema.json → shopping-brief-write-response.schema.json} +3 -3
  16. package/schema/shopping-content-request.schema.json +89 -0
  17. package/schema/shopping-content-response.schema.json +298 -0
  18. package/schema/shopping-domain-get-request.schema.json +19 -1
  19. package/schema/shopping-domain-get-response.schema.json +330 -66
  20. package/schema/shopping-domain-search-request.schema.json +1 -1
  21. package/schema/shopping-domain-search-response.schema.json +40 -35
  22. package/schema/shopping-offers-request.schema.json +174 -23
  23. package/schema/shopping-offers-response.schema.json +20 -10
  24. package/schema/shopping-product-get-request.schema.json +2 -2
  25. package/schema/shopping-product-get-response.schema.json +119 -16
  26. package/schema/shopping-search-request.schema.json +16 -25
  27. package/schema/shopping-search-response.schema.json +101 -21
  28. package/schema/shopping-seller-get-response.schema.json +249 -221
  29. package/schema/shopping-user-forget-request.schema.json +43 -0
  30. package/schema/shopping-user-forget-response.schema.json +74 -0
  31. package/schema/shopping-user-read-request.schema.json +36 -0
  32. package/schema/shopping-user-read-response.schema.json +372 -0
  33. package/schema/shopping-user-remember-request.schema.json +340 -0
  34. package/schema/shopping-user-remember-response.schema.json +66 -0
  35. package/schema/sil-whoami-request.schema.json +8 -0
  36. package/schema/sil-whoami-response.schema.json +90 -0
  37. package/sil-shopping/SKILL.md +139 -180
  38. package/schema/shopping-brief-create-request.schema.json +0 -98
  39. package/schema/shopping-brief-edit-request.schema.json +0 -125
  40. package/schema/shopping-brief-edit-response.schema.json +0 -24
  41. package/schema/shopping-domain-create-request.schema.json +0 -160
  42. package/schema/shopping-domain-create-response.schema.json +0 -60
  43. package/schema/shopping-profile-edit-request.schema.json +0 -97
  44. package/schema/shopping-profile-edit-response.schema.json +0 -17
  45. package/sil-shopping/references/mint.md +0 -190
package/CHANGELOG.md CHANGED
@@ -10,6 +10,53 @@ release (`clawhub package publish --changelog`). See [README](./README.md#releas
10
10
 
11
11
  ## [Unreleased]
12
12
 
13
+ ## [0.7.0] - 2026-10-12
14
+
15
+ ### Changed
16
+
17
+ - **Fifteen tools on sil's signed contract.** `shopping_brief_create`, `shopping_brief_edit` and
18
+ `shopping_profile_edit` are gone; `shopping_brief_write`, `shopping_user_read`,
19
+ `shopping_user_remember` and `shopping_user_forget` replace them. `sil_whoami` answers the
20
+ lean shape (name, country, currency, gender, language, one default address). Replies are
21
+ compact JSON. `shopping_domain_get` pages with `keys` and `after`; `shopping_product_get`
22
+ takes at most three ids and an optional `page`. The skill is rewritten to match.
23
+ - **`sil_whoami` answers flat**, exactly the contract's shape: no `identity` wrapper, no
24
+ `web_origin` fields. `shopping_product_get` names ids sil does not hold in `not_held`.
25
+ - **sil refuses a plugin older than 0.7.0** (HTTP 426); its message reaches the agent as it
26
+ stands.
27
+
28
+ ## [0.6.0] - 2026-10-08
29
+
30
+ ### Added
31
+
32
+ - **`shopping_content` greps sil's library about a thing**: sil's own guides and the sources it
33
+ read, quoted verbatim with their author and link. Send a node and the terms: it reads every
34
+ document on the line through that node (the node, every kind it is, what sits beneath it and
35
+ every place above it) and answers whole passages within a token budget, every term first. A
36
+ quoted phrase is one term, `total` says how many passages hold a term, and `document` with
37
+ `from` reads any document on by part. No model in the path. The skill greps a leaf's library
38
+ before the first question to the buyer, and again when the buyer asks how or why; it says so
39
+ plainly when sil holds nothing.
40
+
41
+ ### Changed
42
+
43
+ - **Finding the place is three calls.** `shopping_domain_search` takes what the thing is
44
+ called and answers up to three leaves, best first: `path`, `name`, which of sil's words
45
+ `matched`, and `under`, every place above the leaf. `shopping_domain_get` reads that leaf's
46
+ specs and says how its products are bought (`record`: `specs` or `full`).
47
+ `shopping_search` is unchanged.
48
+ - **A place sil does not carry yet answers nothing.** The domain search returns no leaf for it,
49
+ and `shopping_domain_get` and `shopping_search` refuse it as `not carried`, before any spend.
50
+ The skill tells the buyer sil cannot sell it yet, it is in the pipeline, and stops: no
51
+ search, no other place, no web.
52
+ - **English to sil.** Every `q`, value, narrative and quoted reason the agent sends is English;
53
+ the skill translates the buyer's words on the way in and answers in their language.
54
+ - The skill's place-finding section is rewritten around the three calls.
55
+
56
+ ### Removed
57
+
58
+ - `tree` and `about` from the search answer, and `guide` from the domain read.
59
+
13
60
  ## [0.5.2] - 2026-10-06
14
61
 
15
62
  ### Added
package/README.md CHANGED
@@ -95,19 +95,19 @@ agent done — here's your checkout link, ready to pay:
95
95
 
96
96
  ## Turn your OpenClaw into your personal shopping expert
97
97
 
98
- So far your *general* agent did the shopping. Go one step further, with **nothing to set up**: install the plugin and the agent you already have shops **any** niche like a specialist, learning how to buy well in each one the first time you shop it and getting sharper every session.
98
+ So far your *general* agent did the shopping. Go one step further, with **nothing to set up**: install the plugin and the agent you already have shops **any** niche like a specialist, getting sharper about *you* every session.
99
99
 
100
- **Spec-Driven Shopping (SDS).** There is no setup step and no interview — just say what you want. The first time you ask for something in a new niche the plugin **classifies** what you're buying, **researches that niche deeply on the spot** (the full how-to-buy-well: fit, gearing, geometry, the trade-offs — announced, so you can correct it), and derives the **dimensions** every request in that niche is decomposed along, minting a reusable **domain**. Ask for that niche again and it reuses what it learned; ask for a new one and it learns that too, keeping *you* the same across all of them. On **every query** it reads sil's shared registry for how that category is bought, decomposes what you asked, and **learns your facts and taste as it goes** (your measurements, your budget, a brand you won't touch) — captured once, never re-asked. It recommends with a "why" that cites *what you asked*, *a fact it remembered*, and *a niche mechanic you'd never have named*.
100
+ **Spec-Driven Shopping (SDS).** There is no setup step and no interview — just say what you want. The plugin finds the node in sil's **domain graph** for what you're buying and reads the **specs** it is bought along (fit, gearing, geometry, the trade-offs) — what every request there is decomposed into. It decomposes what you asked, **learns your facts and taste as it goes** (your measurements, your budget, a brand you won't touch) — captured once, never re-asked — and recommends with a "why" that cites *what you asked*, *a fact it remembered*, and *a niche mechanic you'd never have named*.
101
101
 
102
- **It learns a niche the first time you shop it, and keeps *you* across all of them:**
102
+ **Every niche reads sil's own node, and keeps *you* across all of them:**
103
103
 
104
104
  ```text
105
105
  you find me a road bike, ~€1500
106
106
 
107
- agent New niche for us — road cycling. Let me learn how to buy one
108
- well (fit from height AND inseam, endurance-vs-race geometry,
109
- gearing, the comfort/speed trade-offs) — and two numbers I'll
110
- keep so I never re-ask: your height and inseam.
107
+ agent [shopping_domain_search "road bike" → shopping_domain_get]
108
+ Road bikes are bought on fit from height AND inseam, endurance
109
+ vs race geometry, and gearing. Two numbers I'll keep so I never
110
+ re-ask: your height and inseam.
111
111
 
112
112
  you 178cm, 81cm inseam. Secondhand is fine
113
113
 
@@ -122,20 +122,20 @@ agent searched sil — endurance, 54cm for your fit, ~€1500:
122
122
 
123
123
  you later — find me a backpacking tent for two, under €250
124
124
 
125
- agent Different niche — camping. Learning how to buy a backpacking
126
- tent (season rating, packed weight, floor area)… and your
127
- returns rule carries straight over, no need to re-ask.
125
+ agent [shopping_domain_search "backpacking tent" → shopping_domain_get]
126
+ Tents are bought on season rating, packed weight and floor
127
+ area… and your returns rule carries straight over.
128
128
  ```
129
129
 
130
- > **You teach it once; it stays sharp.** How a category is bought comes from sil's shared registry — read before the web, so it is current without you teaching it twice — and your own facts, taste and shopping jobs belong to your sil account rather than to one agent. Nothing to re-answer, and sharper every session.
130
+ > **You teach it once; it stays sharp.** How a thing is bought comes from sil's domain graph, the same for every agent, and your own facts, taste and shopping jobs belong to your sil account rather than to one agent. Nothing to re-answer, and sharper every session.
131
131
 
132
- **What it keeps on your machine: nothing of yours.** The plugin stores your sil credentials and its own configuration under `$SIL_DATA_DIR` (owner-only `0600`) and nothing else — no notes about you, no shopping jobs, no measurements. A shopping call reads that credential, rewrites it when sil refreshes it, and deletes it when the session is past refreshing. What your agent learns about you lives in your sil account, is **never pooled across users**, and is never used for training or aggregation. Research reads public sources to learn how a *category* is bought; it does not upload anything about you. If an earlier version left a `shopper/` folder under that directory, nothing reads it any more and you can delete it.
132
+ **What it keeps on your machine: nothing of yours.** The plugin stores your sil credentials and its own configuration under `$SIL_DATA_DIR` (owner-only `0600`) and nothing else — no notes about you, no shopping jobs, no measurements. A shopping call reads that credential, rewrites it when sil refreshes it, and deletes it when the session is past refreshing. What your agent learns about you lives in your sil account, is **never pooled across users**, and is never used for training or aggregation. If an earlier version left a `shopper/` folder under that directory, nothing reads it any more and you can delete it.
133
133
 
134
134
  ---
135
135
 
136
136
  ## Tools
137
137
 
138
- Fourteen tools. The eleven the shopping loop calls are named `shopping_*` — for what
138
+ Fifteen tools. The twelve the shopping loop calls are named `shopping_*` — for what
139
139
  they do for you — and the three account tools keep the `sil_` name. Your agent calls them
140
140
  for you; you just say what you want.
141
141
 
@@ -144,28 +144,29 @@ for you; you just say what you want.
144
144
  | Tool | What it does |
145
145
  |---|---|
146
146
  | `sil_register` | Start a browser sign-in and link your agent to your sil identity. Takes no arguments. |
147
- | `sil_whoami` | Read your sil identity — name, country, the currency you price in, saved addresses, and the measurements and preferences sil holds for you — as the agent sees it. Takes no arguments. |
147
+ | `sil_whoami` | Read your sil identity — name, country, the currency you price in, language, gender and your default address — as the agent sees it. Takes no arguments. |
148
148
  | `sil_doctor` | Check the install: file modes, credential health, host wiring, and whether a newer plugin is published. Reports; repairs only what is safe. |
149
149
 
150
- **Your brief and your profile**
150
+ **What sil keeps about you, and your briefs**
151
151
 
152
152
  | Tool | What it does |
153
153
  |---|---|
154
- | `shopping_brief_create` | Open the shopping job this conversation works from — a title and what you are after in your own words, plus any wants you have already stated. One brief per conversation, across every category it covers. |
155
- | `shopping_brief_edit` | Write a want, a change of mind or the end of the job into that brief: the values you want under the category they belong to, the seller terms under `seller`, the keys you have given up, and one sentence saying what you changed and why. |
156
- | `shopping_brief_read` | With no arguments, your shopping jobs, newest first — so a new chat carries on where the last one stopped. With an `id`, that whole brief: what you are after, every want under its category, and the decisions you have already taken. |
157
- | `shopping_profile_edit` | Write what is true of you whatever you are buying: a measurement with its unit, a size as it is printed, a lasting taste in your own words, or the currency you price in. Writing the same name again replaces it; `sil_whoami` reads it all back. A new currency changes which offers come first, never a price: sil converts nothing. |
154
+ | `shopping_user_read` | Everything sil keeps about you — measurements, memories, preferences, purchases — each with what it gives you back. |
155
+ | `shopping_user_remember` | Keep what lasts, in the turn you say it, with "forget that" as the undo. |
156
+ | `shopping_user_forget` | Erase rows you name, or everything, on your word. |
157
+ | `shopping_brief_write` | Open a brief for a buy with requirements, or update one: a title, what you are after in your own words, specs by domain, decisions and the end of the job. |
158
+ | `shopping_brief_read` | With no arguments, your shopping jobs, newest first. With an `id`, that whole brief. |
158
159
 
159
160
  **Shopping**
160
161
 
161
162
  | Tool | What it does |
162
163
  |---|---|
163
- | `shopping_domain_search` | Read sil's shared registry in your own words and get back the categories that match, each with a line on how the thing is bought. An empty list is the one answer that licenses a mint. |
164
- | `shopping_domain_get` | Read one standing category: its buying guide, and every key it is bought by with the operators, unit and allowed values each takes. |
165
- | `shopping_domain_create` | Coin a NEW category — its path, a guide written from research, and its first keys. The one permanent, global write in sil; an existing path is refused and nothing is written. |
166
- | `shopping_search` | Search one settled category, under the brief this conversation is working from. Send the brief's id, the domain, your own shopping words, how many products you want, the brief's own values for that category as `specs`, and `ship_to` — the label of one of your saved addresses, which localizes the search (your default one when it is left off) and rules no seller out. Products come back best-first with `fit` (what sil verified), their variants, a price range, and `webpage_info` where sil has not read the page yet. |
167
- | `shopping_product_get` | Open the whole of what sil holds on 1–10 shortlisted variants: the description, the images, every key sil holds, and where each reading came from and when. |
168
- | `shopping_offers` | Price 1–10 picked variants live, on your own terms: send the brief's id and the variant ids, and sil reads the rest — the brief's `seller` terms and price ceiling, your default address and your currency. It looks on the web for shops it does not hold yet, and each offer comes back with the price exactly as the page prints it, its currency, availability, the listing URL, the moment sil read it, and `seller_fit` — whether that seller ships to your address (`serviceable`, `not_serviceable` or `unknown`) and what it holds for each term on the brief. Shops in your currency and market come first. |
164
+ | `shopping_domain_search` | Say what the thing is called, in your own words, and get back up to three leaves (buyable kinds of thing), best first: each with its name, which of sil's words matched, and `under` — the places above it. Empty when nothing fits, or when the best fit is an area sil does not carry yet. |
165
+ | `shopping_content` | Grep sil's own documents on the line through a node — the node, its kinds, beneath it and above it — by words, never by meaning. Answers whole passages within a token budget, every-word matches first, each with the words it matched; filled passages carry none. |
166
+ | `shopping_domain_get` | Read a leaf's specs, in pages when it is wide (`keys` reads chosen ones whole, `after` reads on): every key it is bought by with the operators, unit and allowed values each takes, plus its kinds, parts and how its products are bought (`record`). On a kind it also lists its `leaves`. A shelf or domain is refused as `not_a_leaf`; an area sil does not carry yet as `not_carried`. |
167
+ | `shopping_search` | Search a leaf, or the kind above its leaves, on every want the buyer settled: each a spec with the operator it needs, words only for what no spec holds. No brief or earlier call is needed. Products come back in sil's order with `fit` (what sil verified, or `unknown`), and every search answers sil's receipt: shops and products weighed, how many fit, how many it could not tell, and what was set aside and why. |
168
+ | `shopping_product_get` | Open the whole of what sil holds on up to three shortlisted variants (or one product's whole page): the description, the images, every key sil holds, and where each reading came from and when. |
169
+ | `shopping_offers` | Who sells it, at what price and on what terms: send 1–10 picked variant ids or a product's `name` for a price check, optionally the `seller_specs` the buyer settled and a `brief` id. Each offer comes back with the seller, the price in its own currency, availability, the listing URL, when sil read it, and `seller_fit` — whether that seller ships to your default address (`serviceable`, `not_serviceable` or `unknown`) and its value for each seller spec asked. Shops in your currency and market come first. |
169
170
  | `shopping_seller_get` | One seller's whole terms, for 1–10 of them: `specs` (every seller key sil holds a value for), whether it ships to you, and the shipping routes and return terms sil has read. `unknown` keeps the seller; it just means sil has not read that policy. |
170
171
 
171
172
  **The wire is a contract, not a convention.** Each shopping tool's input schema IS the
@@ -179,7 +180,7 @@ is the API's own 200 body handed over untouched.
179
180
  The plugin ships one bundled skill — **`sil-shopping`** 🛒 — that your agent loads automatically the first time you express a shopping intent. You don't invoke it; it's the playbook that makes the tools work well together:
180
181
 
181
182
  - **Routes intent to the right tool.** *"find me a keyboard"* → `shopping_search`, *"what does it cost?"* → `shopping_offers`, *"will it reach me?"* → `shopping_seller_get`, *"what was I shopping for?"* → `shopping_brief_read`, *"who am I?"* → `sil_whoami`, *"sign me up"* → `sil_register`.
182
- - **Many niches, minted on the fly, with no preparation.** A shopping intent runs the loop on whatever agent holds the plugin: it classifies what you're buying, reuses a niche it has already learned or **researches a new one on the spot** (announced, so you can correct it), and derives how to decompose every request — learning your facts and taste as it goes.
183
+ - **Many niches, with no preparation.** A shopping intent runs the loop on whatever agent holds the plugin: it finds the place sil shelves what you're buying (`shopping_domain_search`), reads the specs it is bought along (`shopping_domain_get`), and decomposes every request along them — learning your facts and taste as it goes.
183
184
  - **Recovers the right way.** Every tool reports a status; the skill follows that tool's own recovery hint — re-register, fix the query, or retry — instead of guessing a fix that won't work.
184
185
  - **Keeps prices honest.** A price is dated only where sil dated it, so the skill re-reads an item's offers right before you buy and quotes the moment they were read.
185
186
  - **Says what sil verified, and says the rest as what it is.** A key sil holds no value for is named as a gap, not passed off as a miss; a page sil has not read yet is quoted as the seller's own words; a seller sil knows nothing about keeps its place.
package/SECURITY.md CHANGED
@@ -31,10 +31,9 @@ The plugin talks to these hosts and no others:
31
31
  the published `@4gpts/sil` version: no token, no PII, bounded timeout, redirects
32
32
  refused, silent on any failure.
33
33
 
34
- The `shopping_*` tools are read-only, except `shopping_domain_create` (writes one
35
- registry row) and `shopping_brief_create` / `shopping_brief_edit` /
36
- `shopping_profile_edit` (write the buyer's own brief and profile under their sil
37
- account). On a `401`, every sil call refreshes once and retries once. A second
34
+ The `shopping_*` tools are read-only, except `shopping_brief_write` /
35
+ `shopping_user_remember` / `shopping_user_forget` (write or erase the buyer's own brief
36
+ and rows under their sil account). On a `401`, every sil call refreshes once and retries once. A second
38
37
  `401` or a dead refresh token clears `tokens.json`.
39
38
 
40
39
  ### Filesystem and credentials
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * sil OpenClaw plugin — entry point.
3
3
  *
4
4
  * A UCP commerce plugin for sil. It registers its real tool groups — the account
5
- * tools (`sil_register`, `sil_whoami`, `sil_doctor`) and the eleven `shopping_*`
5
+ * tools (`sil_register`, `sil_whoami`, `sil_doctor`) and the ten `shopping_*`
6
6
  * catalog tools — so they load in an OpenClaw host.
7
7
  * There is no transport, no persistent service, and no background work at
8
8
  * register time — `register()` is strictly synchronous and opens nothing.
@@ -9,7 +9,11 @@ import { callShopping, refreshAndRetryOnce, } from "./sil-client.js";
9
9
  import { jsonResult } from "./tool-result.js";
10
10
  /** The guide read, as one route constant: two spellings of one path is a route nobody
11
11
  * owns. */
12
- export const DOMAIN_GET_ROUTE = { method: "GET", path: "/catalog/domains/:path" };
12
+ export const DOMAIN_GET_ROUTE = {
13
+ method: "GET",
14
+ path: "/catalog/domains/:path",
15
+ query: ["keys", "after"],
16
+ };
13
17
  function refused(status, result) {
14
18
  return { kind: "refused", status, result };
15
19
  }
@@ -51,9 +55,8 @@ function mapOutcome(api, call, outcome) {
51
55
  api.logger.info(`${call.name}_invalid_request`, {});
52
56
  return refused("invalid_request", refusal("invalid_request", outcome.message));
53
57
  case "not_found":
54
- case "already_exists":
55
- api.logger.info(`${call.name}_${outcome.kind}`, {});
56
- return refused(outcome.kind, refusal(outcome.kind, outcome.message, call.recovery?.[outcome.kind]));
58
+ api.logger.info(`${call.name}_not_found`, {});
59
+ return refused("not_found", refusal("not_found", outcome.message, call.recovery?.not_found));
57
60
  case "forbidden":
58
61
  return refused("forbidden", forbiddenResult(api, call.name, outcome.reason));
59
62
  case "retryable":
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Typed HTTP wrappers for every endpoint the plugin calls — the two sil-web auth
3
- * endpoints, the sil-api identity read and the eleven shopping routes — each returning
3
+ * endpoints, the sil-api identity read and the ten shopping routes — each returning
4
4
  * a DISCRIMINATED UNION over the documented outcomes so the status taxonomy lives in
5
5
  * exactly one place and the caller switches on `kind` rather than re-deriving meaning
6
6
  * from `res.status` at every site.
@@ -36,11 +36,14 @@
36
36
  * request body:
37
37
  *
38
38
  * GET <silApiUrl>/identity Authorization: Bearer <access_token>
39
- * 200 { name, country?, addresses, measurements?, preferences? } → ok
39
+ * 200 { status, name, country?, currency?, gender?, language?, address? } → ok
40
40
  * 401 → unauthorized (→ refresh)
41
41
  * 403 { error: user_not_provisioned | principal_mismatch } → forbidden (terminal)
42
+ * 426 plugin older than sil accepts → refused (carries sil's message)
42
43
  * 5xx / network / abort → retryable
43
44
  *
45
+ * Shopping routes: 426 (plugin too old) → invalid_request, carrying sil's message.
46
+ *
44
47
  * THE SHOPPING WIRE IS NOT MIRRORED HERE. Each tool's request shape is the committed
45
48
  * artifact under `schema/`, registered as the tool's own `parameters`; each 200 body is
46
49
  * the agent contract's, handed back VERBATIM. So this file declares no product type at
@@ -61,7 +64,7 @@
61
64
  * The VERB is load-bearing: only `GET /identity` is the self-read — `POST` is the
62
65
  * agent enrich route and carries no name. The identity rides in the envelope's
63
66
  * `result`, and a 200 with no usable identity (no `name`) falls to `retryable`,
64
- * never to a false `ok`. An EMPTY `addresses: []` IS a valid identity.
67
+ * never to a false `ok`. A buyer with no `address` is a valid identity.
65
68
  *
66
69
  * Tokens never appear in a log line here (mirrors sil-web's invariant) — they
67
70
  * only travel inside the returned union variant.
@@ -74,17 +77,8 @@ import { readTokens, writeTokens } from "./credentials.js";
74
77
  * route that answers from what sil already holds — at 15 s the plugin refused 7 of 12 live
75
78
  * calls sil-api went on to finish (2026-09-15). */
76
79
  const REQUEST_TIMEOUT_MS = 45_000;
77
- /** The search alone waits out its web leg, which the agent contract gives 120 s. Aborting
78
- * short of that changes nothing sil does — the index is billed, the pages are read and the
79
- * row is written — it only hides the answer from the agent that asked for it. */
80
- const SEARCH_TIMEOUT_MS = 130_000;
81
- /** The search route, the one call that waits out a web leg. Resolved by PATH so a route
82
- * renamed in the tool table falls back to the shared ceiling loudly — `lib/sil-client.test.ts`
83
- * reads this off the production table. */
84
- const SEARCH_PATH = "/catalog/search";
85
- export const requestTimeoutMs = (route) => route.path === SEARCH_PATH ? SEARCH_TIMEOUT_MS : REQUEST_TIMEOUT_MS;
86
80
  /**
87
- * Classify a shopping response. One classifier for all eleven routes — the contract
81
+ * Classify a shopping response. One classifier for all ten routes — the contract
88
82
  * gives them one error vocabulary, so a second one could only drift.
89
83
  *
90
84
  * The 200 gate is the whole of what the plugin owns: a plain object stating
@@ -94,16 +88,16 @@ export const requestTimeoutMs = (route) => route.path === SEARCH_PATH ? SEARCH_T
94
88
  * source, and a second opinion here would be the copy that drifts from it.
95
89
  */
96
90
  function classifyShoppingResponse(status, body) {
97
- if (status === 400)
91
+ // 426: sil refuses a plugin older than it accepts; its message says to update.
92
+ if (status === 400 || status === 426) {
98
93
  return { kind: "invalid_request", message: extractApiError(body).message };
94
+ }
99
95
  if (status === 401)
100
96
  return { kind: "unauthorized" };
101
97
  if (status === 403)
102
98
  return { kind: "forbidden", reason: extractForbiddenReason(body) };
103
99
  if (status === 404)
104
100
  return { kind: "not_found", message: extractApiError(body).message };
105
- if (status === 409)
106
- return { kind: "already_exists", message: extractApiError(body).message };
107
101
  if (status !== 200)
108
102
  return retryableFromBody(body);
109
103
  const envelope = asRecord(body);
@@ -187,7 +181,7 @@ export function classifyRefreshResponse(status, body) {
187
181
  * 401 → unauthorized (the ONLY refresh trigger)
188
182
  * 403 → forbidden (terminal; carries user_not_provisioned/principal_mismatch)
189
183
  * 5xx / non-200 → retryable
190
- * 200 → unwrap the envelope `result` and narrow to {name, addresses}; a 200
184
+ * 200 → unwrap the envelope `result` and narrow to {name, …}; a 200
191
185
  * that yields no usable identity (no `name`) is `retryable`, NEVER `ok`
192
186
  * (the anti-false-green guard — a partial/garbage 200, or the current
193
187
  * /identity STUB shape with no name, must not read as success).
@@ -197,6 +191,9 @@ export function classifyRefreshResponse(status, body) {
197
191
  * auth-branch bug in this flow.
198
192
  */
199
193
  export function classifyIdentityResponse(status, body) {
194
+ // Not `invalid_request`: IdentityOutcome has no such variant; the tool surfaces it as one.
195
+ if (status === 426)
196
+ return { kind: "refused", message: extractApiError(body).message };
200
197
  if (status === 401)
201
198
  return { kind: "unauthorized" };
202
199
  if (status === 403)
@@ -246,17 +243,17 @@ export async function refreshSession(apiUrl, refreshToken) {
246
243
  }
247
244
  /**
248
245
  * Read the authenticated user's identity from sil-api (the SECOND origin, not
249
- * sil-web): a BODYLESS `GET /identity` answering `{ id, name, country?, addresses }`.
246
+ * sil-web): a BODYLESS `GET /identity` answering `{ status, name, country?, currency?, gender?, language?, address? }`.
250
247
  * Bodyless is the point — the principal is the token subject and nothing else, so
251
248
  * no `agent_id` is sendable and the `principal_mismatch` 403 cannot arise.
252
249
  *
253
250
  * The Bearer header is built HERE and never logged.
254
251
  */
255
- export async function fetchIdentity(silApiUrl, token) {
252
+ export async function fetchIdentity(silApiUrl, token, caller, attempt) {
256
253
  const url = `${stripTrailingSlash(silApiUrl)}/identity`;
257
254
  let res;
258
255
  try {
259
- res = await getJson(url, { authorization: `Bearer ${token}` });
256
+ res = await getJson(url, { authorization: `Bearer ${token}`, ...callerHeaders(caller, attempt) });
260
257
  }
261
258
  catch {
262
259
  return { kind: "retryable" };
@@ -288,7 +285,7 @@ export async function callShopping(silApiUrl, token, route, args, caller, attemp
288
285
  const headers = { authorization: `Bearer ${token}`, ...callerHeaders(caller, attempt) };
289
286
  let res;
290
287
  try {
291
- const timeoutMs = requestTimeoutMs(route);
288
+ const timeoutMs = REQUEST_TIMEOUT_MS;
292
289
  res =
293
290
  route.method === "GET"
294
291
  ? await getJson(url, headers, timeoutMs)
@@ -347,6 +344,11 @@ function routePath(route, args) {
347
344
  const value = args[key];
348
345
  if (typeof value === "string")
349
346
  query.set(key, value);
347
+ else if (Array.isArray(value)) {
348
+ for (const item of value)
349
+ if (typeof item === "string")
350
+ query.append(key, item);
351
+ }
350
352
  }
351
353
  const search = query.toString();
352
354
  return search === "" ? path : `${path}?${search}`;
@@ -443,53 +445,30 @@ export async function refreshAndRetryOnce(first, isUnauthorized, retryWithToken)
443
445
  }
444
446
  /**
445
447
  * Unwrap + narrow a sil-api identity body to a typed `Identity`, or null when it
446
- * carries none. The body may wrap the identity in `result` or return it bare.
447
- *
448
- * An EMPTY `addresses` is a real identity (a provisioned user who has not added
449
- * an address yet) — rejecting it would strand them on a `retryable` no retry can
450
- * clear. The non-empty `name` gate is what keeps a nameless body off `ok`.
448
+ * carries none. The body may wrap the identity in `result` or return it bare. The
449
+ * non-empty `name` gate is what keeps a nameless body off `ok`.
451
450
  */
452
451
  function extractIdentity(body) {
453
452
  const envelope = asRecord(body);
454
453
  if (envelope === null)
455
454
  return null;
456
- const result = asRecord(envelope["result"]);
457
- const source = result ?? envelope;
455
+ const source = asRecord(envelope["result"]) ?? envelope;
458
456
  const name = source["name"];
459
457
  if (typeof name !== "string" || name.length === 0)
460
458
  return null;
461
- const rawAddresses = source["addresses"];
462
- if (!Array.isArray(rawAddresses))
463
- return null;
464
- const addresses = rawAddresses.filter((a) => asRecord(a) !== null);
465
- // The profile halves are NOT a gate: a read that carries neither is a buyer who
466
- // has told sil nothing yet, and `[]` says exactly that — refusing here would
467
- // strand them on a `retryable` no retry can clear.
468
- const measurements = plainObjects(source["measurements"]);
469
- const preferences = plainObjects(source["preferences"]);
470
- // `country`, `gender` and `currency` are optional on the read and pass through only as
471
- // strings — an absent or non-string one is dropped, never coerced or inferred. The VALUE
472
- // is the route's to decide: a literal allow-list here would drop a vocabulary sil adds.
473
- const country = source["country"];
474
- const gender = source["gender"];
475
- const currency = source["currency"];
459
+ // Optional fields pass through only as the right shape — an absent or malformed one is
460
+ // dropped, never coerced. The VALUES are the route's to decide.
461
+ const address = asRecord(source["address"]);
462
+ const optional = (key) => typeof source[key] === "string" ? { [key]: source[key] } : {};
476
463
  return {
477
464
  name,
478
- addresses,
479
- measurements,
480
- preferences,
481
- ...(typeof country === "string" ? { country } : {}),
482
- ...(typeof gender === "string" ? { gender } : {}),
483
- ...(typeof currency === "string" ? { currency } : {}),
465
+ ...optional("country"),
466
+ ...optional("gender"),
467
+ ...optional("currency"),
468
+ ...optional("language"),
469
+ ...(address !== null ? { address: address } : {}),
484
470
  };
485
471
  }
486
- /** The elements of `value` that are plain objects, as `addresses` are filtered:
487
- * absent or shapeless is `[]`, never a partial read of a malformed entry. */
488
- function plainObjects(value) {
489
- if (!Array.isArray(value))
490
- return [];
491
- return value.filter((e) => asRecord(e) !== null);
492
- }
493
472
  /** Pull the actionable reason out of a 403 body (`user_not_provisioned` /
494
473
  * `principal_mismatch`), defaulting to a generic marker when the shape is
495
474
  * unexpected — the tool surfaces this to drive the right recovery hint. */
@@ -561,16 +540,7 @@ function extractUser(raw) {
561
540
  ...(typeof name === "string" ? { name } : {}),
562
541
  };
563
542
  }
564
- /**
565
- * A non-null plain object, or null for anything else (incl. arrays/primitives).
566
- *
567
- * The array arm decides an OUTCOME at exactly one site, and it is not a body gate:
568
- * {@link extractIdentity} filters `addresses` through this PER ELEMENT, so the return
569
- * value is membership rather than a branch — without the arm a bare array survives and
570
- * ships as one of the buyer's own addresses (pinned in `whoami.integration.test.ts`).
571
- * At the body sites it changes nothing, because each reads a named key and a parsed
572
- * array has none; the element site is the whole reason it stays.
573
- */
543
+ /** A non-null plain object, or null for anything else (incl. arrays/primitives). */
574
544
  function asRecord(value) {
575
545
  return value !== null && typeof value === "object" && !Array.isArray(value)
576
546
  ? value
@@ -17,7 +17,7 @@ export function jsonResult(data, ...extra) {
17
17
  return {
18
18
  content: [data, ...extra].map((part) => ({
19
19
  type: "text",
20
- text: JSON.stringify(part, null, 2),
20
+ text: JSON.stringify(part),
21
21
  })),
22
22
  };
23
23
  }