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
@@ -1,10 +1,7 @@
1
1
  /**
2
- * The eleven `shopping_*` tools, 1:1 with the sil-api catalog, brief and profile routes.
3
- *
4
- * A projection on the way back would drop exactly the fields the agent's honesty reading
5
- * is computed from (`fit`, `unknown`, `variants`, `printed`) while looking healthy, so the
6
- * body crosses verbatim. A new `registerXTools` group has to be hand-wired into three guards
7
- * or it silently NARROWS them (CLAUDE.md), which is why all eleven live in one group.
2
+ * The twelve `shopping_*` tools, 1:1 with the sil-api user, brief and catalog routes.
3
+ * Bodies cross verbatim: a projection would drop the fields the honesty reading is
4
+ * computed from (`fit`, `unknown`, `variants`) while looking healthy.
8
5
  */
9
6
  import { requestSchema } from "../lib/artifacts.js";
10
7
  import { readConfig } from "../lib/credentials.js";
@@ -18,287 +15,135 @@ import { readInstalledVersion } from "../lib/version-advisory.js";
18
15
  const SEARCH_TOOL = "shopping_search";
19
16
  export const SHOPPING_TOOLS = [
20
17
  {
21
- name: "shopping_domain_search",
22
- method: "GET",
23
- path: "/catalog/domains",
24
- query: ["q"],
25
- label: "Read sil's registry for a domain",
26
- description: "What sil holds, and where it shelves it: read the registry in the buyer's own"
27
- + " words. `matches` are the domains that match, each with its path and a line on how"
28
- + " the thing is bought — judge fit on `about`, then take that path verbatim, or"
29
- + " descend under a broader one, never a sibling of a path that already stands. `tree`"
30
- + " is every standing path grouped by family: hang a new leaf where a specialist shop"
31
- + " would shelve it, and see that a setup of several things is several leaves."
32
- + " `matches: []` is the ONLY answer that licenses shopping_domain_create, and a"
33
- + " non-ok status is not an empty one. At most two reads per domain, then"
34
- + " shopping_domain_get for the document and the keys of the path you take.",
35
- },
36
- {
37
- name: "shopping_domain_get",
38
- ...DOMAIN_GET_ROUTE,
39
- label: "Read a domain's document and keys",
40
- recovery: { not_found: "shopping_domain_search" },
41
- description: "sil's own document on how this thing is bought well — read it before you ask the"
42
- + " buyer anything, and again when a want fits no key: the document GROWS as sil reads"
43
- + " pages. `guide` is markdown: what it is bought on, what goes wrong and what that"
44
- + " costs the buyer, what to trust, and what buying it online takes. `name` is its one"
45
- + " English name and `labels` the market's own words for it — read them, never send"
46
- + " them. `specs` are the keys it is bought by and `seller_specs` the seller terms it"
47
- + " is bought with; one read hands you both. Each key's `description` says how that"
48
- + " key moves the fit: what it decides, what goes wrong at either end, and how a"
49
- + " buyer's own fact becomes its value. Each key states its type, its operators, its"
50
- + " unit, any closed set, the `step` a number moves by, and `forms` — what pages"
51
- + " print, mapped to the value. Send that key and one of those operators, never a"
52
- + " synonym you coined: `specs` go on the brief and to shopping_search,"
53
- + " `seller_specs` on the brief's `seller` domain, where shopping_offers reads"
54
- + " them. variant_spec marks the key an option is picked on (a size, a"
55
- + " colour), answered under each product's variants; product_spec tells one product"
56
- + " from the next. The root `product` always stands and carries the universals every"
57
- + " domain inherits; a path that does not stand answers not_found, and the recovery is"
58
- + " to read the registry again in their words.",
18
+ name: "shopping_user_read",
19
+ method: "POST",
20
+ path: "/user/read",
21
+ label: "Read what sil keeps about the buyer",
22
+ description: "Every row sil keeps about the buyer — measurements, memories, preferences, purchases"
23
+ + " — each with its `id`, what it gives back and its source. Read it once per"
24
+ + " conversation before asking anything, and before any forget; say a row when you use it.",
59
25
  },
60
26
  {
61
- name: "shopping_domain_create",
27
+ name: "shopping_user_remember",
62
28
  method: "POST",
63
- path: "/catalog/domains",
64
- label: "Write a domain sil does not hold",
65
- // A colliding path means the vocabulary is already there, so search that same path.
66
- recovery: { already_exists: "shopping_search" },
67
- description: "The FALLBACK, and the one permanent global write in sil: a curated domain already"
68
- + " carries a document, and this writes one for a domain it does not hold. First: a"
69
- + " shopping_domain_search read that came back `matches: []`, and research on how the"
70
- + " domain is bought (never products). Hang the leaf where the `tree` shows its"
71
- + " family: different keys are a different leaf, another value of the same keys is a"
72
- + " value. `guide` is markdown every later buyer inherits: what the thing is bought"
73
- + " on, what goes wrong and what that costs the buyer, and what buying it online takes"
74
- + " — never \"go to a shop\". Each key's `description` does the same for one key. `name`"
75
- + " is its one English name, `labels` the words shops print; a spec carries `step`,"
76
- + " the increment its numbers move by, and `forms`, a printed form mapped to its"
77
- + " value. Mark variant_spec on the key an option is picked on, product_spec on one"
78
- + " telling products apart. Coin only keys a PRODUCT is bought by: seller terms are"
79
- + " never yours to coin, and shopping_domain_get answers them as `seller_specs`. You"
80
- + " inherit every ancestor's key and may not rename one: re-declare only to change its"
81
- + " unit, values or mark for your subtree; stating nothing new it answers `inherited:"
82
- + " true`, and a key naming a standing one binds and answers `bound_from`. A refusal"
83
- + " names the standing thing and the fix.",
29
+ path: "/user/remember",
30
+ label: "Keep what lasts about the buyer",
31
+ description: "Keep what is lasting about the buyer, in the turn that settles it, and say so with"
32
+ + " \"forget that\" as the undo. What changes only this buy rides on the call or in a"
33
+ + " brief, never here.",
84
34
  },
85
35
  {
86
- name: "shopping_brief_create",
36
+ name: "shopping_user_forget",
87
37
  method: "POST",
88
- path: "/briefs/create",
89
- label: "Open the session's brief",
90
- description: "Once per SESSION: open the one brief this conversation works from — across"
91
- + " every domain the buyer asks about, never one per domain — and hold the `id`"
92
- + " it answers for the rest of the session, because every search and every offers"
93
- + " call names it. A new chat opens its own AFTER shopping_brief_read has shown what"
94
- + " is on file: carry every spec an earlier brief still holds true into this one, then"
95
- + " name that carry in the first shopping_brief_edit `decision`. `title` names the job"
96
- + " in a few words. `narrative` is the spec of the buy in the buyer's own terms — what"
97
- + " a good buy looks like for THEM, what it has to do for them, what would make it a"
98
- + " bad one — and a want no keyed spec can carry lives there and still counts. An"
99
- + " optional first `domain` with `specs` writes what they have already said: a"
100
- + " domain path carries that domain's product specs, `seller` carries the seller"
101
- + " specs, and each spec is a key and an operator shopping_domain_get listed whose"
102
- + " `reason` quotes the buyer VERBATIM — their own words, or the measurement the"
103
- + " guide converted — never a paraphrase and never a want they did not state. On"
104
- + " anything worn, the `gender` sil_whoami holds is a product spec in the registry's"
105
- + " own spelling — male → `gender eq mens`, female → `gender eq womens` — asked once"
106
- + " where the profile answers none or `other`, and never inferred. Everything after"
107
- + " this is shopping_brief_edit.",
38
+ path: "/user/forget",
39
+ label: "Erase what sil keeps, on the buyer's word",
40
+ description: "Erase rows by `ids`, or everything with `all`, only after saying what goes and the"
41
+ + " buyer saying yes. The answer states what went and what sil cannot reach.",
108
42
  },
109
43
  {
110
- name: "shopping_brief_edit",
44
+ name: "shopping_brief_write",
111
45
  method: "POST",
112
- path: "/briefs/edit",
113
- label: "Write a want or a decision into the brief",
114
- // The id is the only thing a 404 can be about here, and the bare read lists what is.
46
+ path: "/briefs/write",
47
+ label: "Open or update a brief",
115
48
  recovery: { not_found: "shopping_brief_read" },
116
- description: "The brief's write: put every want the buyer states into the brief as it is settled,"
117
- + " with `reason` quoting their own words VERBATIM — never a"
118
- + " paraphrase, never a want they did not state. A want that reaches"
119
- + " no brief is a want the next call drops. A MEASUREMENT is never the spec: 27.2 cm is"
120
- + " the buyer's, and the spec is the size the thing is sold in —"
121
- + " `mondo_size in [27, 27.5]`, with that measurement as its `reason`; the key's"
122
- + " `description` says how one becomes the other."
123
- + " One write per `domain`: a domain path carries"
124
- + " that domain's product specs, `price` among them, and `seller` carries the"
125
- + " seller specs, which belong to the whole brief. `specs` REPLACE every spec on the"
126
- + " keys they name — a range is the two rows on its key — `remove` names the keys"
127
- + " whose specs go, and `narrative` replaces the whole narrative. When the buyer"
128
- + " changes their mind — and only then — send the new spec together with `decision`:"
129
- + " one sentence ABOUT them, never in their voice, saying what they changed and"
130
- + " why. A new want's words are its spec's `reason`, never a `decision`, and never a"
131
- + " log of what you have just written down."
132
- + " Send `status: \"closed\"` when the job is over. An"
133
- + " invalid_request names the key and shows a spec on it that passes — fix that row"
134
- + " and send it again, and never give the want up. A brief id that is not the"
135
- + " buyer's answers not_found; shopping_brief_read with no `id` lists their briefs.",
49
+ description: "Write the requirements of a buy that spans asks or conversations: a title, a"
50
+ + " narrative in the buyer's terms and specs by domain. Without `id` it opens a brief"
51
+ + " and answers its `id`; with one it updates it.",
136
52
  },
137
53
  {
138
54
  name: "shopping_brief_read",
139
55
  method: "POST",
140
56
  path: "/briefs/read",
141
- label: "Read the brief, or list the buyer's briefs",
142
- description: "The first read of a new chat: with no `id` it answers the buyer's briefs,"
143
- + " newest first, each with its title, its domains and when it was last written."
144
- + " Call it with sil_whoami before you ask the buyer anything, so a job already"
145
- + " under way is continued rather than interviewed a second time. With an `id` it"
146
- + " answers that brief whole: the title, the narrative, every spec under the domain"
147
- + " it sits on (`seller` for the seller specs), and the decisions already taken with"
148
- + " the time of each. What comes back is a READ: it says what the buyer has already"
149
- + " settled so you ask none of it again, and the specs still true are carried into"
150
- + " this session's own brief with shopping_brief_create — the search runs on that"
151
- + " one, never on an earlier session's. New wants go in through shopping_brief_edit.",
57
+ label: "Read a brief, or list the buyer's briefs",
58
+ description: "Pick a buy up again: with an `id` the whole brief, without one the buyer's briefs,"
59
+ + " newest first.",
60
+ },
61
+ {
62
+ name: "shopping_domain_search",
63
+ method: "GET",
64
+ path: "/catalog/domains",
65
+ query: ["q"],
66
+ label: "Find the place for a thing",
67
+ description: "Place a thing: send `q`, what it is called, in English, and get the leaves it"
68
+ + " could be, best first. An empty answer means sil does not carry it yet.",
152
69
  },
153
70
  {
154
- name: "shopping_profile_edit",
71
+ name: "shopping_domain_get",
72
+ ...DOMAIN_GET_ROUTE,
73
+ label: "Read a place's specs",
74
+ recovery: { not_found: "shopping_domain_search" },
75
+ description: "What decides the buy in a leaf, from a path shopping_domain_search answered: the"
76
+ + " keys it is bought by, their operators and units, and the seller terms. Send those"
77
+ + " keys, never a synonym you coined.",
78
+ },
79
+ {
80
+ name: "shopping_content",
155
81
  method: "POST",
156
- path: "/profile/edit",
157
- label: "Write what is true of the buyer",
158
- description: "The person rather than the job: write what is true of the buyer whatever"
159
- + " they are buying, the moment they say it and BEFORE the next search — only what"
160
- + " they stated UNAMBIGUOUSLY about themselves. A phrase that could mean two things"
161
- + " (\"wide forefoot and bit short\" — the foot, or the buyer?) is asked about, never"
162
- + " written here, because a lasting fact written wrong follows them into every"
163
- + " domain. Every `name` is lower snake_case: `foot_length`, never \"foot length\"."
164
- + " A"
165
- + " `measurements` entry is a number with its `unit`, or a size exactly as it is"
166
- + " printed; a `preferences` entry is a lasting taste in the buyer's own words."
167
- + " An entry replaces the one of the same `name`, and `remove` names the entries"
168
- + " that stopped being true. `currency` is the ISO 4217 code they price in, and"
169
- + " every money row naming none means it: \"my prices in dollars from now on\" is"
170
- + " `currency: \"USD\"`, which changes which offers come first and never a price —"
171
- + " sil converts nothing. sil_whoami reads all of it back, so a fact written here"
172
- + " is one you never ask for again. What belongs to THIS job — a budget, a size for"
173
- + " these boots — is the brief's, through shopping_brief_edit: a measurement is the"
174
- + " buyer's, and the spec the domain's guide turns it into carries that"
175
- + " measurement as its `reason`.",
82
+ path: "/catalog/content",
83
+ label: "Grep what sil holds about it",
84
+ recovery: { not_found: "shopping_domain_search" },
85
+ description: "Grep sil's library under a `path` for `q`: its own guides and the sources it read,"
86
+ + " as whole passages quoted verbatim. Empty `passages` means sil holds nothing on it.",
176
87
  },
177
88
  {
178
89
  name: SEARCH_TOOL,
179
90
  method: "POST",
180
91
  path: "/catalog/search",
181
- label: "Search sil in one settled domain",
182
- // A 404 here is the `brief` id and nothing else: a domain that does not stand is
183
- // refused as `invalid_request`, naming the path.
92
+ label: "Search sil's products",
184
93
  recovery: { not_found: "shopping_brief_read" },
185
- description: "The products that fit the brief, in one settled domain. Search as often as the job"
186
- + " needs — a re-worded `query`, a different `n` — it is cheap and it is how you learn"
187
- + " what is out there. Send `brief` (the session's brief id) on EVERY call,"
188
- + " the domain path, and `query` — the thing as a shop lists it and the numbers"
189
- + " that pick the product, never a sentence; a budget, a market, a unit, a standard's"
190
- + " name, \"in stock\" and \"online\" are specs, and cost most of the offers."
191
- + " `n` counts VARIANTS — one size, one option — max 10. `specs`: every product"
192
- + " spec the brief holds for this domain, all of them and UNCHANGED — never a looser"
193
- + " bound, never one it does not hold — money a decimal STRING (`\"300\"`, never 300)."
194
- + " The brief's `seller` specs are shopping_offers' to read off the brief, never on"
195
- + " the search. Keep the server's order, never re-rank; quote each variant's OWN"
196
- + " `price` with its size. `fit` answers the ask key by key: the value sil verified,"
197
- + " or \"unknown\" where it holds none — a gap to dig into with shopping_product_get,"
198
- + " never a failed one."
199
- + " `host` is the shop; `printed` is that page's own pairs, never verified —"
200
- + " say \"the page says\". A `variants` entry with no option"
201
- + " values is a listing whose sizes sil has not read: say so — it prices like any"
202
- + " other. sil never says what it left out, so a want left off `specs` is one you will"
203
- + " not know you missed.",
94
+ description: "The products that fit, by what decides the buy, in one leaf or the kind above"
95
+ + " several. Search as often as the job needs; `fit` states per key what sil verified"
96
+ + " and what it holds nothing on.",
204
97
  },
205
98
  {
206
99
  name: "shopping_product_get",
207
100
  method: "POST",
208
101
  path: "/catalog/product",
209
102
  label: "Read the whole dossier on a shortlisted variant",
210
- description: "The dossier: send 1–10 variant ids from a shopping_search answer and get"
211
- + " the whole of what sil holds for each — the title, the maker, the page's own"
212
- + " description, the images, every key sil holds for it (not only the ones you"
213
- + " asked about), and `sources` naming which site each reading came from and when."
214
- + " This is where a key the search answered \"unknown\" is dug out. A variant with no"
215
- + " option values is a listing whose sizes sil has not read, and its id opens here"
216
- + " like any other: the answer carries that page whole, so the sizes it prints are"
217
- + " the page's own words — say the size is unread, never that it is in stock."
218
- + " Compare the shortlist on this before recommending, and quote a source's date"
219
- + " rather than implying sil read it just now. An id sil cannot place is simply"
220
- + " absent from the answer — say that listing could not be placed, and never"
221
- + " substitute another product. Ids are opaque: pass them back exactly as sil"
222
- + " minted them, and never read one.",
103
+ description: "One product whole: send 1–3 variant ids from a search and get everything sil holds for each,"
104
+ + " with the source and date of every reading.",
223
105
  },
224
106
  {
225
107
  name: "shopping_offers",
226
108
  method: "POST",
227
109
  path: "/catalog/offers",
228
110
  label: "List who sells a variant, at what price and on what terms",
229
- // Same as the search: the only 404 this route answers is a brief that is not
230
- // the buyer's.
231
111
  recovery: { not_found: "shopping_brief_read" },
232
- description: "Who sells it, at what price, on what terms — the only live read of a price."
233
- + " Worth a call once the buyer wants something: pricing a whole shortlist buries the"
234
- + " fit answer they asked for. Send `brief` (the session's brief id) and 1–10 picked"
235
- + " variant ids, and nothing else: sil reads the brief's `seller` specs, its `price`"
236
- + " ceiling, the buyer's default address and their currency itself, so a seller term"
237
- + " the buyer states goes on the brief. The first three picks are also looked for on"
238
- + " the web, so put the one they want first; the rest answer from shops sil holds. A"
239
- + " variant with no option values is priced as its page prints. An offer is the pick"
240
- + " at one shop, read live: the seller, the price in its own currency (sil converts"
241
- + " nothing), its availability, the listing URL, `observed_at`, and `seller_fit`:"
242
- + " `ships` always — serviceable, not_serviceable or unknown for that address — and"
243
- + " each brief seller key where sil holds the seller's value. An offer over the"
244
- + " brief's price in that price's currency is left out; one in another currency was"
245
- + " not tested against it — say so. `unknown` keeps the offer: say sil could not"
246
- + " confirm shipping. A key absent from `seller_fit` is a term sil has not read. The"
247
- + " order is the buyer's currency and market first, then sellers known to reach them,"
248
- + " then the rest — keep it, never re-rank. Several offers ARE the price spread, and"
249
- + " the spread is the answer.",
112
+ description: "Who sells the picked variants, at what price and on what terms, each price dated —"
113
+ + " a price check too; `confirm` re-reads a hand-off listing now.",
250
114
  },
251
115
  {
252
116
  name: "shopping_seller_get",
253
117
  method: "POST",
254
118
  path: "/catalog/sellers",
255
119
  label: "Read one seller's whole terms",
256
- description: "One seller's WHOLE terms: send 1–10 seller ids from shopping_offers, and"
257
- + " nothing else. Each seller comes back with its name, host and country, `specs` —"
258
- + " every seller key sil holds a value for, base and branch, as the dossier's `specs`"
259
- + " are a product's — and `ships`, which answers for the buyer's default address:"
260
- + " serviceable (sil read a route covering it), not_serviceable (sil read this"
261
- + " seller's policy and it excludes it), or unknown (sil has read nothing about this"
262
- + " seller). `unknown` is an ordinary answer that keeps the seller — say sil could not"
263
- + " confirm shipping, and hand the buyer the listing; an empty `specs` is the same"
264
- + " answer about its terms. Where sil has read them, `shipping` carries the routes"
265
- + " with their cost, free-over threshold and days, and `returns` the window and any"
266
- + " restocking fee; a term the page never stated is simply absent, which is never zero"
267
- + " and never free. A `policy_url` of null means the terms were read off a product"
268
- + " page and sil holds no policy page. This is the details read: whether an offer"
269
- + " meets the buyer's own seller rows is `seller_fit` on that offer, from"
270
- + " shopping_offers.",
120
+ description: "A seller's terms and standing: send 1–10 seller ids from shopping_offers and get"
121
+ + " their shipping, returns and reviews where sil has read them.",
271
122
  },
272
123
  ];
273
124
  /**
274
- * Registers the eleven, reading each one's request artifact off disk as it goes.
275
- *
276
- * That read is the ONE exception to "register() opens nothing": eleven synchronous
277
- * `readFileSync`s that return immediately and hold no resource open, exactly as
278
- * `ensureDataDir`'s `mkdirSync` does. It is deliberately eager — an unreadable artifact
279
- * is a broken build, and failing loud at load beats a tool whose `parameters` the host
280
- * has already published by the time anyone finds out.
281
- *
282
- * Each tool is a factory because the host hands the conversation and the model only to a
283
- * factory, once per agent run; every call that run makes says who is calling.
125
+ * Registers the twelve, reading each request artifact off disk eagerly: an unreadable
126
+ * artifact is a broken build and should fail at load. Each tool is a factory because the
127
+ * host hands the conversation and model only to a factory, once per agent run.
284
128
  */
285
129
  export function registerCatalogTools(api) {
286
130
  const pluginVersion = readInstalledVersion();
287
131
  const openclawVersion = readHostVersion(api) ?? undefined;
288
132
  for (const tool of SHOPPING_TOOLS) {
289
133
  const parameters = requestSchema(tool.name);
290
- api.registerTool((ctx) => {
291
- const { provider, modelId } = ctx.activeModel ?? {};
292
- const run = {
293
- pluginVersion,
294
- ...(openclawVersion !== undefined ? { openclawVersion } : {}),
295
- ...(ctx.sessionId ? { sessionId: ctx.sessionId } : {}),
296
- ...(provider && modelId ? { model: `${provider}/${modelId}` } : {}),
297
- };
298
- return defineTool(api, tool, parameters, run);
299
- }, { name: tool.name });
134
+ api.registerTool((ctx) => defineTool(api, tool, parameters, runOf(ctx, pluginVersion, openclawVersion)), { name: tool.name });
300
135
  }
301
136
  }
137
+ /** Who is calling, as the host hands it to a tool factory once per agent run. */
138
+ export function runOf(ctx, pluginVersion, openclawVersion) {
139
+ const { provider, modelId } = ctx.activeModel ?? {};
140
+ return {
141
+ pluginVersion,
142
+ ...(openclawVersion !== undefined ? { openclawVersion } : {}),
143
+ ...(ctx.sessionId ? { sessionId: ctx.sessionId } : {}),
144
+ ...(provider && modelId ? { model: `${provider}/${modelId}` } : {}),
145
+ };
146
+ }
302
147
  function defineTool(api, tool, parameters, run) {
303
148
  return {
304
149
  name: tool.name,
@@ -314,17 +159,14 @@ function defineTool(api, tool, parameters, run) {
314
159
  }
315
160
  if (tool.name === SEARCH_TOOL)
316
161
  bufferPage(api, callId, called.body);
317
- // VERBATIM, and the advisory rides its own block: the body's keys are the API's
318
- // contract, so nothing of ours may sit beside them.
162
+ // The advisory rides its own block: nothing of ours may sit beside the body's keys.
319
163
  return jsonResult(called.body, ...wiringAdvisoryBlocks(api));
320
164
  },
321
165
  };
322
166
  }
323
167
  /**
324
- * Buffer an `ok` search page for a paired client to pull by this exact `callId`
325
- * (`sil.search_results`). A PURE SIDE EFFECT: the result returned to the agent is
326
- * byte-identical to what every channel got before this existed. Only a body that
327
- * actually carries its `products` list is stored — the pull surface counts it.
168
+ * Buffer an `ok` search page for a paired client to pull by `callId`
169
+ * (`sil.search_results`). A pure side effect: the agent's result is unchanged.
328
170
  */
329
171
  function bufferPage(api, callId, body) {
330
172
  const principal = readConfig()?.user?.id;
@@ -338,9 +180,8 @@ function bufferPage(api, callId, body) {
338
180
  }
339
181
  putSearchResult(callId, body, principal);
340
182
  }
341
- /** Why this `callId` will resolve nothing, logged where the decision is made. The pull
342
- * says only `not_found` — deliberately — so this line is the whole of an operator's
343
- * account of a search a client could not render. */
183
+ /** Why this `callId` will resolve nothing: the pull answers only `not_found`, so this
184
+ * log line is the operator's whole account. */
344
185
  function skipped(api, callId, reason) {
345
186
  logSearchResults(api, "info", "skipped", { callId, reason });
346
187
  }
@@ -1,7 +1,9 @@
1
1
  import { Type } from "typebox";
2
2
  import { getWebUrl, getWebUrlSource, getApiUrl } from "../lib/config.js";
3
3
  import { clearTokens, getTokensPath, hasTokens, readConfig, readTokens, writeConfig, writeTokens, } from "../lib/credentials.js";
4
- import { wiringAdvisories } from "../lib/host-wiring.js";
4
+ import { readHostVersion, wiringAdvisories, wiringAdvisoryBlocks } from "../lib/host-wiring.js";
5
+ import { readInstalledVersion } from "../lib/version-advisory.js";
6
+ import { runOf } from "./catalog.js";
5
7
  import { deriveChallenge, newSessionId, newVerifier } from "../lib/pkce.js";
6
8
  import { POLL_DEADLINE_MS, POLL_INTERVAL_MS, startPoll, } from "../lib/poller.js";
7
9
  import { claimSession, fetchIdentity, refreshAndRetryOnce, stripTrailingSlash, } from "../lib/sil-client.js";
@@ -94,85 +96,80 @@ function registerRegister(api) {
94
96
  * result and is never logged; tokens reach neither.
95
97
  */
96
98
  function registerWhoami(api) {
97
- api.registerTool({
98
- name: "sil_whoami",
99
- label: "Who am I on sil",
100
- description: "The buyer's name, country, `gender`, `currency` and the addresses on file, and"
101
- + " the `measurements` and `preferences` sil already holds for them — read live from"
102
- + " sil with the credentials sil_register stored, a stale session token refreshed"
103
- + " once and the read retried. `gender` is `male`, `female` or `other`, and is"
104
- + " absent where the buyer never stated one; on anything worn it is the product"
105
- + " spec `gender` in the registry's own spelling (male → `mens`, female →"
106
- + " `womens`), asked once where this answers none and never inferred. `currency` is"
107
- + " the ISO 4217 code they price in, absent where nothing on file says it: a money"
108
- + " row that means theirs leaves `currency` off — with none on file, it names its"
109
- + " own — and sil converts nothing. Call it at the start of a chat: it"
110
- + " says where the buyer is, what they price in, how they measure and what they"
111
- + " lastingly prefer, and you never ask them for anything it answers."
112
- + " shopping_profile_edit is what writes those last three back. If they are not"
113
- + " registered, or the session is past refreshing, the result names the recovery"
114
- + " (sil_register).",
115
- parameters: Type.Object({}),
116
- async execute() {
117
- // 1 — no tokens on disk is the SAME state for a never-registered buyer and
118
- // for one whose token write failed in this process, so the in-process marker
119
- // is the only thing that tells the two apart.
120
- const stored = readTokens();
121
- if (stored === null) {
122
- const failure = getPersistFailure();
123
- return failure !== null ? persistenceFailed(failure) : notRegistered();
124
- }
125
- // A staging/self-host web origin is legitimate, so it is surfaced and warned
126
- // about, never rejected — a wrong one is then diagnosable before anything 404s.
127
- const webOrigin = getWebUrl();
128
- const webOriginSource = getWebUrlSource();
129
- if (webOriginSource !== "default") {
130
- api.logger.warn("sil_whoami_web_origin_override", {
131
- web_origin: webOrigin,
132
- web_origin_source: webOriginSource,
133
- });
134
- }
135
- const originBlock = {
136
- web_origin: webOrigin,
137
- web_origin_source: webOriginSource,
138
- };
139
- // 2 — read identity; on a 401 refresh-and-retry ONCE, shared with every
140
- // `shopping_*` call so the recovery cannot drift between tools.
141
- const first = await fetchIdentity(getApiUrl(), stored.access_token);
142
- const recovered = await refreshAndRetryOnce(first, (o) => o.kind === "unauthorized", (accessToken) => fetchIdentity(getApiUrl(), accessToken));
143
- switch (recovered.kind) {
144
- case "result":
145
- // Logs-only, never a payload field: a session thrashing through silent
146
- // 401 recoveries is invisible otherwise.
147
- if (recovered.refreshed)
148
- api.logger.info("sil_whoami_refreshed", {});
149
- return identityOutcomeToResult(api, recovered.outcome, originBlock);
150
- case "must_reregister":
151
- // Clear the known-dead pair so its stale presence cannot block the
152
- // sil_register recovery; an empty re-read has nothing to clear.
153
- if (recovered.reason === "invalid_grant")
99
+ const pluginVersion = readInstalledVersion();
100
+ const openclawVersion = readHostVersion(api) ?? undefined;
101
+ api.registerTool((ctx) => {
102
+ const run = runOf(ctx, pluginVersion, openclawVersion);
103
+ return {
104
+ name: "sil_whoami",
105
+ label: "Who am I on sil",
106
+ description: "Who is signed in, where they are and what they price in: `name`, `country`,"
107
+ + " `currency`, `gender`, `language` and the default `address`, each absent where sil"
108
+ + " holds none. Fast: call it freely, and never ask the buyer for what it answers."
109
+ + " `gender` on anything worn is the product spec `gender` (male → `mens`, female →"
110
+ + " `womens`), asked once where it answers none. If they are not registered, or the"
111
+ + " session is past refreshing, the result names the recovery (sil_register).",
112
+ parameters: Type.Object({}),
113
+ async execute(callId) {
114
+ // 1 — no tokens on disk is the SAME state for a never-registered buyer and
115
+ // for one whose token write failed in this process, so the in-process marker
116
+ // is the only thing that tells the two apart.
117
+ const stored = readTokens();
118
+ if (stored === null) {
119
+ const failure = getPersistFailure();
120
+ return failure !== null ? persistenceFailed(failure) : notRegistered();
121
+ }
122
+ // A staging/self-host web origin is legitimate, so it is warned
123
+ // about, never rejected — a wrong one is then diagnosable before anything 404s.
124
+ const webOrigin = getWebUrl();
125
+ const webOriginSource = getWebUrlSource();
126
+ if (webOriginSource !== "default") {
127
+ api.logger.warn("sil_whoami_web_origin_override", {
128
+ web_origin: webOrigin,
129
+ web_origin_source: webOriginSource,
130
+ });
131
+ }
132
+ // 2 — read identity; on a 401 refresh-and-retry ONCE, shared with every
133
+ // `shopping_*` call so the recovery cannot drift between tools.
134
+ const caller = { ...run, toolCallId: callId };
135
+ const first = await fetchIdentity(getApiUrl(), stored.access_token, caller, 1);
136
+ const recovered = await refreshAndRetryOnce(first, (o) => o.kind === "unauthorized", (accessToken) => fetchIdentity(getApiUrl(), accessToken, caller, 2));
137
+ switch (recovered.kind) {
138
+ case "result":
139
+ // Logs-only, never a payload field: a session thrashing through silent
140
+ // 401 recoveries is invisible otherwise.
141
+ if (recovered.refreshed)
142
+ api.logger.info("sil_whoami_refreshed", {});
143
+ return identityOutcomeToResult(api, recovered.outcome);
144
+ case "must_reregister":
145
+ // Clear the known-dead pair so its stale presence cannot block the
146
+ // sil_register recovery; an empty re-read has nothing to clear.
147
+ if (recovered.reason === "invalid_grant")
148
+ clearTokens();
149
+ api.logger.info("sil_whoami_must_reregister", { cause: recovered.reason });
150
+ return mustReregister();
151
+ case "second_unauthorized":
152
+ // A freshly-rotated token STILL rejected is structurally dead — terminal,
153
+ // never another refresh. Clear the dead pair.
154
154
  clearTokens();
155
- api.logger.info("sil_whoami_must_reregister", { cause: recovered.reason });
156
- return mustReregister();
157
- case "second_unauthorized":
158
- // A freshly-rotated token STILL rejected is structurally dead — terminal,
159
- // never another refresh. Clear the dead pair.
160
- clearTokens();
161
- api.logger.info("sil_whoami_must_reregister", { cause: "retry_unauthorized" });
162
- return mustReregister();
163
- case "retryable":
164
- api.logger.info("sil_whoami_refresh_retryable", {});
165
- return transient();
166
- }
167
- },
168
- });
155
+ api.logger.info("sil_whoami_must_reregister", { cause: "retry_unauthorized" });
156
+ return mustReregister();
157
+ case "retryable":
158
+ api.logger.info("sil_whoami_refresh_retryable", {});
159
+ return transient();
160
+ }
161
+ },
162
+ };
163
+ }, { name: "sil_whoami" });
169
164
  }
170
- /** Map a non-401 identity outcome to the agent-facing result. The origin block
171
- * rides the SUCCESS payload only — pre-failure diagnosis is its whole point. */
172
- function identityOutcomeToResult(api, outcome, originBlock) {
165
+ /** Map a non-401 identity outcome to the agent-facing result. */
166
+ function identityOutcomeToResult(api, outcome) {
173
167
  switch (outcome.kind) {
174
168
  case "ok":
175
- return identityResult(api, outcome.identity, originBlock);
169
+ return jsonResult({ status: "ok", ...outcome.identity }, ...wiringAdvisoryBlocks(api));
170
+ case "refused":
171
+ api.logger.info("sil_whoami_refused", {});
172
+ return jsonResult({ status: "invalid_request", message: outcome.message });
176
173
  case "forbidden":
177
174
  // A token that maps to no account is structurally dead, so clear it or the
178
175
  // sil_register recovery answers `already_registered` and strands the buyer.
@@ -190,18 +187,8 @@ function identityOutcomeToResult(api, outcome, originBlock) {
190
187
  return mustReregister();
191
188
  }
192
189
  }
193
- /** Success: `identity` carries the buyer's name, country, gender and currency (each when
194
- * the read has one), addresses, measurements and preferences — no token, no Bearer header. */
195
- function identityResult(api, identity, originBlock) {
196
- return jsonResult({
197
- status: "ok",
198
- identity,
199
- ...originBlock,
200
- ...wiringAdvisories(api),
201
- });
202
- }
203
190
  /** Not registered: a distinct, actionable outcome naming the recovery tool. No
204
- * identity fields (name/addresses) so the agent can't mistake it for a read. */
191
+ * identity fields (name/address) so the agent can't mistake it for a read. */
205
192
  function notRegistered() {
206
193
  return jsonResult({
207
194
  status: "not_registered",