sil-openclaw 0.3.5 → 0.3.7
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.
- package/CHANGELOG.md +54 -0
- package/README.md +40 -34
- package/dist/lib/profile-store.js +520 -337
- package/dist/tools/profile.js +317 -194
- package/openclaw.plugin.json +4 -4
- package/package.json +1 -1
- package/sil-shopping/SKILL.md +18 -17
- package/sil-shopping/examples/multi_domain_shopper_walkthrough.md +190 -0
- package/sil-shopping/references/agent_creation_engine.md +35 -32
- package/sil-shopping/references/brainstorm_interview.md +31 -47
- package/sil-shopping/references/manage_domains.md +56 -0
- package/sil-shopping/references/refine_shopper.md +48 -0
- package/sil-shopping/references/search_param_mapping.md +12 -12
- package/sil-shopping/references/shop_loop.md +109 -0
- package/sil-shopping/examples/road_cycling_expert_walkthrough.md +0 -150
- package/sil-shopping/references/expert_shopping.md +0 -79
- package/sil-shopping/references/manage_experts.md +0 -42
- package/sil-shopping/references/refine_expert.md +0 -43
package/dist/tools/profile.js
CHANGED
|
@@ -1,127 +1,146 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* sil
|
|
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
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
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
|
-
*
|
|
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 {
|
|
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
|
|
42
|
-
description: "Write
|
|
43
|
-
+ "
|
|
44
|
-
+ "
|
|
45
|
-
+ "
|
|
46
|
-
+ "
|
|
47
|
-
+ "
|
|
48
|
-
+ "
|
|
49
|
-
+ "
|
|
50
|
-
+ "
|
|
51
|
-
+ "
|
|
52
|
-
+ "
|
|
53
|
-
+ "
|
|
54
|
-
+ "
|
|
55
|
-
+ "
|
|
56
|
-
+ "
|
|
57
|
-
+ "
|
|
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
|
|
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
|
|
86
|
-
+ " constraints (
|
|
87
|
-
+ "
|
|
88
|
-
+ "
|
|
89
|
-
+ "
|
|
90
|
-
+ "
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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", {
|
|
115
|
-
|
|
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
|
-
* `
|
|
165
|
+
* `sil_profile_get` — view the shopper at TWO zoom levels (read-only, no `agentId`).
|
|
147
166
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
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
|
|
176
|
+
function registerGet(api) {
|
|
155
177
|
api.registerTool({
|
|
156
|
-
name: "
|
|
157
|
-
label: "
|
|
158
|
-
description: "
|
|
159
|
-
+ "
|
|
160
|
-
+ "
|
|
161
|
-
+ "
|
|
162
|
-
+ "
|
|
163
|
-
+ "
|
|
164
|
-
+ "
|
|
165
|
-
+ "
|
|
166
|
-
+ "
|
|
167
|
-
+ "
|
|
168
|
-
+ "
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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: "
|
|
178
|
-
|
|
179
|
-
|
|
252
|
+
status: "not_found",
|
|
253
|
+
message: result.message,
|
|
254
|
+
recovery: "sil_profile_get",
|
|
180
255
|
});
|
|
181
256
|
},
|
|
182
257
|
});
|
|
183
258
|
}
|
|
184
259
|
/**
|
|
185
|
-
* `
|
|
260
|
+
* `sil_profile_remove` — remove ONE of the shopper's domain packs (artefact half).
|
|
186
261
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
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
|
|
269
|
+
function registerRemove(api) {
|
|
194
270
|
api.registerTool({
|
|
195
|
-
name: "
|
|
196
|
-
label: "
|
|
197
|
-
description: "
|
|
198
|
-
+ "
|
|
199
|
-
+ "
|
|
200
|
-
+ "
|
|
201
|
-
+ "
|
|
202
|
-
+ "
|
|
203
|
-
+ "
|
|
204
|
-
+ "
|
|
205
|
-
+ "
|
|
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
|
-
|
|
208
|
-
description: "The
|
|
209
|
-
+ "
|
|
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
|
|
214
|
-
const result =
|
|
290
|
+
const domainSlug = asString(params["domainSlug"]);
|
|
291
|
+
const result = removeAgentArtefacts(domainSlug);
|
|
215
292
|
if (result.ok) {
|
|
216
|
-
api.logger.info("
|
|
293
|
+
api.logger.info("sil_profile_removed", { domain_slug: result.domainSlug });
|
|
217
294
|
return jsonResult({
|
|
218
|
-
status: "
|
|
219
|
-
|
|
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("
|
|
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
|
-
|
|
238
|
-
|
|
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: "
|
|
241
|
-
|
|
318
|
+
status: "persistence_failed",
|
|
319
|
+
error: result.error,
|
|
242
320
|
message: result.message,
|
|
243
|
-
recovery:
|
|
321
|
+
recovery: result.recovery,
|
|
244
322
|
});
|
|
245
323
|
},
|
|
246
324
|
});
|
|
247
325
|
}
|
|
248
326
|
/**
|
|
249
|
-
* `
|
|
250
|
-
* half of a clean removal).
|
|
327
|
+
* `sil_remember` — the lightweight per-query APPEND memory verb.
|
|
251
328
|
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
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
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
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
|
|
341
|
+
function registerRemember(api) {
|
|
262
342
|
api.registerTool({
|
|
263
|
-
name: "
|
|
264
|
-
label: "
|
|
265
|
-
description: "
|
|
266
|
-
+ "
|
|
267
|
-
+ "
|
|
268
|
-
+ "
|
|
269
|
-
+ "
|
|
270
|
-
+ "
|
|
271
|
-
+ "
|
|
272
|
-
+ "
|
|
273
|
-
+ "
|
|
274
|
-
+ "
|
|
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
|
-
|
|
277
|
-
description: "
|
|
278
|
-
+ " \"
|
|
279
|
-
+ "
|
|
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
|
-
|
|
284
|
-
|
|
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
|
-
|
|
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: "
|
|
289
|
-
|
|
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("
|
|
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("
|
|
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: "
|
|
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("
|
|
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,
|