sil-openclaw 0.6.0 → 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 (38) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +12 -11
  3. package/SECURITY.md +3 -3
  4. package/dist/lib/shopping-call.js +5 -1
  5. package/dist/lib/sil-client.js +34 -62
  6. package/dist/lib/tool-result.js +1 -1
  7. package/dist/tools/catalog.js +83 -239
  8. package/dist/tools/identity.js +74 -87
  9. package/openclaw.plugin.json +11 -6
  10. package/package.json +1 -1
  11. package/schema/PROVENANCE.md +7 -4
  12. package/schema/shopping-brief-write-request.schema.json +225 -0
  13. package/schema/{shopping-brief-create-response.schema.json → shopping-brief-write-response.schema.json} +3 -3
  14. package/schema/shopping-content-request.schema.json +4 -7
  15. package/schema/shopping-content-response.schema.json +234 -108
  16. package/schema/shopping-domain-get-request.schema.json +18 -0
  17. package/schema/shopping-domain-get-response.schema.json +124 -86
  18. package/schema/shopping-offers-request.schema.json +174 -23
  19. package/schema/shopping-offers-response.schema.json +20 -10
  20. package/schema/shopping-product-get-request.schema.json +2 -2
  21. package/schema/shopping-product-get-response.schema.json +113 -16
  22. package/schema/shopping-search-request.schema.json +16 -25
  23. package/schema/shopping-search-response.schema.json +95 -21
  24. package/schema/shopping-seller-get-response.schema.json +249 -221
  25. package/schema/shopping-user-forget-request.schema.json +43 -0
  26. package/schema/shopping-user-forget-response.schema.json +74 -0
  27. package/schema/shopping-user-read-request.schema.json +36 -0
  28. package/schema/shopping-user-read-response.schema.json +372 -0
  29. package/schema/shopping-user-remember-request.schema.json +340 -0
  30. package/schema/shopping-user-remember-response.schema.json +66 -0
  31. package/schema/sil-whoami-request.schema.json +8 -0
  32. package/schema/sil-whoami-response.schema.json +90 -0
  33. package/sil-shopping/SKILL.md +149 -203
  34. package/schema/shopping-brief-create-request.schema.json +0 -98
  35. package/schema/shopping-brief-edit-request.schema.json +0 -125
  36. package/schema/shopping-brief-edit-response.schema.json +0 -24
  37. package/schema/shopping-profile-edit-request.schema.json +0 -97
  38. package/schema/shopping-profile-edit-response.schema.json +0 -17
@@ -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,284 +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: "Find the place for a thing",
26
- description: "The first call for any buy: send `q`, what the thing is called, in English — "
27
- + "translate the buyer first — and get up to three LEAVES — buyable kinds of thing — best first. Each has "
28
- + "its `path`, `name`, `matched` (which of sil's words your ask matched) and `under`, "
29
- + "the places above it, outermost first down to its parent, each with a `role`: `under`"
30
- + " tells same-named leaves apart. Choose from what the ask already says; when the "
31
- + "three share one kind, ask the buyer which. Take the path verbatim to "
32
- + "shopping_domain_get. An empty answer, or no leaf that fits, means sil does not carry"
33
- + " it yet: tell the buyer so — it is in the pipeline — and do not search; never shop "
34
- + "around.",
35
- },
36
- {
37
- name: "shopping_domain_get",
38
- ...DOMAIN_GET_ROUTE,
39
- label: "Read a place's specs",
40
- recovery: { not_found: "shopping_domain_search" },
41
- description: "A leaf's specs, from a path shopping_domain_search answered. `name` is its one "
42
- + "English name and `labels` the market's own words for it — never send them. `specs` "
43
- + "are the keys it is bought by and `seller_specs` the seller terms it is bought with. "
44
- + "Each key's `description` says how it moves the fit: what it decides, what goes wrong"
45
- + " at either end, and how a buyer's fact becomes its value. Each key states its type, "
46
- + "operators, unit, any closed set, the `step` a number moves by, and `forms` — printed"
47
- + " forms mapped to the value. Send that key and one of those operators, never a "
48
- + "synonym you coined: `specs` go on the brief and to shopping_search, `seller_specs` "
49
- + "on the brief's `seller` domain, where shopping_offers reads them. variant_spec marks"
50
- + " the key an option is picked on (a size, a colour), answered under each product's "
51
- + "variants; product_spec tells one product from the next; `several`, a key held many-"
52
- + "valued — `eq`/`in` meet any, `neq`/`nin` none. `reach` says where each key comes "
53
- + "from, `kinds` every kind it is, `parts` what it has, `made_for` what a part or "
54
- + "consumable fits. `record` is how a leaf's products are bought: `specs` — on measures"
55
- + " alone; `full` — on measures and their record (purpose, story, pros and cons, for "
56
- + "and not for). On a kind, `leaves` lists what to choose from. A shelf or domain is "
57
- + "refused `not_a_leaf`, naming leaves; one sil does not carry yet, `not carried`.",
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.",
58
25
  },
59
26
  {
60
- name: "shopping_content",
27
+ name: "shopping_user_remember",
61
28
  method: "POST",
62
- path: "/catalog/content",
63
- label: "Grep what sil holds about it",
64
- recovery: { not_found: "shopping_domain_search" },
65
- description: "Grep sil's library for a thing: its own guides and the sources it read, quoted "
66
- + "verbatim — label law, producers' technical sheets, writers on the trade. Send `path` (the "
67
- + "leaf you chose, or any place above it) and `q`, the terms: each word matched stemmed, "
68
- + "a \"quoted phrase\" as one term, never by meaning. It reads every document on the "
69
- + "line through that node, up to the root, and answers whole passages: every term "
70
- + "first, then more terms, then the densest. `total` says how many passages hold a "
71
- + "term; more than came back means grep narrower, add a phrase, or set `kinds`. Each "
72
- + "passage carries `part` and `of`: send `document` (its `id`) with `from` to read that "
73
- + "document on. `max_passages` and `max_tokens` bound the answer, the last passage cut "
74
- + "and marked `truncated`; an empty `matched` only fills the minimum. Search like an "
75
- + "agent: grep, read on, grep again in other words. Once the leaf is chosen, grep it "
76
- + "before your first question to the buyer, and again whenever they ask how or why. "
77
- + "A passage with `author` is that author's words — quote and name them, with `url`; "
78
- + "without it, the words are sil's. Empty `passages`: say sil holds nothing on it, "
79
- + "and never fill the gap from the open web.",
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.",
80
34
  },
81
35
  {
82
- name: "shopping_brief_create",
36
+ name: "shopping_user_forget",
83
37
  method: "POST",
84
- path: "/briefs/create",
85
- label: "Open the session's brief",
86
- description: "Once per SESSION: open the one brief this conversation works from — across"
87
- + " every domain the buyer asks about, never one per domain — and hold the `id`"
88
- + " it answers for the rest of the session, because every search and every offers"
89
- + " call names it. A new chat opens its own AFTER shopping_brief_read has shown what"
90
- + " is on file: carry every spec an earlier brief still holds true into this one, then"
91
- + " name that carry in the first shopping_brief_edit `decision`. `title` names the job"
92
- + " in a few words. `narrative` is the spec of the buy in the buyer's own terms — what"
93
- + " a good buy looks like for THEM, what it has to do for them, what would make it a"
94
- + " bad one — and a want no keyed spec can carry lives there and still counts. An"
95
- + " optional first `domain` with `specs` writes what they have already said: a"
96
- + " domain path carries that domain's product specs, `seller` carries the seller"
97
- + " specs, and each spec is a key and an operator shopping_domain_get listed whose"
98
- + " `reason` quotes the buyer VERBATIM, in English — their own words, or the measurement the"
99
- + " key's `description` converted — never a paraphrase and never a want they did not state. On"
100
- + " anything worn, the `gender` sil_whoami holds is a product spec in the registry's"
101
- + " own spelling — male → `gender eq mens`, female → `gender eq womens` — asked once"
102
- + " where the profile answers none or `other`, and never inferred. Everything after"
103
- + " 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.",
104
42
  },
105
43
  {
106
- name: "shopping_brief_edit",
44
+ name: "shopping_brief_write",
107
45
  method: "POST",
108
- path: "/briefs/edit",
109
- label: "Write a want or a decision into the brief",
110
- // 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",
111
48
  recovery: { not_found: "shopping_brief_read" },
112
- description: "The brief's write: put every want the buyer states into the brief as it is settled,"
113
- + " with `reason` quoting their own words VERBATIM — never a"
114
- + " paraphrase, never a want they did not state. A want that reaches"
115
- + " no brief is a want the next call drops. A MEASUREMENT is never the spec: 27.2 cm is"
116
- + " the buyer's, and the spec is the size the thing is sold in —"
117
- + " `mondo_size in [27, 27.5]`, with that measurement as its `reason`; the key's"
118
- + " `description` says how one becomes the other."
119
- + " One write per `domain`: a domain path carries"
120
- + " that domain's product specs, `price` among them, and `seller` carries the"
121
- + " seller specs, which belong to the whole brief. `specs` REPLACE every spec on the"
122
- + " keys they name — a range is the two rows on its key — `remove` names the keys"
123
- + " whose specs go, and `narrative` replaces the whole narrative. When the buyer"
124
- + " changes their mind — and only then — send the new spec together with `decision`:"
125
- + " one sentence ABOUT them, never in their voice, saying what they changed and"
126
- + " why. A new want's words are its spec's `reason`, never a `decision`, and never a"
127
- + " log of what you have just written down."
128
- + " Send `status: \"closed\"` when the job is over. An"
129
- + " invalid_request names the key and shows a spec on it that passes — fix that row"
130
- + " and send it again, and never give the want up. A brief id that is not the"
131
- + " 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.",
132
52
  },
133
53
  {
134
54
  name: "shopping_brief_read",
135
55
  method: "POST",
136
56
  path: "/briefs/read",
137
- label: "Read the brief, or list the buyer's briefs",
138
- description: "The first read of a new chat: with no `id` it answers the buyer's briefs,"
139
- + " newest first, each with its title, its domains and when it was last written."
140
- + " Call it with sil_whoami before you ask the buyer anything, so a job already"
141
- + " under way is continued rather than interviewed a second time. With an `id` it"
142
- + " answers that brief whole: the title, the narrative, every spec under the domain"
143
- + " it sits on (`seller` for the seller specs), and the decisions already taken with"
144
- + " the time of each. What comes back is a READ: it says what the buyer has already"
145
- + " settled so you ask none of it again, and the specs still true are carried into"
146
- + " this session's own brief with shopping_brief_create — the search runs on that"
147
- + " 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.",
69
+ },
70
+ {
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.",
148
78
  },
149
79
  {
150
- name: "shopping_profile_edit",
80
+ name: "shopping_content",
151
81
  method: "POST",
152
- path: "/profile/edit",
153
- label: "Write what is true of the buyer",
154
- description: "The person rather than the job: write what is true of the buyer whatever"
155
- + " they are buying, the moment they say it and BEFORE the next search — only what"
156
- + " they stated UNAMBIGUOUSLY about themselves. A phrase that could mean two things"
157
- + " (\"wide forefoot and bit short\" — the foot, or the buyer?) is asked about, never"
158
- + " written here, because a lasting fact written wrong follows them into every"
159
- + " domain. Every `name` is lower snake_case: `foot_length`, never \"foot length\"."
160
- + " A"
161
- + " `measurements` entry is a number with its `unit`, or a size exactly as it is"
162
- + " printed; a `preferences` entry is a lasting taste in the buyer's own words."
163
- + " An entry replaces the one of the same `name`, and `remove` names the entries"
164
- + " that stopped being true. `currency` is the ISO 4217 code they price in, and"
165
- + " every money row naming none means it: \"my prices in dollars from now on\" is"
166
- + " `currency: \"USD\"`, which changes which offers come first and never a price —"
167
- + " sil converts nothing. sil_whoami reads all of it back, so a fact written here"
168
- + " is one you never ask for again. What belongs to THIS job — a budget, a size for"
169
- + " these boots — is the brief's, through shopping_brief_edit: a measurement is the"
170
- + " buyer's, and the spec the domain's key turns it into carries that"
171
- + " 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.",
172
87
  },
173
88
  {
174
89
  name: SEARCH_TOOL,
175
90
  method: "POST",
176
91
  path: "/catalog/search",
177
- label: "Search sil in one settled domain",
178
- // A 404 here is the `brief` id and nothing else: a domain that does not stand is
179
- // refused as `invalid_request`, naming the path.
92
+ label: "Search sil's products",
180
93
  recovery: { not_found: "shopping_brief_read" },
181
- description: "The products that fit the brief, in one settled domain. Search as often as the job"
182
- + " needs — a re-worded `query`, a different `n` — it is cheap and it is how you learn"
183
- + " what is out there. Send `brief` (the session's brief id) on EVERY call,"
184
- + " the domain path, and `query` — the thing as a shop lists it and the numbers"
185
- + " that pick the product, never a sentence; a budget, a market, a unit, a standard's"
186
- + " name, \"in stock\" and \"online\" are specs, and cost most of the offers."
187
- + " `n` counts VARIANTS — one size, one option — max 10. `specs`: every product"
188
- + " spec the brief holds for this domain, all of them and UNCHANGED — never a looser"
189
- + " bound, never one it does not hold — money a decimal STRING (`\"300\"`, never 300)."
190
- + " The brief's `seller` specs are shopping_offers' to read off the brief, never on"
191
- + " the search. Keep the server's order, never re-rank; quote each variant's OWN"
192
- + " `price` with its size. `fit` answers the ask key by key: the value sil verified"
193
- + " (a list on a `several` key), or \"unknown\" where it holds none — a gap to dig"
194
- + " into with shopping_product_get, never a failed one."
195
- + " `host` is the shop; `printed` is that page's own pairs, never verified —"
196
- + " say \"the page says\". A `variants` entry with no option"
197
- + " values is a listing whose sizes sil has not read: say so — it prices like any"
198
- + " other. sil never says what it left out, so a want left off `specs` is one you will"
199
- + " 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.",
200
97
  },
201
98
  {
202
99
  name: "shopping_product_get",
203
100
  method: "POST",
204
101
  path: "/catalog/product",
205
102
  label: "Read the whole dossier on a shortlisted variant",
206
- description: "The dossier: send 1–10 variant ids from a shopping_search answer and get"
207
- + " the whole of what sil holds for each — the title, the maker, the page's own"
208
- + " description, the images, every key sil holds for it (not only the ones you"
209
- + " asked about; a `several` key as a list), and `sources` naming which site each"
210
- + " reading came from and when."
211
- + " This is where a key the search answered \"unknown\" is dug out. A variant with no"
212
- + " option values is a listing whose sizes sil has not read, and its id opens here"
213
- + " like any other: the answer carries that page whole, so the sizes it prints are"
214
- + " the page's own words — say the size is unread, never that it is in stock."
215
- + " Compare the shortlist on this before recommending, and quote a source's date"
216
- + " rather than implying sil read it just now. An id sil cannot place is simply"
217
- + " absent from the answer — say that listing could not be placed, and never"
218
- + " substitute another product. Ids are opaque: pass them back exactly as sil"
219
- + " 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.",
220
105
  },
221
106
  {
222
107
  name: "shopping_offers",
223
108
  method: "POST",
224
109
  path: "/catalog/offers",
225
110
  label: "List who sells a variant, at what price and on what terms",
226
- // Same as the search: the only 404 this route answers is a brief that is not
227
- // the buyer's.
228
111
  recovery: { not_found: "shopping_brief_read" },
229
- description: "Who sells it, at what price, on what terms — the only live read of a price."
230
- + " Worth a call once the buyer wants something: pricing a whole shortlist buries the"
231
- + " fit answer they asked for. Send `brief` (the session's brief id) and 1–10 picked"
232
- + " variant ids, and nothing else: sil reads the brief's `seller` specs, its `price`"
233
- + " ceiling, the buyer's default address and their currency itself, so a seller term"
234
- + " the buyer states goes on the brief. The first three picks are also looked for on"
235
- + " the web, so put the one they want first; the rest answer from shops sil holds. A"
236
- + " variant with no option values is priced as its page prints. An offer is the pick"
237
- + " at one shop, read live: the seller, the price in its own currency (sil converts"
238
- + " nothing), its availability, the listing URL, `observed_at`, and `seller_fit`:"
239
- + " `ships` always — serviceable, not_serviceable or unknown for that address — and"
240
- + " each brief seller key where sil holds the seller's value. An offer over the"
241
- + " brief's price in that price's currency is left out; one in another currency was"
242
- + " not tested against it — say so. `unknown` keeps the offer: say sil could not"
243
- + " confirm shipping. A key absent from `seller_fit` is a term sil has not read. The"
244
- + " order is the buyer's currency and market first, then sellers known to reach them,"
245
- + " then the rest — keep it, never re-rank. Several offers ARE the price spread, and"
246
- + " 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.",
247
114
  },
248
115
  {
249
116
  name: "shopping_seller_get",
250
117
  method: "POST",
251
118
  path: "/catalog/sellers",
252
119
  label: "Read one seller's whole terms",
253
- description: "One seller's WHOLE terms: send 1–10 seller ids from shopping_offers, and"
254
- + " nothing else. Each seller comes back with its name, host and country, `specs` —"
255
- + " every seller key sil holds a value for, base and branch, as the dossier's `specs`"
256
- + " are a product's — and `ships`, which answers for the buyer's default address:"
257
- + " serviceable (sil read a route covering it), not_serviceable (sil read this"
258
- + " seller's policy and it excludes it), or unknown (sil has read nothing about this"
259
- + " seller). `unknown` is an ordinary answer that keeps the seller — say sil could not"
260
- + " confirm shipping, and hand the buyer the listing; an empty `specs` is the same"
261
- + " answer about its terms. Where sil has read them, `shipping` carries the routes"
262
- + " with their cost, free-over threshold and days, and `returns` the window and any"
263
- + " restocking fee; a term the page never stated is simply absent, which is never zero"
264
- + " and never free. A `policy_url` of null means the terms were read off a product"
265
- + " page and sil holds no policy page. This is the details read: whether an offer"
266
- + " meets the buyer's own seller rows is `seller_fit` on that offer, from"
267
- + " 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.",
268
122
  },
269
123
  ];
270
124
  /**
271
- * Registers the eleven, reading each one's request artifact off disk as it goes.
272
- *
273
- * That read is the ONE exception to "register() opens nothing": eleven synchronous
274
- * `readFileSync`s that return immediately and hold no resource open, exactly as
275
- * `ensureDataDir`'s `mkdirSync` does. It is deliberately eager — an unreadable artifact
276
- * is a broken build, and failing loud at load beats a tool whose `parameters` the host
277
- * has already published by the time anyone finds out.
278
- *
279
- * Each tool is a factory because the host hands the conversation and the model only to a
280
- * 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.
281
128
  */
282
129
  export function registerCatalogTools(api) {
283
130
  const pluginVersion = readInstalledVersion();
284
131
  const openclawVersion = readHostVersion(api) ?? undefined;
285
132
  for (const tool of SHOPPING_TOOLS) {
286
133
  const parameters = requestSchema(tool.name);
287
- api.registerTool((ctx) => {
288
- const { provider, modelId } = ctx.activeModel ?? {};
289
- const run = {
290
- pluginVersion,
291
- ...(openclawVersion !== undefined ? { openclawVersion } : {}),
292
- ...(ctx.sessionId ? { sessionId: ctx.sessionId } : {}),
293
- ...(provider && modelId ? { model: `${provider}/${modelId}` } : {}),
294
- };
295
- return defineTool(api, tool, parameters, run);
296
- }, { name: tool.name });
134
+ api.registerTool((ctx) => defineTool(api, tool, parameters, runOf(ctx, pluginVersion, openclawVersion)), { name: tool.name });
297
135
  }
298
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
+ }
299
147
  function defineTool(api, tool, parameters, run) {
300
148
  return {
301
149
  name: tool.name,
@@ -311,17 +159,14 @@ function defineTool(api, tool, parameters, run) {
311
159
  }
312
160
  if (tool.name === SEARCH_TOOL)
313
161
  bufferPage(api, callId, called.body);
314
- // VERBATIM, and the advisory rides its own block: the body's keys are the API's
315
- // 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.
316
163
  return jsonResult(called.body, ...wiringAdvisoryBlocks(api));
317
164
  },
318
165
  };
319
166
  }
320
167
  /**
321
- * Buffer an `ok` search page for a paired client to pull by this exact `callId`
322
- * (`sil.search_results`). A PURE SIDE EFFECT: the result returned to the agent is
323
- * byte-identical to what every channel got before this existed. Only a body that
324
- * 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.
325
170
  */
326
171
  function bufferPage(api, callId, body) {
327
172
  const principal = readConfig()?.user?.id;
@@ -335,9 +180,8 @@ function bufferPage(api, callId, body) {
335
180
  }
336
181
  putSearchResult(callId, body, principal);
337
182
  }
338
- /** Why this `callId` will resolve nothing, logged where the decision is made. The pull
339
- * says only `not_found` — deliberately — so this line is the whole of an operator's
340
- * 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. */
341
185
  function skipped(api, callId, reason) {
342
186
  logSearchResults(api, "info", "skipped", { callId, reason });
343
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",