sil-openclaw 0.3.5 → 0.3.6

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.
@@ -1,127 +1,146 @@
1
1
  /**
2
- * sil shopping-expert profile tools.
2
+ * sil shopper profile tools — the single multi-domain shopper seam.
3
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 `sil-shopping/SKILL.md` procedure; the
14
- * plugin never writes `~/.openclaw` (`security.noChildProcess: true`, host
15
- * config is outside `filesystemScope`).
4
+ * `sil_profile_materialize` is the plugin's half of the agent-creation engine and
5
+ * the lazy domain-mint path: it writes the SHARED user spec and, when a `domain`
6
+ * pack is supplied, that niche's SDS artefacts
7
+ * (`domains/<slug>/{domain_spec,intent_spec,playbook}.md`) into the plugin's own
8
+ * data directory (`$SIL_DATA_DIR`, the disclosed `filesystemScope`). It stays ONE
9
+ * tool with an OPTIONAL `domain`: no `domain` ⇒ create the one shopper; with
10
+ * `domain` ⇒ lazily mint/refresh a niche AND persist any cross-niche fact captured
11
+ * into the shared user spec — one atomic call. The persona is NOT written here —
12
+ * the shopper's identity/voice is the host workspace `SOUL.md`. The wiring half
13
+ * (the host `agents.list[]` entry, the enabled `sil` plugin, the attached skill,
14
+ * the `SOUL.md`) is the host agent driving its own `openclaw …` CLI; the plugin
15
+ * never writes `~/.openclaw` (`security.noChildProcess: true`).
16
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.
17
+ * The product is a SINGLETON shopper, so the store is scoped to a fixed,
18
+ * compile-time-constant path — there is no caller-supplied `agentId` on ANY of the
19
+ * four profile tools. Domain classification / routing at shop time stays
20
+ * SKILL-REASONING — there is no routing tool. The surface is exactly four profile
21
+ * tools; the skill reads `profile.json.domains` (via `sil_profile_get`) to pick or
22
+ * lazily mint a niche.
23
23
  *
24
24
  * This follows `identity.ts` (the reference group): a `registerXTools(api)`
25
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).
26
+ * `jsonResult` success/structured-error envelope, and ALL I/O inside `execute()`
27
+ * (register() opens nothing).
28
28
  */
29
29
  import { Type } from "typebox";
30
- import { listAgentProfiles, materializeProfile, readAgentProfile, removeAgentArtefacts, } from "../lib/profile-store.js";
30
+ import { appendProfileEntry, materializeProfile, readAgentProfile, removeAgentArtefacts, } from "../lib/profile-store.js";
31
31
  import { jsonResult } from "../lib/tool-result.js";
32
+ /** Narrow a host-validated param to a string, defaulting to "" so the store does
33
+ * the real, structured-error validation (validate-first / write-nothing). */
34
+ function asString(value) {
35
+ return typeof value === "string" ? value : "";
36
+ }
32
37
  export function registerProfileTools(api) {
33
38
  registerMaterialize(api);
34
- registerList(api);
35
39
  registerGet(api);
36
40
  registerRemove(api);
41
+ registerRemember(api);
37
42
  }
38
43
  function registerMaterialize(api) {
39
44
  api.registerTool({
40
45
  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.",
46
+ label: "Materialize the sil shopper / mint a domain pack",
47
+ description: "Write the one sil shopper's behaviour artefacts into the sil data directory."
48
+ + " ONE tool, two modes. WITHOUT a `domain`: create the shopper — write the"
49
+ + " SHARED user spec (the one person's standing facts + hard constraints that"
50
+ + " carry across every niche) and a manifest with an empty domains map. WITH a"
51
+ + " `domain`: lazily mint or refresh that niche on first shop — write its domain"
52
+ + " spec (deep researched niche expertise), intent spec (the decomposition"
53
+ + " dimensions a query must resolve) and playbook (the niche buying taste) under"
54
+ + " domains/<slug>/, AND overwrite the shared user spec (so a cross-niche fact"
55
+ + " surfaced in the same query is persisted) — all in one atomic call that"
56
+ + " upserts domains[slug]. `userSpec` is REQUIRED on every call (pass the full"
57
+ + " updated body — it overwrites atomically). The persona is NOT written here —"
58
+ + " it is the host workspace SOUL.md. Re-run with the SAME domain.slug to refresh"
59
+ + " a niche in place. Does NOT touch the host OpenClaw config. Writes are atomic:"
60
+ + " an invalid spec writes nothing, and a write failure leaves nothing partial (a"
61
+ + " failed new-domain mint tears down only that fresh leaf; the shopper and"
62
+ + " siblings survive).",
59
63
  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
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.",
65
+ description: "The human-readable shopper name (recorded in the manifest).",
83
66
  }),
84
67
  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.",
68
+ description: "The SHARED user spec — the one person's domain-relevant facts + hard"
69
+ + " constraints (addresses, sizes, allergy/ethics rules they never break,"
70
+ + " budget psychology) that carry across EVERY niche. REQUIRED, non-empty on"
71
+ + " every call. Materialized as user_spec.md and read by every domain's shop"
72
+ + " loop, so a fact captured while shopping one niche is reused in another"
73
+ + " without being re-asked. On any augment, pass the full updated body — it"
74
+ + " overwrites atomically.",
98
75
  }),
76
+ domain: Type.Optional(Type.Object({
77
+ slug: Type.String({
78
+ description: "The domain slug, lower-kebab; not \"main\". Keys domains/<slug>/."
79
+ + " Reuse the slug of an existing matching niche before minting a new"
80
+ + " one (the skill dedups; the store enforces only shape).",
81
+ }),
82
+ name: Type.String({
83
+ description: "The human-readable domain name (e.g. \"Road cycling\").",
84
+ }),
85
+ domainSpec: Type.String({
86
+ description: "The SDS domain spec — deep researched niche expertise: how to buy"
87
+ + " well in the niche and its full mechanics. REQUIRED, non-empty."
88
+ + " Materialized as domains/<slug>/domain_spec.md; web-refreshed every"
89
+ + " query.",
90
+ }),
91
+ intentSpec: Type.String({
92
+ description: "The SDS intent spec — the decomposition DIMENSIONS a shopping query"
93
+ + " in this niche must resolve (use-case, budget, compatibility…),"
94
+ + " derived from the domain spec. REQUIRED, non-empty. The dimension"
95
+ + " SCHEMA only — the per-query intent is ephemeral. Materialized as"
96
+ + " domains/<slug>/intent_spec.md.",
97
+ }),
98
+ playbook: Type.String({
99
+ description: "The SDS playbook — the user's buying TASTE for THIS niche (price"
100
+ + " band, brand leanings, niche-mechanical preferences). REQUIRED,"
101
+ + " non-empty. Materialized as domains/<slug>/playbook.md. On a"
102
+ + " per-query augment, pass the full updated body.",
103
+ }),
104
+ }, {
105
+ description: "OPTIONAL per-domain pack. Omit to create/refresh the shopper only;"
106
+ + " include to lazily mint or refresh a niche.",
107
+ })),
99
108
  }),
100
109
  async execute(_callId, params) {
101
110
  // The host validates `params` against the schema above before we run, but
102
111
  // narrow at the read site (the SDK types params as Record<string,unknown>)
103
112
  // and let the store do the real, structured-error validation.
113
+ const rawDomain = params["domain"];
114
+ let domain;
115
+ if (typeof rawDomain === "object" && rawDomain !== null) {
116
+ const d = rawDomain;
117
+ domain = {
118
+ slug: asString(d["slug"]),
119
+ name: asString(d["name"]),
120
+ domainSpec: asString(d["domainSpec"]),
121
+ intentSpec: asString(d["intentSpec"]),
122
+ playbook: asString(d["playbook"]),
123
+ };
124
+ }
104
125
  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"] : "",
126
+ name: asString(params["name"]),
127
+ userSpec: asString(params["userSpec"]),
128
+ ...(domain ? { domain } : {}),
111
129
  };
112
130
  const result = materializeProfile(spec);
113
131
  if (result.ok) {
114
- api.logger.info("sil_profile_materialized", { agent_id: result.agentId });
115
- return jsonResult({
132
+ api.logger.info("sil_profile_materialized", {
133
+ domain_slug: result.domain?.slug,
134
+ });
135
+ const payload = {
116
136
  status: "ok",
117
- agentId: result.agentId,
118
137
  dir: result.dir,
119
- domainSpecPath: result.domainSpecPath,
120
- intentSpecPath: result.intentSpecPath,
121
138
  userSpecPath: result.userSpecPath,
122
- playbookPath: result.playbookPath,
123
139
  profilePath: result.profilePath,
124
- });
140
+ };
141
+ if (result.domain)
142
+ payload["domain"] = result.domain;
143
+ return jsonResult(payload);
125
144
  }
126
145
  if (result.kind === "invalid_request") {
127
146
  api.logger.warn("sil_profile_invalid_request", { field: result.field });
@@ -143,154 +162,259 @@ function registerMaterialize(api) {
143
162
  });
144
163
  }
145
164
  /**
146
- * `sil_profile_list` — enumerate the user's sil shopping experts (read-only).
165
+ * `sil_profile_get` — view the shopper at TWO zoom levels (read-only, no `agentId`).
147
166
  *
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`).
167
+ * WITHOUT a `domainSlug` (Zoom A — absorbs the old standalone listing surface): the
168
+ * shopper overview — its name, the SHARED user spec, the domain index (each niche's
169
+ * slug/name/timestamps, no bodies) and the `unreadable[]` degraded-directory array.
170
+ * An EMPTY store, or a freshly-created shopper with no domains, is `ok` (empty-is-
171
+ * healthy) — never `not_found`. WITH a `domainSlug` (Zoom C): that one domain's
172
+ * three bodies (domain spec, intent spec, playbook) PLUS the shared user spec. An
173
+ * unminted/unloadable domain → `not_found` (recovery: the no-args `sil_profile_get`);
174
+ * a malformed/traversal slug → `invalid_request`. Reads no token and writes nothing.
153
175
  */
154
- function registerList(api) {
176
+ function registerGet(api) {
155
177
  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
- });
178
+ name: "sil_profile_get",
179
+ label: "View the sil shopper overview or one domain",
180
+ description: "Show the sil shopper's detail — read-only. WITHOUT a `domainSlug`: the shopper"
181
+ + " overview — its name, the SHARED user spec (the one person's facts + hard"
182
+ + " constraints), the domain index (each niche's slug/name/timestamps, no"
183
+ + " per-domain bodies) and any degraded directories in `unreadable`. This is the"
184
+ + " way to see what the shopper knows / which domains it has learned. An empty"
185
+ + " store, or a freshly-created shopper with no domains, returns ok (healthy,"
186
+ + " empty domain index) — never not_found. WITH a `domainSlug`: that one"
187
+ + " domain's pack — its domain spec, intent spec and playbook (buying taste)"
188
+ + " PLUS the shared user spec. The persona is not here — it is the host"
189
+ + " workspace SOUL.md. An unminted/unloadable domain returns `not_found` (omit"
190
+ + " the domainSlug to see what exists). A malformed/traversal slug returns"
191
+ + " `invalid_request`. Reads no token and writes nothing.",
192
+ parameters: Type.Object({
193
+ domainSlug: Type.Optional(Type.String({
194
+ description: "OPTIONAL. A domain slug to view that niche's pack; omit for the shopper"
195
+ + " overview (name + shared user spec + domain index).",
196
+ })),
197
+ }),
198
+ async execute(_callId, params) {
199
+ const rawSlug = params["domainSlug"];
200
+ const domainSlug = typeof rawSlug === "string" ? rawSlug : undefined;
201
+ const result = readAgentProfile(domainSlug);
202
+ if (result.ok) {
203
+ if (result.slug !== undefined) {
204
+ // Per-domain read (Zoom C) — the niche's three bodies + the shared user spec.
205
+ api.logger.info("sil_profile_viewed", { domain_slug: result.slug });
206
+ return jsonResult({
207
+ status: "ok",
208
+ name: result.name,
209
+ slug: result.slug,
210
+ userSpec: result.userSpec,
211
+ domainSpec: result.domainSpec,
212
+ intentSpec: result.intentSpec,
213
+ playbook: result.playbook,
214
+ profilePath: result.profilePath,
215
+ createdAt: result.createdAt,
216
+ updatedAt: result.updatedAt,
217
+ });
218
+ }
219
+ // Zoom A overview — the domain index + unreadable[]; the shared user spec +
220
+ // identity only when a shopper actually exists (an empty store is healthy
221
+ // and carries no shopper content).
222
+ api.logger.info("sil_profile_viewed", {
223
+ shopper_present: result.name !== undefined,
224
+ domain_count: result.domains.length,
225
+ unreadable_count: result.unreadable.length,
226
+ });
227
+ const payload = {
228
+ status: "ok",
229
+ domains: result.domains,
230
+ unreadable: result.unreadable,
231
+ };
232
+ if (result.name !== undefined) {
233
+ payload["name"] = result.name;
234
+ payload["userSpec"] = result.userSpec;
235
+ payload["profilePath"] = result.profilePath;
236
+ payload["createdAt"] = result.createdAt;
237
+ }
238
+ return jsonResult(payload);
239
+ }
240
+ if (result.kind === "invalid_request") {
241
+ api.logger.warn("sil_profile_get_invalid_request", { field: result.field });
242
+ return jsonResult({
243
+ status: "invalid_request",
244
+ field: result.field,
245
+ message: result.message,
246
+ });
247
+ }
248
+ // not_found — a normal outcome; steer the agent to the no-args read (the
249
+ // overview), never to a now-removed standalone listing tool.
250
+ api.logger.info("sil_profile_get_not_found", {});
176
251
  return jsonResult({
177
- status: "ok",
178
- experts,
179
- unreadable,
252
+ status: "not_found",
253
+ message: result.message,
254
+ recovery: "sil_profile_get",
180
255
  });
181
256
  },
182
257
  });
183
258
  }
184
259
  /**
185
- * `sil_profile_get` — view one expert's full detail (read-only).
260
+ * `sil_profile_remove` — remove ONE of the shopper's domain packs (artefact half).
186
261
  *
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.
262
+ * `domainSlug` is REQUIRED — there is no omit-deletes-everything trap; removing the
263
+ * whole shopper is a host concern, not this tool. Removes exactly the one
264
+ * `domains/<slug>/` leaf and de-registers it from the manifest; the shopper and the
265
+ * SHARED user spec survive. Re-runs the gate itself, deletes NOTHING on a bad/
266
+ * missing slug. Absent (unregistered) slug → `not_found` (idempotent). A genuine
267
+ * `rmSync`/rewrite failure → `persistence_failed`. Reads no token.
192
268
  */
193
- function registerGet(api) {
269
+ function registerRemove(api) {
194
270
  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.",
271
+ name: "sil_profile_remove",
272
+ label: "Remove one of the sil shopper's domains",
273
+ description: "Remove ONE of the sil shopper's domain packs from the sil data directory"
274
+ + " (its domains/<slug>/ directory) — the SIL-SIDE artefact half only. Pass"
275
+ + " `domainSlug`; it is REQUIRED — this never deletes the whole shopper"
276
+ + " (decommissioning the shopper is a host concern). Scoped to exactly that one"
277
+ + " domain: the shopper, the SHARED user spec, and every sibling domain survive."
278
+ + " A malformed/traversal/\"main\" or missing slug returns `invalid_request` and"
279
+ + " deletes nothing; an unregistered slug returns `not_found` (idempotent — safe"
280
+ + " to re-run after a partial failure); a genuine filesystem failure returns"
281
+ + " `persistence_failed`. Confirm with the user before removing — it is"
282
+ + " destructive and irreversible.",
206
283
  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.",
284
+ domainSlug: Type.String({
285
+ description: "The domain slug to remove (lower-kebab; not \"main\"). REQUIRED —"
286
+ + " exactly one domain pack is affected; the shopper itself is not.",
210
287
  }),
211
288
  }),
212
289
  async execute(_callId, params) {
213
- const agentId = typeof params["agentId"] === "string" ? params["agentId"] : "";
214
- const result = readAgentProfile(agentId);
290
+ const domainSlug = asString(params["domainSlug"]);
291
+ const result = removeAgentArtefacts(domainSlug);
215
292
  if (result.ok) {
216
- api.logger.info("sil_profile_viewed", { agent_id: result.agentId });
293
+ api.logger.info("sil_profile_removed", { domain_slug: result.domainSlug });
217
294
  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,
295
+ status: "removed",
296
+ domainSlug: result.domainSlug,
227
297
  });
228
298
  }
229
299
  if (result.kind === "invalid_request") {
230
- api.logger.warn("sil_profile_get_invalid_request", { field: result.field });
300
+ api.logger.warn("sil_profile_remove_invalid_request", { field: result.field });
231
301
  return jsonResult({
232
302
  status: "invalid_request",
233
303
  field: result.field,
234
304
  message: result.message,
235
305
  });
236
306
  }
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 });
307
+ if (result.kind === "not_found") {
308
+ api.logger.info("sil_profile_remove_not_found", {});
309
+ return jsonResult({
310
+ status: "not_found",
311
+ message: result.message,
312
+ recovery: "sil_profile_get",
313
+ });
314
+ }
315
+ // persistence_failed — the path + cause are in `error` (never a token/PII).
316
+ api.logger.error("sil_profile_remove_persistence_failed", { error: result.error });
239
317
  return jsonResult({
240
- status: "not_found",
241
- agentId: result.agentId,
318
+ status: "persistence_failed",
319
+ error: result.error,
242
320
  message: result.message,
243
- recovery: "sil_profile_list",
321
+ recovery: result.recovery,
244
322
  });
245
323
  },
246
324
  });
247
325
  }
248
326
  /**
249
- * `sil_profile_remove` — remove one expert's behaviour artefacts (the sil-side
250
- * half of a clean removal).
327
+ * `sil_remember` — the lightweight per-query APPEND memory verb.
251
328
  *
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`).
329
+ * Appends ONE typed learning without re-emitting the whole document — the cheap
330
+ * path the model actually takes under load (vs. the heavy whole-doc
331
+ * `sil_profile_materialize` round-trip). `kind:"fact"` (something true about the
332
+ * person) lands in the shared `user_spec.md` and carries across every niche;
333
+ * `kind:"taste"` (how they like to buy in this niche) lands in the active domain's
334
+ * `playbook.md`. `hard:true` marks an inviolable user-spec constraint (FACT only);
335
+ * `domain` selects the niche for a TASTE (omitted ⇒ the single registered domain).
255
336
  *
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.
337
+ * Thin over `appendProfileEntry`: narrow the host-validated params, call the store,
338
+ * map the discriminated result to the canonical envelope. The remembered `text` is
339
+ * user content — it is NEVER written to a log payload (only non-PII markers are).
260
340
  */
261
- function registerRemove(api) {
341
+ function registerRemember(api) {
262
342
  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.",
343
+ name: "sil_remember",
344
+ label: "Remember one fact or taste for the sil shopper",
345
+ description: "Append ONE typed learning to the sil shopper's behaviour artefacts — the"
346
+ + " CHEAP per-query persistence path (no whole-doc round-trip). Use this every"
347
+ + " query to capture something the interaction surfaced, in the open (never"
348
+ + " silently). `kind:\"fact\"` records something true about the PERSON (a"
349
+ + " measurement, a size, an address, an allergy/ethics rule) — it appends to the"
350
+ + " shared user spec and carries across EVERY niche; set `hard:true` to mark an"
351
+ + " INVIOLABLE constraint (a reject-at-pick rule, FACTS only). `kind:\"taste\"`"
352
+ + " records how the person likes to BUY in a niche (price band, brand leaning) —"
353
+ + " it appends to that niche's buying-taste playbook; pass `domain` to select the"
354
+ + " niche (omit it only when the shopper has exactly one). ONE discrete learning"
355
+ + " per call — two facts and a taste are three calls. Append-only and accretive:"
356
+ + " it never rewrites or de-duplicates the doc — a contradiction or a full"
357
+ + " refine/overwrite stays the whole-doc sil_profile_materialize path. Makes NO"
358
+ + " network call and reads no token; writes one short line via O_APPEND. A blank"
359
+ + " text, a fact carrying a domain, a taste carrying hard:true, or a"
360
+ + " malformed/traversal/\"main\" taste domain returns invalid_request and writes"
361
+ + " nothing; an unknown shopper / unminted domain / missing body returns"
362
+ + " not_found (mint it first); a genuine write failure returns"
363
+ + " persistence_failed.",
275
364
  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.",
365
+ kind: Type.Union([Type.Literal("fact"), Type.Literal("taste")], {
366
+ description: "\"fact\" → the shared user spec (true about the person; carries across"
367
+ + " niches). \"taste\" → the active domain's buying-taste playbook (how they"
368
+ + " buy in THIS niche).",
369
+ }),
370
+ text: Type.String({
371
+ description: "The ONE short learning to record (a single discrete fact or taste). Keep it"
372
+ + " to one entry — it is appended verbatim as a markdown bullet.",
280
373
  }),
374
+ domain: Type.Optional(Type.String({
375
+ description: "TASTE only — the domain slug (lower-kebab; not \"main\") to append the"
376
+ + " taste to. Omit ONLY when the shopper has exactly one domain (it"
377
+ + " resolves automatically); with 2+ domains, omitting it is ambiguous and"
378
+ + " returns invalid_request. Ignored / a category error on a fact.",
379
+ })),
380
+ hard: Type.Optional(Type.Boolean({
381
+ description: "FACT only — true marks an INVIOLABLE user-spec constraint (an allergy, an"
382
+ + " ethics rule, an age gate) the shop loop rejects candidates against."
383
+ + " Taste is always soft, so hard:true on a taste is a contradiction"
384
+ + " (invalid_request).",
385
+ })),
281
386
  }),
282
387
  async execute(_callId, params) {
283
- const agentId = typeof params["agentId"] === "string" ? params["agentId"] : "";
284
- const result = removeAgentArtefacts(agentId);
388
+ // Host-validated against the schema above; narrow at the read site (the SDK
389
+ // types params as Record<string,unknown>) and let the store do the real,
390
+ // structured-error validation. Only carry domain/hard when meaningfully set
391
+ // so a fact never carries a spurious `domain: undefined`.
392
+ const kind = params["kind"] === "taste" ? "taste" : "fact";
393
+ const rawDomain = params["domain"];
394
+ const domain = typeof rawDomain === "string" ? rawDomain : undefined;
395
+ const hard = params["hard"] === true ? true : undefined;
396
+ const spec = {
397
+ kind,
398
+ text: asString(params["text"]),
399
+ ...(domain !== undefined ? { domain } : {}),
400
+ ...(hard !== undefined ? { hard } : {}),
401
+ };
402
+ const result = appendProfileEntry(spec);
285
403
  if (result.ok) {
286
- api.logger.info("sil_profile_removed", { agent_id: result.agentId });
404
+ // Non-PII marker only — the remembered `text` is user content and is never
405
+ // logged.
406
+ api.logger.info("sil_remembered", {
407
+ kind: result.kind,
408
+ domain_slug: result.domain,
409
+ });
287
410
  return jsonResult({
288
- status: "removed",
289
- agentId: result.agentId,
411
+ status: "ok",
412
+ kind: result.kind,
413
+ ...(result.domain !== undefined ? { domain: result.domain } : {}),
290
414
  });
291
415
  }
292
416
  if (result.kind === "invalid_request") {
293
- api.logger.warn("sil_profile_remove_invalid_request", { field: result.field });
417
+ api.logger.warn("sil_remember_invalid_request", { field: result.field });
294
418
  return jsonResult({
295
419
  status: "invalid_request",
296
420
  field: result.field,
@@ -298,16 +422,15 @@ function registerRemove(api) {
298
422
  });
299
423
  }
300
424
  if (result.kind === "not_found") {
301
- api.logger.info("sil_profile_remove_not_found", { agent_id: result.agentId });
425
+ api.logger.info("sil_remember_not_found", {});
302
426
  return jsonResult({
303
427
  status: "not_found",
304
- agentId: result.agentId,
305
428
  message: result.message,
306
- recovery: "sil_profile_list",
429
+ recovery: "sil_profile_materialize",
307
430
  });
308
431
  }
309
432
  // persistence_failed — the path + cause are in `error` (never a token/PII).
310
- api.logger.error("sil_profile_remove_persistence_failed", { error: result.error });
433
+ api.logger.error("sil_remember_persistence_failed", { error: result.error });
311
434
  return jsonResult({
312
435
  status: "persistence_failed",
313
436
  error: result.error,