sil-openclaw 0.2.4 → 0.3.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.
@@ -0,0 +1,283 @@
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 *behaviour* artefacts (persona + optional
6
+ * domain sub-skill playbook + a typed manifest) into the plugin's own data
7
+ * directory (`$SIL_DATA_DIR`, the disclosed `filesystemScope`). The *wiring*
8
+ * half — the host `agents.list[]` entry, the enabled `sil` plugin, the attached
9
+ * `sil` skill — is the host agent driving its own `openclaw …` CLI under the
10
+ * bundled `skill/SKILL.md` procedure; the plugin never writes `~/.openclaw`
11
+ * (`security.noChildProcess: true`, host config is outside `filesystemScope`).
12
+ *
13
+ * Why a tool (not skill-driven `write`-tool prose): the host agent's only way
14
+ * to invoke plugin code is a registered tool, and a plugin write buys
15
+ * host-validated typed inputs, the structured-error envelope, and ATOMIC
16
+ * all-or-nothing writes — all of which serve the goal's primary correctness
17
+ * bar (a created expert that actually shops). The artefact write lives here;
18
+ * the host-config write stays host-CLI.
19
+ *
20
+ * This follows `identity.ts` (the reference group): a `registerXTools(api)`
21
+ * function, a `Type.Object` schema the host validates inputs against, the
22
+ * `jsonResult` success/structured-error envelope, and ALL I/O inside
23
+ * `execute()` (register() opens nothing).
24
+ */
25
+ import { Type } from "typebox";
26
+ import { listAgentProfiles, materializeProfile, readAgentProfile, removeAgentArtefacts, } from "../lib/profile-store.js";
27
+ import { jsonResult } from "../lib/tool-result.js";
28
+ export function registerProfileTools(api) {
29
+ registerMaterialize(api);
30
+ registerList(api);
31
+ registerGet(api);
32
+ registerRemove(api);
33
+ }
34
+ function registerMaterialize(api) {
35
+ api.registerTool({
36
+ name: "sil_profile_materialize",
37
+ label: "Materialize a sil shopping-expert's behaviour artefacts",
38
+ description: "Write a created sil shopping expert's behaviour artefacts into the sil"
39
+ + " data directory: the persona/instructions, an optional generated domain"
40
+ + " sub-skill (playbook), and a typed manifest the sil skill reads at"
41
+ + " runtime to load them. Call this AFTER the host agent has been created"
42
+ + " (openclaw agents add) and BEFORE openclaw config validate. It does NOT"
43
+ + " touch the host OpenClaw config — the plugin enable + skill attach are"
44
+ + " driven by the host CLI, not this tool. Writes are atomic: an invalid"
45
+ + " spec writes nothing, and a write failure leaves nothing partial.",
46
+ parameters: Type.Object({
47
+ agentId: Type.String({
48
+ description: "The host agent id the expert was created under (agents.list[].id),"
49
+ + " lower-kebab; not \"main\" (host-reserved). Keys the artefact dir.",
50
+ }),
51
+ name: Type.String({
52
+ description: "The human-readable expert name (recorded in the manifest).",
53
+ }),
54
+ persona: Type.String({
55
+ description: "The shopping persona/instructions — the expert's expertise, tone, and"
56
+ + " standing rules. Non-empty. Materialized as persona.md and copied"
57
+ + " into the agent workspace SOUL.md by the skill.",
58
+ }),
59
+ playbook: Type.Optional(Type.String({
60
+ description: "The generated domain sub-skill: how this expert shops on sil (which"
61
+ + " sil_* tool for which intent, refinement rules). Materialized as"
62
+ + " playbook.md and loaded by the sil skill at session start. Omit"
63
+ + " when the expert needs no domain playbook.",
64
+ })),
65
+ }),
66
+ async execute(_callId, params) {
67
+ // The host validates `params` against the schema above before we run, but
68
+ // narrow at the read site (the SDK types params as Record<string,unknown>)
69
+ // and let the store do the real, structured-error validation.
70
+ const spec = {
71
+ agentId: typeof params["agentId"] === "string" ? params["agentId"] : "",
72
+ name: typeof params["name"] === "string" ? params["name"] : "",
73
+ persona: typeof params["persona"] === "string" ? params["persona"] : "",
74
+ ...(typeof params["playbook"] === "string"
75
+ ? { playbook: params["playbook"] }
76
+ : {}),
77
+ };
78
+ const result = materializeProfile(spec);
79
+ if (result.ok) {
80
+ api.logger.info("sil_profile_materialized", {
81
+ agent_id: result.agentId,
82
+ has_playbook: result.playbookPath !== undefined,
83
+ });
84
+ return jsonResult({
85
+ status: "ok",
86
+ agentId: result.agentId,
87
+ dir: result.dir,
88
+ personaPath: result.personaPath,
89
+ ...(result.playbookPath ? { playbookPath: result.playbookPath } : {}),
90
+ profilePath: result.profilePath,
91
+ });
92
+ }
93
+ if (result.kind === "invalid_request") {
94
+ api.logger.warn("sil_profile_invalid_request", { field: result.field });
95
+ return jsonResult({
96
+ status: "invalid_request",
97
+ field: result.field,
98
+ message: result.message,
99
+ });
100
+ }
101
+ // persistence_failed — the path + cause are in `error` (never a token/PII).
102
+ api.logger.error("sil_profile_persistence_failed", { error: result.error });
103
+ return jsonResult({
104
+ status: "persistence_failed",
105
+ error: result.error,
106
+ message: result.message,
107
+ recovery: "fix_data_dir",
108
+ });
109
+ },
110
+ });
111
+ }
112
+ /**
113
+ * `sil_profile_list` — enumerate the user's sil shopping experts (read-only).
114
+ *
115
+ * The artefact store is the source of truth for "what is a sil expert" (a
116
+ * readable `agents/<id>/profile.json`), not the host agent list. Returns each
117
+ * expert summarized from its manifest, most-recently-created first, plus an
118
+ * `unreadable[]` bucket so one corrupt manifest never blinds the user to the
119
+ * rest. An empty store is a normal `ok` outcome (like an empty `sil_search`).
120
+ */
121
+ function registerList(api) {
122
+ api.registerTool({
123
+ name: "sil_profile_list",
124
+ label: "List the user's sil shopping experts",
125
+ description: "List the sil shopping experts the user has created — read-only, no"
126
+ + " arguments. Sourced from the sil data directory's artefact store (each"
127
+ + " agents/<id>/profile.json is the authoritative \"is a sil expert\""
128
+ + " signal — a bare host agent without one is not listed). Returns the"
129
+ + " experts most-recently-created first, each with its agentId, name,"
130
+ + " whether it carries a domain playbook, and createdAt. An empty store is"
131
+ + " a normal, successful empty listing — not an error. One unreadable or"
132
+ + " corrupt manifest is reported inline in `unreadable` and never aborts"
133
+ + " the listing. Reads no token and writes nothing.",
134
+ parameters: Type.Object({}),
135
+ async execute(_callId, _params) {
136
+ const { experts, unreadable } = listAgentProfiles();
137
+ api.logger.info("sil_profile_listed", {
138
+ expert_count: experts.length,
139
+ unreadable_count: unreadable.length,
140
+ });
141
+ return jsonResult({
142
+ status: "ok",
143
+ experts,
144
+ unreadable,
145
+ });
146
+ },
147
+ });
148
+ }
149
+ /**
150
+ * `sil_profile_get` — view one expert's full detail (read-only).
151
+ *
152
+ * Re-runs the writer's `agentId` gate before any read (a traversal-shaped id →
153
+ * `invalid_request`). Returns the manifest plus the persona/playbook bodies so
154
+ * the skill can render a complete view. An unknown or unloadable expert →
155
+ * `not_found` (the skill lists the healthy experts) — never a stack trace or a
156
+ * raw path. Reads no token and writes nothing.
157
+ */
158
+ function registerGet(api) {
159
+ api.registerTool({
160
+ name: "sil_profile_get",
161
+ label: "View one sil shopping expert's detail",
162
+ description: "Show one sil shopping expert's full detail — read-only. Pass its"
163
+ + " `agentId`. Returns the expert's name, its persona/instructions, its"
164
+ + " domain playbook when one exists, the manifest path, and createdAt,"
165
+ + " read from the artefact store so the agent can summarize the expert."
166
+ + " An unknown expert returns `not_found` (list the experts to see which"
167
+ + " exist) — never a stack trace or a raw path. A malformed/traversal id"
168
+ + " returns `invalid_request`. Reads no token and writes nothing.",
169
+ parameters: Type.Object({
170
+ agentId: Type.String({
171
+ description: "The expert's host agent id (lower-kebab, e.g. \"gift-buyer\"; not"
172
+ + " \"main\"). Keys the artefact directory the detail is read from.",
173
+ }),
174
+ }),
175
+ async execute(_callId, params) {
176
+ const agentId = typeof params["agentId"] === "string" ? params["agentId"] : "";
177
+ const result = readAgentProfile(agentId);
178
+ if (result.ok) {
179
+ api.logger.info("sil_profile_viewed", {
180
+ agent_id: result.agentId,
181
+ has_playbook: result.playbook !== undefined,
182
+ });
183
+ return jsonResult({
184
+ status: "ok",
185
+ agentId: result.agentId,
186
+ name: result.name,
187
+ persona: result.persona,
188
+ ...(result.playbook !== undefined ? { playbook: result.playbook } : {}),
189
+ profilePath: result.profilePath,
190
+ createdAt: result.createdAt,
191
+ });
192
+ }
193
+ if (result.kind === "invalid_request") {
194
+ api.logger.warn("sil_profile_get_invalid_request", { field: result.field });
195
+ return jsonResult({
196
+ status: "invalid_request",
197
+ field: result.field,
198
+ message: result.message,
199
+ });
200
+ }
201
+ // not_found — a normal outcome; steer the agent to list-then-retry.
202
+ api.logger.info("sil_profile_get_not_found", { agent_id: result.agentId });
203
+ return jsonResult({
204
+ status: "not_found",
205
+ agentId: result.agentId,
206
+ message: result.message,
207
+ recovery: "sil_profile_list",
208
+ });
209
+ },
210
+ });
211
+ }
212
+ /**
213
+ * `sil_profile_remove` — remove one expert's behaviour artefacts (the sil-side
214
+ * half of a clean removal).
215
+ *
216
+ * This is the ARTEFACT half ONLY. The host-wiring half (the `agents.list[]`
217
+ * entry) is the skill's `openclaw agents remove <agentId>` CLI step, which the
218
+ * skill runs FIRST — the plugin cannot write `~/.openclaw` (`noChildProcess`).
219
+ *
220
+ * Fail-closed: re-runs the `agentId` gate itself, deletes only the single
221
+ * validated leaf directory under `agents/`, and deletes NOTHING on a bad id.
222
+ * Absent target → `not_found` (idempotent — safe to re-run after a partial host
223
+ * failure). A genuine `rmSync` failure → `persistence_failed`. Reads no token.
224
+ */
225
+ function registerRemove(api) {
226
+ api.registerTool({
227
+ name: "sil_profile_remove",
228
+ label: "Remove a sil shopping expert's behaviour artefacts",
229
+ description: "Remove one sil shopping expert's behaviour artefacts from the sil data"
230
+ + " directory (its agents/<id>/ directory). This is the SIL-SIDE half of"
231
+ + " removal only — the host wiring (the agents.list[] entry) is removed"
232
+ + " separately by the host CLI, which the skill runs FIRST (this plugin"
233
+ + " cannot write the host config). Pass the `agentId`. Scoped to exactly"
234
+ + " that one expert: a malformed/traversal/\"main\" id returns"
235
+ + " `invalid_request` and deletes nothing; an unknown id returns"
236
+ + " `not_found` (idempotent — safe to re-run after a partial failure); a"
237
+ + " genuine filesystem failure returns `persistence_failed`. Confirm with"
238
+ + " the user before removing — it is destructive and irreversible.",
239
+ parameters: Type.Object({
240
+ agentId: Type.String({
241
+ description: "The expert's host agent id (lower-kebab, e.g. \"gift-buyer\"; not"
242
+ + " \"main\"). Keys the artefact directory to remove. Exactly one"
243
+ + " expert is affected.",
244
+ }),
245
+ }),
246
+ async execute(_callId, params) {
247
+ const agentId = typeof params["agentId"] === "string" ? params["agentId"] : "";
248
+ const result = removeAgentArtefacts(agentId);
249
+ if (result.ok) {
250
+ api.logger.info("sil_profile_removed", { agent_id: result.agentId });
251
+ return jsonResult({
252
+ status: "removed",
253
+ agentId: result.agentId,
254
+ });
255
+ }
256
+ if (result.kind === "invalid_request") {
257
+ api.logger.warn("sil_profile_remove_invalid_request", { field: result.field });
258
+ return jsonResult({
259
+ status: "invalid_request",
260
+ field: result.field,
261
+ message: result.message,
262
+ });
263
+ }
264
+ if (result.kind === "not_found") {
265
+ api.logger.info("sil_profile_remove_not_found", { agent_id: result.agentId });
266
+ return jsonResult({
267
+ status: "not_found",
268
+ agentId: result.agentId,
269
+ message: result.message,
270
+ recovery: "sil_profile_list",
271
+ });
272
+ }
273
+ // persistence_failed — the path + cause are in `error` (never a token/PII).
274
+ api.logger.error("sil_profile_remove_persistence_failed", { error: result.error });
275
+ return jsonResult({
276
+ status: "persistence_failed",
277
+ error: result.error,
278
+ message: result.message,
279
+ recovery: result.recovery,
280
+ });
281
+ },
282
+ });
283
+ }
@@ -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.0",
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 behaviour artefacts (persona.md, optional playbook.md, profile.json) atomically into $SIL_DATA_DIR/agents/<agentId>/ (owner-only, 0600) — the agent's host-config wiring is driven separately by the host CLI, never by this plugin. 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 + persona/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>/{persona.md,playbook.md,profile.json} (shopping-expert behaviour artefacts written by sil_profile_materialize)"
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.0",
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 shop-time loop. It is additive: 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,106 @@
1
+ # Worked example — a road-cycling shopping expert, end to end
2
+
3
+ A complete walkthrough from a free-form request through the interview ([`../references/brainstorm_interview.md`](../references/brainstorm_interview.md)) to a created expert via the engine ([`../references/agent_creation_engine.md`](../references/agent_creation_engine.md)). The transcript is illustrative — a real interview adapts to the user; this shows the *shape* of convergence and the load-bearing gates.
4
+
5
+ ## 1. The free-form request
6
+
7
+ > **User:** "I want an expert that shops for road-cycling gear for me."
8
+
9
+ Reflect the request back and open with one orienting question — not a form:
10
+
11
+ > **Expert:** "A shopping expert for road-cycling gear — let's shape it together. We can revise anything as we go. To start: are you after a complete bike, or kit and components (wheels, groupsets, apparel)?"
12
+
13
+ ## 2. Narrow the (vague) domain FIRST
14
+
15
+ "Road-cycling gear" is broad. Narrow it before any other section:
16
+
17
+ > **User:** "Mostly components and apparel — I already have a frame."
18
+ > **Expert:** "Got it — so the niche is **road-cycling components & apparel for an existing frame** (wheels, groupsets, finishing kit, clothing), not complete bikes. Does that capture it?"
19
+ > **User:** "Yes."
20
+
21
+ The concrete, confirmed niche is locked before persona/mapping/rubric — the narrow-first gate is satisfied.
22
+
23
+ ## 3. Converge the persona (section 2)
24
+
25
+ > **Expert:** "How should this expert come across — a terse spec-checker, or a chatty guide who explains trade-offs? Any standing rules?"
26
+ > **User:** "Knowledgeable but concise. Always flag compatibility issues with my groupset. No carbon-fibre handlebars — I don't trust them."
27
+ > **Expert:** "Persona: a concise, knowledgeable road-cycling components advisor; standing rules — always flag groupset compatibility, never recommend carbon handlebars. Good?"
28
+ > **User:** "Perfect."
29
+
30
+ → lands in `persona`.
31
+
32
+ ## 4. Converge the three playbook sections (3–5)
33
+
34
+ **Elicitation style:**
35
+ > **Expert:** "When you ask it to shop, should it search right away on a one-line request, or ask a clarifying question or two first?"
36
+ > **User:** "Ask at most one clarifying question, then search."
37
+
38
+ **Answer→`sil_search`-param mapping** (loading [`../references/search_param_mapping.md`](../references/search_param_mapping.md)):
39
+ > **Expert:** "For components the decision-attributes are budget, groupset tier, new vs. secondhand, and where you buy. Where do you stand?"
40
+ > **User:** "Budget around €1200, secondhand is fine, I'm in France and prefer local shops."
41
+
42
+ Translating each stated input to a real param:
43
+
44
+ ```
45
+ query: "road-cycling components 105 groupset" # niche descriptors
46
+ category: "cycling-components"
47
+ price_max: 120000 # €1200 → minor units (cents)
48
+ condition: ["secondhand"] # "secondhand is fine"
49
+ local_merchants: true # "prefer local shops" → ranking bias; query issued in French
50
+ # ship_to: OMITTED — server resolves the registered default address; no sil_whoami round-trip
51
+ ```
52
+
53
+ **Recommendation rubric:**
54
+ > **Expert:** "What matters most when I pick among results?"
55
+ > **User:** "Compatibility first, then value, then weight. Brand X is a hard no."
56
+
57
+ → Rubric: rank by groupset compatibility, then value, then weight; exclude brand X. Tied to the user's *stated* priorities, not a fixed order.
58
+
59
+ All three sections are authored as prose into the single `playbook` string.
60
+
61
+ ## 5. Derive + confirm the identity
62
+
63
+ > **Expert:** "I'll call it **Road-Cycling Buyer** (`road-cycling-buyer`). Good?"
64
+ > **User:** "Yes."
65
+
66
+ → `agentId: road-cycling-buyer` (lower-kebab, ≠ `main`), `name: "Road-Cycling Buyer"`.
67
+
68
+ ## 6. Assemble the draft and present it back
69
+
70
+ The assembled spec — a valid `sil_profile_materialize` input:
71
+
72
+ ```jsonc
73
+ {
74
+ "agentId": "road-cycling-buyer",
75
+ "name": "Road-Cycling Buyer",
76
+ "persona": "A concise, knowledgeable road-cycling components advisor. Standing rules: always flag groupset compatibility; never recommend carbon-fibre handlebars.",
77
+ "playbook": "## Elicitation style\nAsk at most one clarifying question, then search.\n\n## Answer→sil_search-param mapping\n- Budget → price_min/price_max (minor units). Secondhand-ok → condition: [\"secondhand\"]. Local shops → local_merchants: true, query in French. ship_to left empty (server resolves the registered default; no sil_whoami round-trip).\n\n## Recommendation rubric\nRank by groupset compatibility, then value, then weight. Brand X is a hard no."
78
+ }
79
+ ```
80
+
81
+ > **Expert:** "Here's the expert: a concise components advisor that flags compatibility, searches secondhand within ~€1200, biases to local French shops, and ranks compatibility → value → weight. Shall I create it?"
82
+
83
+ ## 7. Explicit endorsement — the gate
84
+
85
+ > **User:** "Yes, create it."
86
+
87
+ **This affirmative act is the gate.** Up to this point, **zero engine steps have run** — nothing was written. Only now does the engine proceed.
88
+
89
+ ## 8. Run the engine (after endorsement)
90
+
91
+ Following [`../references/agent_creation_engine.md`](../references/agent_creation_engine.md) in order:
92
+
93
+ 1. **Validate the spec FIRST** — `agentId` lower-kebab & ≠ `main` ✓, `name` non-blank ✓, `persona` non-blank ✓, `workspace` present ✓.
94
+ 2. **Collision check** — `openclaw agents list --json`; no existing `road-cycling-buyer` → proceed.
95
+ 3. **Create the shell** — `openclaw agents add road-cycling-buyer --workspace ~/.openclaw/workspace-road-cycling-buyer --non-interactive --json`.
96
+ 4. **Materialize artefacts** — `sil_profile_materialize` with the spec writes `persona.md`, `playbook.md`, `profile.json` into `$SIL_DATA_DIR/agents/road-cycling-buyer/`.
97
+ 5. **System framing** — copy `persona.md` into the agent's workspace `SOUL.md`.
98
+ 6. **Wire sil** — `openclaw config set 'agents.list[<i>].skills' '["sil"]' --strict-json` and `openclaw config set plugins.entries.sil.enabled true --strict-json`.
99
+ 7. **Validate with the host's OWN check, THEN declare created** — `openclaw config validate --json` returns valid → outcome **`created`**.
100
+ 8. **Tell the user** — the expert exists; opening it loads the persona + playbook and it shops on its niche with **no further setup**.
101
+
102
+ ## Edge cases this example would have handled
103
+
104
+ - **Collision** (a `road-cycling-buyer` already exists): the engine returns `collision`, writes nothing, and the conversation offers **refine-or-rename** — never clobbers.
105
+ - **Abandon before step 7** of the interview (user walks away pre-endorsement): nothing was created, nothing to tear down — the draft lived only in the conversation.
106
+ - **Creation is local + offline**: no sil registration was needed to create the expert; the user registers later, on first shop, via `sil_register`.
@@ -0,0 +1,65 @@
1
+ # Create a sil-wired shopping expert — the agent-creation engine
2
+
3
+ **Precondition: read and run this reference ONLY after the user has explicitly endorsed the assembled draft from [`brainstorm_interview.md`](brainstorm_interview.md).** Running any step below before that explicit endorsement is forbidden — the interview owns the endorsement gate.
4
+
5
+ When the user wants a **dedicated shopping expert** — "make me a shopping expert for buying gifts", "set up a grocery re-order agent", "create a sil shopping agent" — author and persist a **valid OpenClaw agent profile**: a real new agent under the host `agents` config, with the **sil plugin enabled** and the **sil skill attached**, plus the expert's behaviour artefacts in the sil data directory — so the created agent can shop with **no further setup**.
6
+
7
+ You are the engine. The host config write is **you driving the host's own `openclaw …` CLI** — the sil plugin never writes the host config itself. Run these steps **in order, top to bottom** — the order is the spec.
8
+
9
+ ## The profile spec (input)
10
+
11
+ The endorsed draft from the interview *is* this spec (the persona → `persona`, and the elicitation style + answer→param mapping + rubric → `playbook`):
12
+
13
+ | Field | Meaning | Required? |
14
+ |---|---|---|
15
+ | **agentId** | The new agent's id (lower-kebab, e.g. `gift-buyer`). Becomes `agents.list[].id`. Must be **unique** and is never `main` (host-reserved). | Required |
16
+ | **name** | Human-readable expert name ("Gift Buyer"). | Required |
17
+ | **persona / instructions** | Who this expert is and how it shops — its expertise, tone, standing rules. | Required (non-empty) |
18
+ | **workspace** | The agent's workspace directory (e.g. `~/.openclaw/workspace-gift-buyer`). | Required for the non-interactive add |
19
+ | **playbook (sub-skill)** | An optional generated **domain sub-skill** — a shopping playbook for this expert's niche. | Optional |
20
+
21
+ The **sil plugin** and the **sil skill** are always attached (that is what makes it *sil-wired*). Creating an expert is **local and offline** — it does **not** require or perform sil registration, reads no token, and writes nothing to identity storage. The expert registers the user later, on first shop, via `sil_register`. Do **not** present registration as a prerequisite for creating the profile.
22
+
23
+ ## Engine steps (run in this exact order)
24
+
25
+ 1. **Validate the spec FIRST — before anything is written.** Check `agentId` is present, lower-kebab, unique-looking, and not `main`; `name` is present; `persona`/instructions is non-empty; `workspace` is present. If any check fails, stop with the **`invalid_request`** outcome naming the offending field and **write nothing** — no agent, no artefacts. Nothing partial. This validation runs ahead of every host command, so a bad spec never reaches the host.
26
+
27
+ 2. **Collision check — read before write.** Run `openclaw agents list --json` and confirm no existing agent already uses `agentId`. If one does, stop with the **`collision`** outcome and **do not** run `openclaw agents add` — never overwrite or clobber an existing agent's persona or wiring. Surface the collision so the user can rename. (This list-check precedes the add, so a same-name agent is caught before any change.)
28
+
29
+ 3. **Create the agent shell (host CLI).** Run:
30
+ ```
31
+ openclaw agents add <agentId> --workspace <workspace> --non-interactive --json
32
+ ```
33
+ This creates the real `agents.list[]` entry and the agent's workspace bootstrap files (`SOUL.md`, `AGENTS.md`, …), inheriting model and tool profile from `agents.defaults`. `--non-interactive --json` is required so you can drive it without a prompt and read the structured result.
34
+
35
+ 4. **Materialize the behaviour artefacts into the sil data directory.** Call **`sil_profile_materialize`** with `{ agentId, name, persona, playbook? }`. It writes the expert's behaviour artefacts atomically into **`$SIL_DATA_DIR`** (the sil data directory — the plugin's own disclosed scope) under `agents/<agentId>/`:
36
+ - **`persona.md`** — the persona/instructions that power the expert's behaviour;
37
+ - **`playbook.md`** — the generated domain **sub-skill**, when supplied;
38
+ - **`profile.json`** — the manifest the sil skill reads at runtime to load them.
39
+ These behaviour artefacts live in `$SIL_DATA_DIR`, kept **out of** the thin host `agents` wiring entry. The tool's own outcomes are `ok` / `invalid_request` / `persistence_failed` — on `invalid_request` it wrote nothing; on `persistence_failed` it left nothing partial.
40
+
41
+ 5. **Make the persona the agent's system framing.** Copy the materialized `persona.md` into the new agent's workspace `SOUL.md` (its persona bootstrap file), so the host injects the persona into the expert's system prompt.
42
+
43
+ 6. **Wire the sil skill and plugin into the agent (host CLI).** Attach the sil skill and enable the sil plugin for the created agent. These shapes are asserted against the host the sil-stage round pins — **`alpine/openclaw:2026.6.9`** — where both are value-mode sets driven with `--strict-json` (the only set mode this image accepts):
44
+ ```
45
+ openclaw config set 'agents.list[<i>].skills' '["sil"]' --strict-json
46
+ openclaw config set plugins.entries.sil.enabled true --strict-json
47
+ ```
48
+ The skill attach makes the agent **know how** to drive the tools; the plugin enable makes the four `sil_*` tools available to it (they come for free once the `sil` plugin is enabled). Keep `sil` in the agent's skill list and do not deny the `sil_*` tools in its tool profile.
49
+
50
+ 7. **Validate with the host's OWN check, THEN declare created.** Run `openclaw config validate --json`. On `alpine/openclaw:2026.6.9` the verdict shape is `{ valid, path, issues? }` — success keys off **`.valid`**, never an `ok` field. "Valid" means *the host says yes* — never assert it yourself. Only when the verdict reads `valid: true` do you report the **`created`** outcome. If `openclaw config validate` returns `valid: false` (or any CLI step failed), report **`persistence_failed`** with the failing **path** and **cause** (the `issues?` the verdict reports), and leave nothing partial behind. This validate-after-add step is what guarantees the host will load the profile.
51
+
52
+ 8. **Tell the user it is ready.** On `created`, tell the user the expert exists and how to open it. When they open the new agent, the host loads it: the sil plugin is enabled, the sil skill is attached, `SOUL.md` carries the persona, and the sil skill reads `$SIL_DATA_DIR/agents/<agentId>/profile.json` to load the persona + playbook — the expert calls `sil_search` / `sil_product_get` (and `sil_register` / `sil_whoami` as needed) on the user's intent with **no further setup**.
53
+
54
+ ## Status taxonomy (agent-creation engine)
55
+
56
+ | `status` | Meaning | What to do |
57
+ |---|---|---|
58
+ | `created` | The agent was added, the behaviour artefacts materialized, the sil plugin + skill wired, and `openclaw config validate` accepted it. | Tell the user the expert is ready and how to open it. |
59
+ | `invalid_request` | The spec failed validation (missing/blank field). **Nothing was written.** | Name the field, fix it, run again. Do NOT proceed to `openclaw agents add`. |
60
+ | `collision` | An agent with that id already exists (from `openclaw agents list`). | Surface it; pick a different id. **Never overwrite / clobber** the existing agent. |
61
+ | `persistence_failed` | A write or `openclaw config validate` step failed. The reported **path** + **cause** name what to fix. **Nothing partial** was left behind. | Fix the path/cause (writable config, valid spec), then create the expert again. |
62
+
63
+ ## Runtime — how a created expert loads its behaviour
64
+
65
+ When you (the sil skill) start a session inside a created expert, read `$SIL_DATA_DIR/agents/<agentId>/profile.json`, then load the `persona.md` (reaffirm the standing instructions) and `playbook.md` sub-skill (the domain shopping playbook) it points at. That is what lets the expert shop on its niche with no further setup. When the user then states a shopping intent, shop per [`expert_shopping.md`](expert_shopping.md) — the profile-driven shop-time loop. To sharpen a created expert from what it observed in real sessions, see [`refine_expert.md`](refine_expert.md).