sil-openclaw 0.2.4 → 0.3.1

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.
@@ -0,0 +1,319 @@
1
+ /**
2
+ * sil shopping-expert profile tools.
3
+ *
4
+ * `sil_profile_materialize` is the plugin's half of the agent-creation engine:
5
+ * it writes the created expert's *SDS behaviour* artefacts (all four required —
6
+ * domain spec + intent-spec dimension schema + user spec + playbook taste,
7
+ * present from creation and augmented every query — and a typed manifest) into
8
+ * the plugin's own data directory (`$SIL_DATA_DIR`, the
9
+ * disclosed `filesystemScope`). The persona is NOT written here — the agent's
10
+ * identity/voice is the host workspace `SOUL.md`, written directly via the host
11
+ * CLI. The *wiring* half — the host `agents.list[]` entry, the enabled `sil`
12
+ * plugin, the attached `sil` skill, the `SOUL.md` — is the host agent driving
13
+ * its own `openclaw …` CLI under the bundled `skill/SKILL.md` procedure; the
14
+ * plugin never writes `~/.openclaw` (`security.noChildProcess: true`, host
15
+ * config is outside `filesystemScope`).
16
+ *
17
+ * Why a tool (not skill-driven `write`-tool prose): the host agent's only way
18
+ * to invoke plugin code is a registered tool, and a plugin write buys
19
+ * host-validated typed inputs, the structured-error envelope, and ATOMIC
20
+ * all-or-nothing writes — all of which serve the goal's primary correctness
21
+ * bar (a created expert that actually shops). The artefact write lives here;
22
+ * the host-config write stays host-CLI.
23
+ *
24
+ * This follows `identity.ts` (the reference group): a `registerXTools(api)`
25
+ * function, a `Type.Object` schema the host validates inputs against, the
26
+ * `jsonResult` success/structured-error envelope, and ALL I/O inside
27
+ * `execute()` (register() opens nothing).
28
+ */
29
+ import { Type } from "typebox";
30
+ import { listAgentProfiles, materializeProfile, readAgentProfile, removeAgentArtefacts, } from "../lib/profile-store.js";
31
+ import { jsonResult } from "../lib/tool-result.js";
32
+ export function registerProfileTools(api) {
33
+ registerMaterialize(api);
34
+ registerList(api);
35
+ registerGet(api);
36
+ registerRemove(api);
37
+ }
38
+ function registerMaterialize(api) {
39
+ api.registerTool({
40
+ name: "sil_profile_materialize",
41
+ label: "Materialize a sil shopping-expert's SDS behaviour artefacts",
42
+ description: "Write a created sil shopping expert's SDS behaviour artefacts into the sil"
43
+ + " data directory — ALL FOUR are REQUIRED and present from creation (seeded"
44
+ + " partial by the light ≤10-question setup + an initial research pass, then"
45
+ + " augmented every query): the domain spec (deep researched niche expertise"
46
+ + " — how to buy well, the full mechanics), the intent spec (the"
47
+ + " agent-specific decomposition dimensions a query must resolve, derived"
48
+ + " from the domain spec), the user spec (the user's domain-relevant facts +"
49
+ + " hard constraints) and the playbook (the user's buying taste), plus a"
50
+ + " typed manifest the sil skill reads at runtime to load them. The persona"
51
+ + " is NOT written here — it is the host workspace SOUL.md, written via the"
52
+ + " host CLI. Re-run it over the SAME agentId to refine an expert in place or"
53
+ + " augment a spec from a query (pass the full updated body — it overwrites"
54
+ + " atomically). Call this AFTER the host agent has been created (openclaw"
55
+ + " agents add) and BEFORE openclaw config validate. It does NOT touch the"
56
+ + " host OpenClaw config — the plugin enable + skill attach are driven by the"
57
+ + " host CLI, not this tool. Writes are atomic: an invalid spec writes"
58
+ + " nothing, and a write failure leaves nothing partial.",
59
+ parameters: Type.Object({
60
+ agentId: Type.String({
61
+ description: "The host agent id the expert was created under (agents.list[].id),"
62
+ + " lower-kebab; not \"main\" (host-reserved). Keys the artefact dir.",
63
+ }),
64
+ name: Type.String({
65
+ description: "The human-readable expert name (recorded in the manifest).",
66
+ }),
67
+ domainSpec: Type.String({
68
+ description: "The SDS domain spec — deep researched niche expertise: how to buy well"
69
+ + " in the niche and its full mechanics (for cycling: gearing theory,"
70
+ + " frame geometry, the complete bike-fit process). Researched by the"
71
+ + " agent itself (web + knowledge), not interrogated from the user."
72
+ + " REQUIRED, non-empty. Materialized as domain_spec.md; web-refreshed"
73
+ + " every query.",
74
+ }),
75
+ intentSpec: Type.String({
76
+ description: "The SDS intent spec — the agent-specific decomposition DIMENSIONS (a"
77
+ + " PRD-style template) a shopping query must resolve, derived from the"
78
+ + " domain spec (for cycling: use-case, terrain, budget, timeline,"
79
+ + " compatibility, performance priorities, aesthetics). REQUIRED,"
80
+ + " non-empty. This is the dimension SCHEMA only — the per-query intent"
81
+ + " (dimensions filled in) is ephemeral and is never stored. Materialized"
82
+ + " as intent_spec.md.",
83
+ }),
84
+ userSpec: Type.String({
85
+ description: "The SDS user spec — the user's domain-relevant facts + hard"
86
+ + " constraints (body measurements, climate, the rules they never"
87
+ + " break). REQUIRED, non-empty: present from creation (seeded partial"
88
+ + " by the light ≤10-question setup), then augmented every query."
89
+ + " Materialized as user_spec.md (per-user, per-expert, local). On a"
90
+ + " per-query augment / refine, pass the full updated body.",
91
+ }),
92
+ playbook: Type.String({
93
+ description: "The SDS playbook — the user's buying TASTE (price sensitivity, brand"
94
+ + " preferences, general taste). REQUIRED, non-empty: present from"
95
+ + " creation (seeded partial), then augmented every query. Materialized"
96
+ + " as playbook.md. On a per-query augment / refine, pass the full"
97
+ + " updated body.",
98
+ }),
99
+ }),
100
+ async execute(_callId, params) {
101
+ // The host validates `params` against the schema above before we run, but
102
+ // narrow at the read site (the SDK types params as Record<string,unknown>)
103
+ // and let the store do the real, structured-error validation.
104
+ const spec = {
105
+ agentId: typeof params["agentId"] === "string" ? params["agentId"] : "",
106
+ name: typeof params["name"] === "string" ? params["name"] : "",
107
+ domainSpec: typeof params["domainSpec"] === "string" ? params["domainSpec"] : "",
108
+ intentSpec: typeof params["intentSpec"] === "string" ? params["intentSpec"] : "",
109
+ userSpec: typeof params["userSpec"] === "string" ? params["userSpec"] : "",
110
+ playbook: typeof params["playbook"] === "string" ? params["playbook"] : "",
111
+ };
112
+ const result = materializeProfile(spec);
113
+ if (result.ok) {
114
+ api.logger.info("sil_profile_materialized", { agent_id: result.agentId });
115
+ return jsonResult({
116
+ status: "ok",
117
+ agentId: result.agentId,
118
+ dir: result.dir,
119
+ domainSpecPath: result.domainSpecPath,
120
+ intentSpecPath: result.intentSpecPath,
121
+ userSpecPath: result.userSpecPath,
122
+ playbookPath: result.playbookPath,
123
+ profilePath: result.profilePath,
124
+ });
125
+ }
126
+ if (result.kind === "invalid_request") {
127
+ api.logger.warn("sil_profile_invalid_request", { field: result.field });
128
+ return jsonResult({
129
+ status: "invalid_request",
130
+ field: result.field,
131
+ message: result.message,
132
+ });
133
+ }
134
+ // persistence_failed — the path + cause are in `error` (never a token/PII).
135
+ api.logger.error("sil_profile_persistence_failed", { error: result.error });
136
+ return jsonResult({
137
+ status: "persistence_failed",
138
+ error: result.error,
139
+ message: result.message,
140
+ recovery: "fix_data_dir",
141
+ });
142
+ },
143
+ });
144
+ }
145
+ /**
146
+ * `sil_profile_list` — enumerate the user's sil shopping experts (read-only).
147
+ *
148
+ * The artefact store is the source of truth for "what is a sil expert" (a
149
+ * readable `agents/<id>/profile.json`), not the host agent list. Returns each
150
+ * expert summarized from its manifest, most-recently-created first, plus an
151
+ * `unreadable[]` bucket so one corrupt manifest never blinds the user to the
152
+ * rest. An empty store is a normal `ok` outcome (like an empty `sil_search`).
153
+ */
154
+ function registerList(api) {
155
+ api.registerTool({
156
+ name: "sil_profile_list",
157
+ label: "List the user's sil shopping experts",
158
+ description: "List the sil shopping experts the user has created — read-only, no"
159
+ + " arguments. Sourced from the sil data directory's artefact store (each"
160
+ + " agents/<id>/profile.json is the authoritative \"is a sil expert\""
161
+ + " signal — a bare host agent without one is not listed). Returns the"
162
+ + " experts most-recently-created first, each with its agentId, name, and"
163
+ + " createdAt. Every expert carries all four SDS specs (domain + intent +"
164
+ + " user + playbook, all required and present from creation), so per-slot"
165
+ + " presence is not flagged. An empty store is a normal, successful empty"
166
+ + " listing — not an error. One unreadable or corrupt manifest is reported"
167
+ + " inline in `unreadable` and never aborts the listing. Reads no token and"
168
+ + " writes nothing.",
169
+ parameters: Type.Object({}),
170
+ async execute(_callId, _params) {
171
+ const { experts, unreadable } = listAgentProfiles();
172
+ api.logger.info("sil_profile_listed", {
173
+ expert_count: experts.length,
174
+ unreadable_count: unreadable.length,
175
+ });
176
+ return jsonResult({
177
+ status: "ok",
178
+ experts,
179
+ unreadable,
180
+ });
181
+ },
182
+ });
183
+ }
184
+ /**
185
+ * `sil_profile_get` — view one expert's full detail (read-only).
186
+ *
187
+ * Re-runs the writer's `agentId` gate before any read (a traversal-shaped id →
188
+ * `invalid_request`). Returns the manifest plus the SDS artefact bodies so the
189
+ * skill can render a complete view. An unknown or unloadable expert →
190
+ * `not_found` (the skill lists the healthy experts) — never a stack trace or a
191
+ * raw path. Reads no token and writes nothing.
192
+ */
193
+ function registerGet(api) {
194
+ api.registerTool({
195
+ name: "sil_profile_get",
196
+ label: "View one sil shopping expert's detail",
197
+ description: "Show one sil shopping expert's full detail — read-only. Pass its"
198
+ + " `agentId`. Returns the expert's name, its four SDS specs (domain, intent,"
199
+ + " user spec / facts, and playbook / buying taste — all present), the"
200
+ + " manifest path, and createdAt, read from the artefact store so the agent"
201
+ + " can summarize the expert. The persona is not here — it is the host"
202
+ + " workspace SOUL.md. An unknown expert returns `not_found` (list the"
203
+ + " experts to see which exist) — never a stack trace or a raw path. A"
204
+ + " malformed/traversal id returns `invalid_request`. Reads no token and"
205
+ + " writes nothing.",
206
+ parameters: Type.Object({
207
+ agentId: Type.String({
208
+ description: "The expert's host agent id (lower-kebab, e.g. \"gift-buyer\"; not"
209
+ + " \"main\"). Keys the artefact directory the detail is read from.",
210
+ }),
211
+ }),
212
+ async execute(_callId, params) {
213
+ const agentId = typeof params["agentId"] === "string" ? params["agentId"] : "";
214
+ const result = readAgentProfile(agentId);
215
+ if (result.ok) {
216
+ api.logger.info("sil_profile_viewed", { agent_id: result.agentId });
217
+ return jsonResult({
218
+ status: "ok",
219
+ agentId: result.agentId,
220
+ name: result.name,
221
+ domainSpec: result.domainSpec,
222
+ intentSpec: result.intentSpec,
223
+ userSpec: result.userSpec,
224
+ playbook: result.playbook,
225
+ profilePath: result.profilePath,
226
+ createdAt: result.createdAt,
227
+ });
228
+ }
229
+ if (result.kind === "invalid_request") {
230
+ api.logger.warn("sil_profile_get_invalid_request", { field: result.field });
231
+ return jsonResult({
232
+ status: "invalid_request",
233
+ field: result.field,
234
+ message: result.message,
235
+ });
236
+ }
237
+ // not_found — a normal outcome; steer the agent to list-then-retry.
238
+ api.logger.info("sil_profile_get_not_found", { agent_id: result.agentId });
239
+ return jsonResult({
240
+ status: "not_found",
241
+ agentId: result.agentId,
242
+ message: result.message,
243
+ recovery: "sil_profile_list",
244
+ });
245
+ },
246
+ });
247
+ }
248
+ /**
249
+ * `sil_profile_remove` — remove one expert's behaviour artefacts (the sil-side
250
+ * half of a clean removal).
251
+ *
252
+ * This is the ARTEFACT half ONLY. The host-wiring half (the `agents.list[]`
253
+ * entry) is the skill's `openclaw agents remove <agentId>` CLI step, which the
254
+ * skill runs FIRST — the plugin cannot write `~/.openclaw` (`noChildProcess`).
255
+ *
256
+ * Fail-closed: re-runs the `agentId` gate itself, deletes only the single
257
+ * validated leaf directory under `agents/`, and deletes NOTHING on a bad id.
258
+ * Absent target → `not_found` (idempotent — safe to re-run after a partial host
259
+ * failure). A genuine `rmSync` failure → `persistence_failed`. Reads no token.
260
+ */
261
+ function registerRemove(api) {
262
+ api.registerTool({
263
+ name: "sil_profile_remove",
264
+ label: "Remove a sil shopping expert's behaviour artefacts",
265
+ description: "Remove one sil shopping expert's behaviour artefacts from the sil data"
266
+ + " directory (its agents/<id>/ directory). This is the SIL-SIDE half of"
267
+ + " removal only — the host wiring (the agents.list[] entry) is removed"
268
+ + " separately by the host CLI, which the skill runs FIRST (this plugin"
269
+ + " cannot write the host config). Pass the `agentId`. Scoped to exactly"
270
+ + " that one expert: a malformed/traversal/\"main\" id returns"
271
+ + " `invalid_request` and deletes nothing; an unknown id returns"
272
+ + " `not_found` (idempotent — safe to re-run after a partial failure); a"
273
+ + " genuine filesystem failure returns `persistence_failed`. Confirm with"
274
+ + " the user before removing — it is destructive and irreversible.",
275
+ parameters: Type.Object({
276
+ agentId: Type.String({
277
+ description: "The expert's host agent id (lower-kebab, e.g. \"gift-buyer\"; not"
278
+ + " \"main\"). Keys the artefact directory to remove. Exactly one"
279
+ + " expert is affected.",
280
+ }),
281
+ }),
282
+ async execute(_callId, params) {
283
+ const agentId = typeof params["agentId"] === "string" ? params["agentId"] : "";
284
+ const result = removeAgentArtefacts(agentId);
285
+ if (result.ok) {
286
+ api.logger.info("sil_profile_removed", { agent_id: result.agentId });
287
+ return jsonResult({
288
+ status: "removed",
289
+ agentId: result.agentId,
290
+ });
291
+ }
292
+ if (result.kind === "invalid_request") {
293
+ api.logger.warn("sil_profile_remove_invalid_request", { field: result.field });
294
+ return jsonResult({
295
+ status: "invalid_request",
296
+ field: result.field,
297
+ message: result.message,
298
+ });
299
+ }
300
+ if (result.kind === "not_found") {
301
+ api.logger.info("sil_profile_remove_not_found", { agent_id: result.agentId });
302
+ return jsonResult({
303
+ status: "not_found",
304
+ agentId: result.agentId,
305
+ message: result.message,
306
+ recovery: "sil_profile_list",
307
+ });
308
+ }
309
+ // persistence_failed — the path + cause are in `error` (never a token/PII).
310
+ api.logger.error("sil_profile_remove_persistence_failed", { error: result.error });
311
+ return jsonResult({
312
+ status: "persistence_failed",
313
+ error: result.error,
314
+ message: result.message,
315
+ recovery: result.recovery,
316
+ });
317
+ },
318
+ });
319
+ }
@@ -2,7 +2,7 @@
2
2
  "id": "sil",
3
3
  "name": "sil",
4
4
  "description": "sil commerce plugin for OpenClaw — register on sil, read your identity, and search and look up products in the sil catalog.",
5
- "version": "0.2.4",
5
+ "version": "0.3.1",
6
6
  "skills": ["./skill"],
7
7
  "activation": {
8
8
  "onCapabilities": ["tool"]
@@ -10,6 +10,10 @@
10
10
  "contracts": {
11
11
  "tools": [
12
12
  "sil_product_get",
13
+ "sil_profile_get",
14
+ "sil_profile_list",
15
+ "sil_profile_materialize",
16
+ "sil_profile_remove",
13
17
  "sil_register",
14
18
  "sil_search",
15
19
  "sil_whoami"
@@ -47,7 +51,7 @@
47
51
  },
48
52
  "security": {
49
53
  "shipsRuntimeCode": true,
50
- "packagingNote": "Compiled JavaScript ships under ./dist. register() stays synchronous and opens nothing — it only registers tools. ALL I/O happens inside a tool's execute(): sil_register calls sil-web over the network, writes tokens.json + config.json to the plugin data directory (owner-only, 0600), and arms a bounded background poll timer that stops on the first terminal claim outcome or after the session deadline. sil_whoami reads the stored access token and calls sil-api for the user's identity, refreshing transparently via sil-web on a 401 (at most one refresh + one retry per call, no timer); a confirmed-dead session clears tokens.json. sil_search and sil_product_get read the stored access token and call sil-api's catalog endpoints (search / lookup) with it — read-only, no token write, no timer, a single round-trip (a 401 is a terminal re-register hint, no refresh). The PKCE verifier is held only in memory and is never written to disk. Tokens and identity PII are never logged.",
54
+ "packagingNote": "Compiled JavaScript ships under ./dist. register() stays synchronous and opens nothing — it only registers tools. ALL I/O happens inside a tool's execute(): sil_register calls sil-web over the network, writes tokens.json + config.json to the plugin data directory (owner-only, 0600), and arms a bounded background poll timer that stops on the first terminal claim outcome or after the session deadline. sil_whoami reads the stored access token and calls sil-api for the user's identity, refreshing transparently via sil-web on a 401 (at most one refresh + one retry per call, no timer); a confirmed-dead session clears tokens.json. sil_search and sil_product_get read the stored access token and call sil-api's catalog endpoints (search / lookup) with it — read-only, no token write, no timer, a single round-trip (a 401 is a terminal re-register hint, no refresh). sil_profile_materialize makes no network call and reads no token: it writes a created shopping expert's SDS behaviour artefacts (domain_spec.md + intent_spec.md + user_spec.md + playbook.md — all four required and present from creation, seeded partial then augmented every query, plus profile.json) atomically into $SIL_DATA_DIR/agents/<agentId>/ (owner-only, 0600) — the persona is the agent's host workspace SOUL.md, written by the host CLI (not this plugin, not a sil artefact), and the agent's host-config wiring is driven separately by the host CLI. sil_profile_list / sil_profile_get / sil_profile_remove are the local expert lifecycle over the same artefact store, also making no network call and reading no token: list enumerates $SIL_DATA_DIR/agents/*/profile.json read-only, get reads one expert's manifest + domain_spec/intent_spec/user_spec/playbook bodies read-only, and remove deletes exactly one validated agents/<agentId>/ leaf directory (fail-closed on a malformed/traversal id — deletes nothing) — the host-wiring half of removal is the host CLI's, not this plugin's. The PKCE verifier is held only in memory and is never written to disk. Tokens and identity PII are never logged.",
51
55
  "registersLongLivedService": false,
52
56
  "serviceIds": [],
53
57
  "runsTimers": true,
@@ -57,7 +61,7 @@
57
61
  "https://sil.4gpts.com"
58
62
  ],
59
63
  "filesystemScope": [
60
- "$SIL_DATA_DIR (default $XDG_DATA_HOME/sil, else ~/.local/share/sil) — tokens.json, config.json"
64
+ "$SIL_DATA_DIR (default $XDG_DATA_HOME/sil, else ~/.local/share/sil) — tokens.json, config.json, agents/<agentId>/{domain_spec.md,intent_spec.md,user_spec.md,playbook.md,profile.json} (shopping-expert SDS behaviour artefacts written by sil_profile_materialize — all four required and present from creation, seeded partial then augmented every query: the domain spec (domain_spec.md) + intent-spec dimension schema (intent_spec.md) + user spec (user_spec.md) + buying taste (playbook.md); the persona is the host workspace SOUL.md, not a sil artefact)"
61
65
  ],
62
66
  "credentialsOnDisk": [
63
67
  "tokens.json (access + refresh token)",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sil-openclaw",
3
- "version": "0.2.4",
3
+ "version": "0.3.1",
4
4
  "description": "OpenClaw plugin for sil — register an identity and search and look up products in the sil commerce catalog from an agent.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/skill/SKILL.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: sil
3
- description: This skill should be used when the user wants to shop on sil — register an identity, see who they are, search the catalog for purchasable products, or look up specific products by id. The plugin exposes sil_register, sil_whoami, sil_search, and sil_product_get.
3
+ description: This skill should be used when the user wants to shop on sil — register an identity, see who they are, search the catalog for purchasable products, or look up specific products by id — or when they want to create a dedicated sil-wired shopping expert (a new OpenClaw agent profile) and then list, view, or remove the experts they have created. The plugin exposes sil_register, sil_whoami, sil_search, sil_product_get, sil_profile_materialize, sil_profile_list, sil_profile_get, and sil_profile_remove.
4
4
  metadata:
5
5
  openclaw:
6
6
  emoji: "\U0001F6D2"
@@ -8,55 +8,48 @@ metadata:
8
8
 
9
9
  # sil
10
10
 
11
- ## 1. Role
11
+ Drive the sil plugin's tools on the user's behalf: register them on sil, read their identity, help them find purchasable products in the sil catalog — and, when asked, create a dedicated sil-wired shopping expert, then list, view, or remove the experts they have created. Read user intent, route to the matching tool (loading its reference on demand), call it, and report what came back.
12
12
 
13
- Drive the sil plugin's tools on the user's behalf: register them on sil, read their identity, and help them find purchasable products in the sil catalog. Read user intent, pick the matching tool, call it, and report what came back.
13
+ ## Always-on behavioural contract
14
14
 
15
- Principles:
15
+ These three principles hold on every path, before any reference is loaded:
16
16
 
17
17
  - **Act, don't narrate.** When intent maps to a tool, call it. Don't re-confirm what was already stated.
18
- - **Fail visibly, recover correctly.** Every tool returns a `status`. On a non-`ok` status, say what happened and follow the tool's own `recovery` hint — never improvise a different one (re-registering can't fix a bad query or a transient 5xx, and would derail the user).
18
+ - **Fail visibly, recover correctly.** Every tool returns a `status`. On a non-`ok` status, say what happened and follow the tool's own `recovery` hint — never improvise a different one.
19
19
  - **Relay prices as point-in-time.** A product's price, availability, and `checkout_url` are a snapshot, not a guarantee. Before the user buys, re-fetch with `sil_product_get` rather than trusting an earlier `sil_search` result.
20
20
 
21
- ## 2. Session start
21
+ ## Session start
22
22
 
23
- Confirm the `sil_*` tools are exposed. If they are missing from the available tool list, the host runtime is filtering them out — tell the user to consult the host's tool-allowlist docs and stop.
23
+ Confirm the `sil_*` tools are exposed. If they are missing from the available tool list, the host runtime is filtering them out — tell the user to consult the host's tool-allowlist docs and stop. Most flows need an identity: if the user has not registered this session, the catalog tools return an unregistered status whose `recovery` points at `sil_register` (the [catalog tools reference](references/catalog_tools_reference.md) has the full taxonomy) — so calling a catalog tool first lets that outcome route, or run `sil_register` up front when the user's intent clearly requires it.
24
24
 
25
- Most flows need an identity. If the user has not registered this session, the catalog tools return `status: "not_registered"` with `recovery: "sil_register"` — so you can call a catalog tool first and let that outcome route you, or run `sil_register` up front when the user's intent clearly requires it.
25
+ ## Routing — match intent to a tool, load its reference on demand
26
26
 
27
- ## 3. Acting on user intent
28
-
29
- When intent maps to a tool, execute:
30
-
31
- | Intent | Tool |
32
- |---|---|
33
- | "sign me up" / "log me in to sil" / "register" | `sil_register` (takes no arguments; returns an auth URL to open in a browser) |
34
- | "who am I?" / "what's on my account" / show my saved name + addresses | `sil_whoami` (takes no arguments) |
35
- | "find X" / "search for X" / browse a category or price range | `sil_search` (free-text `query` and/or `category`, `price_min`, `price_max`; paginate with `cursor`/`limit`) |
36
- | "look up these items" / re-check ids from a prior result, a saved list, or a deep link | `sil_product_get` (pass `ids` — one or more product/variant ids) |
27
+ | Intent | Tool | Reference to load |
28
+ |---|---|---|
29
+ | "sign me up" / "log me in to sil" / "register" | `sil_register` | [`references/catalog_tools_reference.md`](references/catalog_tools_reference.md) |
30
+ | "who am I?" / "what's on my account" / show my saved name + addresses | `sil_whoami` | [`references/catalog_tools_reference.md`](references/catalog_tools_reference.md) |
31
+ | "find X" / "search for X" / browse a category or price range | `sil_search` | [`references/catalog_tools_reference.md`](references/catalog_tools_reference.md) |
32
+ | "look up these items" / re-check ids from a prior result, a saved list, or a deep link | `sil_product_get` | [`references/catalog_tools_reference.md`](references/catalog_tools_reference.md) |
33
+ | "make me a shopping expert" / "set up an agent that shops for me" / build a dedicated shopping expert | (interview, then the engine) | see the two-step gate below |
34
+ | "what experts do I have?" / "list my experts" | `sil_profile_list` | [`references/manage_experts.md`](references/manage_experts.md) |
35
+ | "show me / tell me about &lt;expert&gt;" | `sil_profile_get` | [`references/manage_experts.md`](references/manage_experts.md) |
36
+ | "remove / delete &lt;expert&gt;" | `sil_profile_remove` (host-CLI-first — see the reference) | [`references/manage_experts.md`](references/manage_experts.md) |
37
+ | (inside a created expert) a shopping intent — "find me something for X" on the expert's niche | `sil_search` → `sil_product_get` (driven by the loaded profile) | [`references/expert_shopping.md`](references/expert_shopping.md) |
38
+ | "refine / sharpen / improve &lt;expert&gt;" / "the gift buyer keeps surfacing the wrong stuff — fix it" | (load → propose → confirm → persist — see the reference) | [`references/refine_expert.md`](references/refine_expert.md) |
37
39
 
38
- How each behaves:
40
+ [`references/catalog_tools_reference.md`](references/catalog_tools_reference.md) holds the per-tool behaviour for the four core tools and the shared status taxonomy. Basic shopping needs only that one reference.
39
41
 
40
- - **`sil_register`** starts browser-based registration. It returns promptly with `status: "awaiting_browser"` and an `auth_url` — share that URL with the user. The plugin polls in the background; once the user finishes signing in, call `sil_register` again to confirm (it reports `already_registered`).
41
- - **`sil_whoami`** returns the registered user's identity (name and addresses). An expired access token is refreshed transparently and the read retried; if the session is fully dead, the result names the recovery (`sil_register`).
42
- - **`sil_search`** returns a ranked list of purchasable variants (`id`, `title`, `price`, `availability`, `checkout_url`, `source`), best match first — present them in order, do not re-rank. An empty list means nothing matched: a normal `ok` outcome, not an error. Use the returned `cursor` for the next page; its absence means no more results (never infer end-of-results from page size).
43
- - **`sil_product_get`** is the lookup companion to `sil_search`. Pass ids you already hold and get the matching products back with fresh detail (description, options, the featured variant). Each variant carries an `inputs` list correlating it back to the id(s) you asked about (the response is NOT in request order). Ids that no longer resolve come back in a `not_found` list — a normal partial-success outcome, not an error; the other products are still valid.
42
+ When the session is running **inside a created expert** (a loaded profile under `$SIL_DATA_DIR/agents/<agentId>/`) and the user states a shopping intent, follow [`references/expert_shopping.md`](references/expert_shopping.md) — the profile-driven, **Spec-Driven Shopping (SDS)** shop-time loop that web-refreshes the domain spec, decomposes the request along the intent spec, and augments the already-present user spec + buying taste every query. A created expert runs entirely on SDS; a plain, profile-less session keeps shopping via the "find X" → `sil_search` row above, unchanged.
44
43
 
45
- All four return the canonical envelope: a single text content block whose JSON body carries a `status`. Prices are in the currency's ISO 4217 minor unit (e.g. cents).
44
+ [`references/manage_experts.md`](references/manage_experts.md) holds the list / view / remove flow for the experts the user has created — including the host-CLI-first remove ordering and the confirm-before-remove gate. Load it the moment the user wants to see or remove an existing expert.
46
45
 
47
- ### Status taxonomy (shared across the tools)
46
+ [`references/refine_expert.md`](references/refine_expert.md) holds the refinement loop for an *existing* expert — sharpening it from observed sessions, with a confirm-before-persist gate (nothing changes silently). Load it when the user wants to refine, sharpen, or amend an expert they already have.
48
47
 
49
- | `status` | Meaning | What to do |
50
- |---|---|---|
51
- | `ok` | Success. Catalog results may be empty (`products: []`) or partial (`not_found: [...]`) — still a success. | Relay the data. |
52
- | `not_registered` | No stored credentials. | Run `sil_register`, then retry the tool. |
53
- | `must_reregister` | The session is dead (refresh rejected / 401). | Run `sil_register` to sign in again, then retry. |
54
- | `forbidden` | Authenticated but not authorized (e.g. account not provisioned). | Follow the message; usually complete onboarding via `sil_register`. |
55
- | `invalid_request` | The query/ids were rejected (e.g. empty input). | Fix the input and call again — do NOT re-register. |
56
- | `retryable` | A transient network/5xx blip. | Try the same call again — do NOT re-register. |
48
+ ### Creating a shopping expert — the endorsement-gated two-step
57
49
 
58
- ## 4. Adding a real tool
50
+ When the user asks to create / set up / build a dedicated shopping expert:
59
51
 
60
- The mechanical steps live in the repo's `CLAUDE.md` ("How to add a tool"); the short version is three steps: register the tool inside a `registerXTools(api)` group in `src/tools/`, wire that group into `register()` in `src/index.ts`, and add the tool's name to `openclaw.plugin.json#contracts.tools`. The manifest↔code drift-guard test fails if those disagree, which keeps the pattern self-enforcing.
52
+ 1. **Interview first.** Read and run [`references/brainstorm_interview.md`](references/brainstorm_interview.md) — the open, back-and-forth interview that converges a tailored spec *with* the user. While running it, load [`references/search_param_mapping.md`](references/search_param_mapping.md) when authoring the answer→`sil_search`-param mapping section.
53
+ 2. **Engine only after explicit endorsement.** Only after the user explicitly endorses the assembled draft, read and follow [`references/agent_creation_engine.md`](references/agent_creation_engine.md) — the ordered engine that persists the sil-wired agent. Running ANY engine step before that explicit endorsement is forbidden (the interview reference owns the endorsement gate).
61
54
 
62
- The reference group is `src/tools/identity.ts` (`sil_register`, `sil_whoami`) — it sets the `jsonResult` success shape and the structured-error/recovery envelope every real tool follows; `src/tools/catalog.ts` (`sil_search`, `sil_product_get`) is the catalog counterpart. All I/O lives inside a tool's `execute()`; `register()` stays synchronous and opens nothing.
55
+ Want a concrete walkthrough? [`examples/road_cycling_expert_walkthrough.md`](examples/road_cycling_expert_walkthrough.md) is an end-to-end worked example: a free-form request → interview convergence → assembled spec → created expert.
@@ -0,0 +1,150 @@
1
+ # Worked example — a road-cycling shopping expert as general counsel
2
+
3
+ A short walkthrough from a **create-expert request** through the interview
4
+ ([`../references/brainstorm_interview.md`](../references/brainstorm_interview.md))
5
+ to a created expert via the engine
6
+ ([`../references/agent_creation_engine.md`](../references/agent_creation_engine.md)),
7
+ then how it acts as **general counsel to the buyer** — an ongoing advisor across
8
+ the buyer's cycling needs, not a one-query optimizer. The interview walks the
9
+ **five artefacts, one touchpoint each, in order**; the deep domain work is the
10
+ agent's own research. The transcript is illustrative — it shows the *shape*, the
11
+ gates, and the SDS layering.
12
+
13
+ ## The interview — one touchpoint per document
14
+
15
+ > **User:** "I want an expert that shops for road-cycling gear for me."
16
+
17
+ **1. `SOUL.md` — ask first (persona; the niche falls out).** No separate
18
+ narrow-the-niche step:
19
+
20
+ > **Expert:** "Let's shape it. What kind of expert do you want, and how should it
21
+ > behave?"
22
+ > **User:** "A patient guide — I'm buying my first proper road bike and I'm new to
23
+ > this. Always explain fit. And no carbon-fibre handlebars, a friend cracked one."
24
+
25
+ → Persona (→ host **`SOUL.md`**): *a patient first-bike advisor who always explains
26
+ fit; standing rule — never recommend carbon handlebars.* The niche — **a complete
27
+ first road bike** — fell out of the answer.
28
+
29
+ **2. `domain_spec.md` — no question (the agent researches the web).** The agent
30
+ researches how to buy a first road bike well, then reflects the shape back:
31
+
32
+ > **Expert:** "I've done the homework. The short version: **the fit is everything** —
33
+ > frame size from height *and* inseam, stack/reach set torso angle, saddle setback
34
+ > from KOPS, crank length scales with inseam. Then endurance-vs-race geometry,
35
+ > groupset/gearing theory (gear-inches, compact vs mid-compact for your terrain),
36
+ > and alloy-vs-carbon + wheel/tyre trade-offs. For a first bike I'd weight fit and
37
+ > comfort over outright speed. Track?"
38
+ > **User:** "Yes — I want to actually enjoy riding it."
39
+
40
+ → Deep **`domainSpec`** (→ `domain_spec.md`): the full how-to-buy-well — the
41
+ complete fit process, geometry, gearing theory, material/wheel trade-offs — the
42
+ layer a coarse "size 56, black" request never names. *(If the agent had no web tool,
43
+ it would say so, then write the domain spec from its own knowledge — never fake it.)*
44
+
45
+ **3. `user_spec.md` — one basic question.** The single most-basic niche fact:
46
+
47
+ > **Expert:** "One basic thing I'll keep: your **height** and **inseam**?"
48
+ > **User:** "178 cm, 81 cm inseam."
49
+
50
+ → Seeded partial **`userSpec`** (→ `user_spec.md`): *height 178 / inseam 81 (soft
51
+ facts); HARD-NO: carbon-fibre handlebars (inviolable).* The rest is augmented per
52
+ query.
53
+
54
+ **4. `playbook.md` — one question: compare a set of options (buying taste).**
55
+
56
+ > **Expert:** "Of these three — a value alloy build, a mid-range carbon, a premium
57
+ > race bike — which appeals, and why?"
58
+ > **User:** "The value alloy, around €1500. I don't chase brands."
59
+
60
+ → Seeded partial **`playbook`** (→ `playbook.md`): *value-conscious, ~€1500 feel,
61
+ brand-agnostic; comfort over outright speed.*
62
+
63
+ **5. `intent_spec.md` — sign-off.** The decomposition dimensions, derived from the
64
+ domain spec:
65
+
66
+ > **Expert:** "Every time you ask me to find something, I'll decompose along:
67
+ > use-case, terrain, budget, fit envelope, timeline, compatibility, performance
68
+ > priorities, aesthetics. Sign off?"
69
+ > **User:** "Yep."
70
+
71
+ → **`intentSpec`** (→ `intent_spec.md`): that schema (the dimensions to resolve),
72
+ never a filled-in request.
73
+
74
+ ## Assemble + endorse — the gate
75
+
76
+ Identity confirmed (`road-cycling-buyer` / "Road-Cycling Buyer"), the assembled
77
+ draft is a valid `sil_profile_materialize` input — persona → `SOUL.md`, all four
78
+ SDS specs to the sil store, all present from creation (user side seeded *partial*):
79
+
80
+ ```jsonc
81
+ {
82
+ "agentId": "road-cycling-buyer",
83
+ "name": "Road-Cycling Buyer",
84
+ "persona": "A patient first-road-bike advisor. Always explains fit. Standing rule: never recommend carbon-fibre handlebars.",
85
+ "domainSpec": "## First road bike — how to buy well (deep)\n**Fit is everything**: size from height AND inseam; stack/reach set torso angle; saddle setback from KOPS; crank length scales with inseam; bar reach/drop set hands. Bad fit is the #1 reason first bikes get abandoned.\n## Geometry: endurance (comfort) vs race (speed); head-tube angle + trail govern handling.\n## Groupset & gearing: tier = shift quality + weight, not capability; gear-inches = chainring/cog × wheel; compact vs mid-compact vs 1x trade range for step size — pick for terrain.\n## Material & wheels: alloy vs carbon (feel/price/repairability); rim depth vs crosswind; tyre clearance bounds comfort.\n## Trade-offs: stiffness vs comfort; aero vs crosswind; tier vs budget. First bike: weight fit + comfort over speed.",
86
+ "intentSpec": "## Decomposition dimensions (schema)\nuse-case; terrain; budget band; fit envelope; timeline; compatibility; performance priorities; aesthetics. The per-query fill is ephemeral; this schema is persisted.",
87
+ "userSpec": "## User spec (seeded partial)\n### Soft facts/preferences\n- Height 178 cm, inseam 81 cm.\n- Comfort + enjoyment over outright speed.\n### Hard constraints (INVIOLABLE)\n- HARD-NO: carbon-fibre handlebars.",
88
+ "playbook": "## Buying taste (seeded partial)\n- Value-conscious; budget feel ~€1500.\n- Brand-agnostic. (Finer taste fills in per-query.)"
89
+ }
90
+ ```
91
+
92
+ > **Expert:** "Here's the expert — shall I create it?"
93
+ > **User:** "Yes, create it."
94
+
95
+ **This affirmative act is the gate** — up to here, **zero engine steps ran**. Only
96
+ now does the engine proceed
97
+ ([`../references/agent_creation_engine.md`](../references/agent_creation_engine.md)):
98
+ validate-first → collision check → `openclaw agents add road-cycling-buyer
99
+ --workspace ~/.openclaw/workspace-road-cycling-buyer --non-interactive --json`
100
+ (confirm the inherited profile grants a web tool) → write the persona into
101
+ `SOUL.md` → `sil_profile_materialize { agentId, name, domainSpec, intentSpec,
102
+ userSpec, playbook }` → wire sil:
103
+
104
+ ```
105
+ openclaw config set 'agents.list[<i>].skills' '["sil"]' --strict-json
106
+ openclaw config set plugins.entries.sil.enabled true --strict-json
107
+ ```
108
+
109
+ → `openclaw config validate --json` returns valid → **`created`**.
110
+
111
+ ## As general counsel — an ongoing advisor, not a one-query optimizer
112
+
113
+ The expert is now standing counsel for this buyer's cycling life. Across requests it
114
+ **reuses** what it knows (the 178/81 fit envelope, the no-carbon-bars hard rule, the
115
+ value-conscious taste — **never re-asked**), and on **every query** web-refreshes the
116
+ domain spec, decomposes the request along the intent dimensions, and **augments** the
117
+ already-present user spec + playbook — we keep learning.
118
+
119
+ > **User:** "Find me a first road bike, ~€1500."
120
+
121
+ This is one request, not the point of the expert. It runs the shop-time loop
122
+ ([`../references/expert_shopping.md`](../references/expert_shopping.md) owns the
123
+ map→search→compare→recommend machinery — not repeated here): web-refresh the domain,
124
+ decompose the intent, augment the playbook with a taste it surfaces in context, then
125
+ recommend with a "why" that **cites the layers** — "for your **178/81 fit envelope**
126
+ (kept from before) a 54 cm endurance frame sits right, and **fit/comfort outrank
127
+ outright speed on a first bike** (a domain mechanic), so I passed a lighter race-geo
128
+ bike, all within your value budget." A rationale naming no domain mechanic and reusing
129
+ no stored fact would **fail the SDS bar** even if the bike were fine.
130
+
131
+ Weeks later the *same* counsel handles new needs without re-onboarding:
132
+
133
+ > **User:** "Now a winter bike, same budget."
134
+
135
+ It reuses the fit envelope and taste, decomposes the new intent (all-weather →
136
+ mudguard clearance, tyre durability), and recommends citing the kept fit fact + a
137
+ winter domain mechanic. A "bump my budget to €2000" **updates** the stored taste
138
+ (visibly); but "find me a carbon-handlebar bike" hits the standing **hard rule** —
139
+ intent never overrides a hard constraint.
140
+
141
+ ## Edge cases this example would have handled
142
+
143
+ - **Collision** (`road-cycling-buyer` exists): the engine returns `collision`, writes
144
+ nothing, the conversation offers **refine-or-rename** — never clobbers.
145
+ - **Abandon before endorsement**: nothing created, nothing to tear down — the draft
146
+ lived only in the conversation.
147
+ - **No web tool**: the expert says so honestly and proceeds on the existing domain
148
+ spec — never pretends the refresh happened.
149
+ - **Creation is local + offline** (for identity): no sil registration to create; the
150
+ user registers later, on first shop, via `sil_register`.