sil-openclaw 0.3.9 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +124 -0
- package/dist/lib/profile-store.js +578 -581
- package/dist/lib/sil-client.js +282 -33
- package/dist/tools/catalog.js +475 -7
- package/dist/tools/profile.js +229 -371
- package/openclaw.plugin.json +6 -4
- package/package.json +1 -1
- package/scripts/create-shopper.mjs +71 -40
- package/sil-shopping/SKILL.md +65 -89
- package/sil-shopping/examples/multi_domain_shopper_walkthrough.md +34 -103
- package/sil-shopping/references/agent_creation_engine.md +177 -118
- package/sil-shopping/references/fill_and_feedback.md +86 -0
- package/sil-shopping/references/method_and_prds.md +111 -0
- package/sil-shopping/references/setup_onboarding.md +48 -52
- package/sil-shopping/references/shop_loop.md +109 -160
- package/sil-shopping/references/brainstorm_interview.md +0 -97
- package/sil-shopping/references/catalog_tools_reference.md +0 -44
- package/sil-shopping/references/manage_domains.md +0 -77
- package/sil-shopping/references/refine_shopper.md +0 -97
- package/sil-shopping/references/search_param_mapping.md +0 -79
package/dist/tools/profile.js
CHANGED
|
@@ -1,442 +1,300 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* sil shopper profile tools — the
|
|
2
|
+
* sil shopper profile tools — the frontmatter-as-truth artefact seam.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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`).
|
|
4
|
+
* FIVE local verbs over the singleton shopper store ($SIL_DATA_DIR/shopper), each
|
|
5
|
+
* making NO network call and reading no token:
|
|
16
6
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
7
|
+
* - `sil_profile_materialize { name, userSpec }` — SETUP-ONLY: write user_spec.md
|
|
8
|
+
* (its frontmatter carries the shopper name). Does NOT mint methods/PRDs.
|
|
9
|
+
* - `sil_learn { target, domain?, prd?, kind, … }` — the single target+change verb
|
|
10
|
+
* for the whole method/PRD lifecycle: create mints a whole doc; append/amend/
|
|
11
|
+
* retract refine in place; attach-asset persists image bytes by path.
|
|
12
|
+
* - `sil_profile_search { domain?, product?, intent?, query? }` — query artefact
|
|
13
|
+
* FRONTMATTER (coordinates only, no bodies); the discovery / reuse-before-mint
|
|
14
|
+
* primitive. Malformed frontmatter surfaces in `unreadable`, never dropped.
|
|
15
|
+
* - `sil_profile_get { domainSlug, prd? }` — the rich read (one whole body).
|
|
16
|
+
* - `sil_profile_remove { domainSlug, prd? }` — remove a whole domain, or one PRD.
|
|
23
17
|
*
|
|
24
|
-
* This follows `identity.ts` (the reference group): a `registerXTools(api)`
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
18
|
+
* This follows `identity.ts` (the reference group): a `registerXTools(api)` function,
|
|
19
|
+
* a `Type.Object` schema the host validates inputs against, the `jsonResult`
|
|
20
|
+
* success/structured-error envelope, and ALL I/O inside `execute()` (register() opens
|
|
21
|
+
* nothing). The persona is NOT written here — it is the host workspace SOUL.md.
|
|
28
22
|
*/
|
|
29
23
|
import { Type } from "typebox";
|
|
30
|
-
import {
|
|
24
|
+
import { learnArtefact, materializeProfile, readArtefactBody, removeArtefact, searchProfileFrontmatter, } from "../lib/profile-store.js";
|
|
31
25
|
import { jsonResult } from "../lib/tool-result.js";
|
|
32
|
-
/** Narrow a host-validated param to a string, defaulting to "" so the store does
|
|
33
|
-
*
|
|
26
|
+
/** Narrow a host-validated param to a string, defaulting to "" so the store does the
|
|
27
|
+
* real, structured-error validation (validate-first / write-nothing). */
|
|
34
28
|
function asString(value) {
|
|
35
29
|
return typeof value === "string" ? value : "";
|
|
36
30
|
}
|
|
31
|
+
/** Narrow an optional string param — `undefined` unless a non-empty string is given,
|
|
32
|
+
* so a selector is never carried as a spurious empty value. */
|
|
33
|
+
function optString(value) {
|
|
34
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
35
|
+
}
|
|
37
36
|
export function registerProfileTools(api) {
|
|
38
37
|
registerMaterialize(api);
|
|
38
|
+
registerLearn(api);
|
|
39
|
+
registerSearch(api);
|
|
39
40
|
registerGet(api);
|
|
40
41
|
registerRemove(api);
|
|
41
|
-
registerRemember(api);
|
|
42
42
|
}
|
|
43
43
|
function registerMaterialize(api) {
|
|
44
44
|
api.registerTool({
|
|
45
45
|
name: "sil_profile_materialize",
|
|
46
|
-
label: "
|
|
47
|
-
description: "
|
|
48
|
-
+ "
|
|
49
|
-
+ "
|
|
50
|
-
+ "
|
|
51
|
-
+ "
|
|
52
|
-
+ "
|
|
53
|
-
+ "
|
|
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).",
|
|
46
|
+
label: "Set up the sil shopper",
|
|
47
|
+
description: "SETUP-ONLY: create the one sil shopper by writing its shared user_spec.md — the"
|
|
48
|
+
+ " person's cross-niche facts + hard constraints — with the shopper `name` in the"
|
|
49
|
+
+ " file's frontmatter (no manifest). Does NOT mint any domain method or PRD (that"
|
|
50
|
+
+ " is sil_learn create). Run ONCE at setup; refine later with sil_learn, never a"
|
|
51
|
+
+ " re-materialize (it overwrites the whole body). `name` + `userSpec` required and"
|
|
52
|
+
+ " non-empty. Local-only, no network. Blank input → invalid_request; write failure"
|
|
53
|
+
+ " → persistence_failed.",
|
|
63
54
|
parameters: Type.Object({
|
|
64
55
|
name: Type.String({
|
|
65
|
-
description: "The human-readable shopper name (recorded in
|
|
56
|
+
description: "The human-readable shopper name (recorded in user_spec.md frontmatter).",
|
|
66
57
|
}),
|
|
67
58
|
userSpec: Type.String({
|
|
68
|
-
description: "The
|
|
69
|
-
+ " constraints
|
|
70
|
-
+ "
|
|
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.",
|
|
59
|
+
description: "The shared user spec — the one person's cross-domain facts + hard"
|
|
60
|
+
+ " constraints. REQUIRED, non-empty. Read by every domain's shop loop, so a"
|
|
61
|
+
+ " fact captured in one niche is reused in another without re-asking.",
|
|
75
62
|
}),
|
|
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
|
-
})),
|
|
108
63
|
}),
|
|
109
64
|
async execute(_callId, params) {
|
|
110
|
-
|
|
111
|
-
// narrow at the read site (the SDK types params as Record<string,unknown>)
|
|
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
|
-
}
|
|
125
|
-
const spec = {
|
|
65
|
+
const result = materializeProfile({
|
|
126
66
|
name: asString(params["name"]),
|
|
127
67
|
userSpec: asString(params["userSpec"]),
|
|
128
|
-
|
|
129
|
-
};
|
|
130
|
-
const result = materializeProfile(spec);
|
|
68
|
+
});
|
|
131
69
|
if (result.ok) {
|
|
132
|
-
api.logger.info("sil_profile_materialized", {
|
|
133
|
-
|
|
134
|
-
});
|
|
135
|
-
const payload = {
|
|
136
|
-
status: "ok",
|
|
137
|
-
dir: result.dir,
|
|
138
|
-
userSpecPath: result.userSpecPath,
|
|
139
|
-
profilePath: result.profilePath,
|
|
140
|
-
};
|
|
141
|
-
if (result.domain)
|
|
142
|
-
payload["domain"] = result.domain;
|
|
143
|
-
return jsonResult(payload);
|
|
70
|
+
api.logger.info("sil_profile_materialized", {});
|
|
71
|
+
return jsonResult({ status: "ok", dir: result.dir, userSpecPath: result.userSpecPath });
|
|
144
72
|
}
|
|
145
|
-
|
|
146
|
-
api.logger.warn("sil_profile_invalid_request", { field: result.field });
|
|
147
|
-
return jsonResult({
|
|
148
|
-
status: "invalid_request",
|
|
149
|
-
field: result.field,
|
|
150
|
-
message: result.message,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
// persistence_failed — the path + cause are in `error` (never a token/PII).
|
|
154
|
-
api.logger.error("sil_profile_persistence_failed", { error: result.error });
|
|
155
|
-
return jsonResult({
|
|
156
|
-
status: "persistence_failed",
|
|
157
|
-
error: result.error,
|
|
158
|
-
message: result.message,
|
|
159
|
-
recovery: "fix_data_dir",
|
|
160
|
-
});
|
|
73
|
+
return mapFailure(api, "sil_profile_materialize", result);
|
|
161
74
|
},
|
|
162
75
|
});
|
|
163
76
|
}
|
|
164
|
-
|
|
165
|
-
* `sil_profile_get` — view the shopper at TWO zoom levels (read-only, no `agentId`).
|
|
166
|
-
*
|
|
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.
|
|
175
|
-
*/
|
|
176
|
-
function registerGet(api) {
|
|
77
|
+
function registerLearn(api) {
|
|
177
78
|
api.registerTool({
|
|
178
|
-
name: "
|
|
179
|
-
label: "
|
|
180
|
-
description: "
|
|
181
|
-
+ "
|
|
182
|
-
+ "
|
|
183
|
-
+ " per-
|
|
184
|
-
+ "
|
|
185
|
-
+ "
|
|
186
|
-
+ "
|
|
187
|
-
+ "
|
|
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.",
|
|
79
|
+
name: "sil_learn",
|
|
80
|
+
label: "Teach the sil shopper (create or refine a method / PRD)",
|
|
81
|
+
description: "The single target+change verb owning the sil shopper's method/PRD lifecycle."
|
|
82
|
+
+ " `target` (user_spec | method | prd) picks WHERE the change lands; `kind`"
|
|
83
|
+
+ " (create | append | amend | retract | attach-asset) picks the change — the"
|
|
84
|
+
+ " per-field schema names which fields each needs. `create` mints a whole method/"
|
|
85
|
+
+ "PRD (not valid for user_spec); append/amend/retract/attach-asset need the target"
|
|
86
|
+
+ " to exist (else not_found). `hard` (append to user_spec/prd only) marks an"
|
|
87
|
+
+ " inviolable constraint. Local-only, atomic, owner-only, no network; a bad field"
|
|
88
|
+
+ " → invalid_request and writes nothing.",
|
|
192
89
|
parameters: Type.Object({
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
90
|
+
target: Type.Union([Type.Literal("user_spec"), Type.Literal("method"), Type.Literal("prd")], { description: "WHERE the change lands: user_spec | method | prd." }),
|
|
91
|
+
kind: Type.Union([
|
|
92
|
+
Type.Literal("create"),
|
|
93
|
+
Type.Literal("append"),
|
|
94
|
+
Type.Literal("amend"),
|
|
95
|
+
Type.Literal("retract"),
|
|
96
|
+
Type.Literal("attach-asset"),
|
|
97
|
+
], { description: "The change: create | append | amend | retract | attach-asset." }),
|
|
98
|
+
domain: Type.Optional(Type.String({ description: "The domain slug (lower-kebab, not \"main\") — required for method/prd." })),
|
|
99
|
+
prd: Type.Optional(Type.String({ description: "The PRD key <product>-<intent> (lower-kebab) — required for a prd target." })),
|
|
100
|
+
name: Type.Optional(Type.String({ description: "create method: the human-readable domain name." })),
|
|
101
|
+
body: Type.Optional(Type.String({ description: "create: the whole markdown body to mint." })),
|
|
102
|
+
product: Type.Optional(Type.String({ description: "create prd: the product type." })),
|
|
103
|
+
intent: Type.Optional(Type.String({ description: "create prd: the use-context (general when context-free)." })),
|
|
104
|
+
title: Type.Optional(Type.String({ description: "create prd: the human-readable job title." })),
|
|
105
|
+
text: Type.Optional(Type.String({ description: "append: the one bullet to add." })),
|
|
106
|
+
from: Type.Optional(Type.String({ description: "amend/retract: the exact bullet text to match (single occurrence)." })),
|
|
107
|
+
to: Type.Optional(Type.String({ description: "amend: the replacement bullet text." })),
|
|
108
|
+
section: Type.Optional(Type.String({ description: "append/amend/retract: the `## section` to scope to." })),
|
|
109
|
+
hard: Type.Optional(Type.Boolean({ description: "append to user_spec/prd only: mark an inviolable constraint the shop loop rejects against." })),
|
|
110
|
+
bytes: Type.Optional(Type.String({ description: "attach-asset: the image bytes, base64-encoded." })),
|
|
111
|
+
mime: Type.Optional(Type.String({ description: "attach-asset: image/jpeg | image/png | image/webp | image/gif." })),
|
|
112
|
+
caption: Type.Optional(Type.String({ description: "attach-asset: an optional caption for the markdown link." })),
|
|
197
113
|
}),
|
|
198
114
|
async execute(_callId, params) {
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
115
|
+
const spec = {
|
|
116
|
+
target: params["target"] ?? "method",
|
|
117
|
+
kind: params["kind"] ?? "append",
|
|
118
|
+
domain: optString(params["domain"]),
|
|
119
|
+
prd: optString(params["prd"]),
|
|
120
|
+
name: optString(params["name"]),
|
|
121
|
+
body: optString(params["body"]),
|
|
122
|
+
product: optString(params["product"]),
|
|
123
|
+
intent: optString(params["intent"]),
|
|
124
|
+
title: optString(params["title"]),
|
|
125
|
+
text: optString(params["text"]),
|
|
126
|
+
from: optString(params["from"]),
|
|
127
|
+
to: optString(params["to"]),
|
|
128
|
+
section: optString(params["section"]),
|
|
129
|
+
hard: params["hard"] === true ? true : undefined,
|
|
130
|
+
bytes: optString(params["bytes"]),
|
|
131
|
+
mime: optString(params["mime"]),
|
|
132
|
+
caption: optString(params["caption"]),
|
|
133
|
+
};
|
|
134
|
+
const result = learnArtefact(spec);
|
|
202
135
|
if (result.ok) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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,
|
|
136
|
+
// Non-PII markers only — no artefact body/text is ever logged.
|
|
137
|
+
api.logger.info("sil_learned", {
|
|
138
|
+
kind: result.kind,
|
|
139
|
+
target: result.target,
|
|
140
|
+
domain_slug: result.domain,
|
|
141
|
+
prd: result.prd,
|
|
226
142
|
});
|
|
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
143
|
return jsonResult({
|
|
243
|
-
status: "
|
|
244
|
-
|
|
245
|
-
|
|
144
|
+
status: "ok",
|
|
145
|
+
kind: result.kind,
|
|
146
|
+
target: result.target,
|
|
147
|
+
...(result.domain !== undefined ? { domain: result.domain } : {}),
|
|
148
|
+
...(result.prd !== undefined ? { prd: result.prd } : {}),
|
|
149
|
+
path: result.path,
|
|
150
|
+
...(result.assetPath !== undefined ? { assetPath: result.assetPath } : {}),
|
|
246
151
|
});
|
|
247
152
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
153
|
+
return mapFailure(api, "sil_learn", result);
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function registerSearch(api) {
|
|
158
|
+
api.registerTool({
|
|
159
|
+
name: "sil_profile_search",
|
|
160
|
+
label: "Search what the sil shopper knows (domains + PRDs)",
|
|
161
|
+
description: "Query the sil shopper's artefact FRONTMATTER — the discovery / reuse-before-mint"
|
|
162
|
+
+ " primitive. Returns COORDINATES only (no bodies): the domains learned ({slug,"
|
|
163
|
+
+ " name}) and their PRDs ({domain, key, product, intent, title}). All filters"
|
|
164
|
+
+ " optional — none = full overview; narrow by domain/product/intent/query. A"
|
|
165
|
+
+ " filesystem scan: malformed frontmatter is surfaced in `unreadable`, never"
|
|
166
|
+
+ " dropped; healthy siblings still list. Empty store → ok with empty lists. When"
|
|
167
|
+
+ " NO domain matches, the result carries `next_step: mint_domain` — the cue to"
|
|
168
|
+
+ " mint the niche (sil_learn create) BEFORE shopping. Local-only, no network.",
|
|
169
|
+
parameters: Type.Object({
|
|
170
|
+
domain: Type.Optional(Type.String({ description: "Filter to one domain slug." })),
|
|
171
|
+
product: Type.Optional(Type.String({ description: "Filter PRDs by product type." })),
|
|
172
|
+
intent: Type.Optional(Type.String({ description: "Filter PRDs by intent (use-context)." })),
|
|
173
|
+
query: Type.Optional(Type.String({ description: "Free-text substring match over the coordinates." })),
|
|
174
|
+
}),
|
|
175
|
+
async execute(_callId, params) {
|
|
176
|
+
const result = searchProfileFrontmatter({
|
|
177
|
+
domain: optString(params["domain"]),
|
|
178
|
+
product: optString(params["product"]),
|
|
179
|
+
intent: optString(params["intent"]),
|
|
180
|
+
query: optString(params["query"]),
|
|
181
|
+
});
|
|
182
|
+
api.logger.info("sil_profile_searched", {
|
|
183
|
+
domain_count: result.domains.length,
|
|
184
|
+
prd_count: result.prds.length,
|
|
185
|
+
unreadable_count: result.unreadable.length,
|
|
186
|
+
});
|
|
187
|
+
// The mint trigger. No matching domain came back (an empty store, or a
|
|
188
|
+
// filtered miss on a populated one) — this IS the reuse-before-mint MISS, and
|
|
189
|
+
// it is where a first shop silently stalls: the model finds nothing to reuse
|
|
190
|
+
// and, with no next move in hand, answers a buy-intent off the open web. Carry
|
|
191
|
+
// the next action in the result so the MISS itself points at the mint, the way
|
|
192
|
+
// the catalog tools carry `recovery`. Absent when a domain matched.
|
|
193
|
+
const noMatch = result.domains.length === 0;
|
|
251
194
|
return jsonResult({
|
|
252
|
-
status: "
|
|
253
|
-
|
|
254
|
-
|
|
195
|
+
status: "ok",
|
|
196
|
+
domains: result.domains,
|
|
197
|
+
prds: result.prds,
|
|
198
|
+
unreadable: result.unreadable,
|
|
199
|
+
...(noMatch
|
|
200
|
+
? {
|
|
201
|
+
next_step: "mint_domain",
|
|
202
|
+
guidance: "No learned domain matches this request. To shop this niche, mint"
|
|
203
|
+
+ " its domain FIRST: research the buying guide, then sil_learn create"
|
|
204
|
+
+ " (target: method). Then shop with sil_search — a buy-intent is"
|
|
205
|
+
+ " answered from the sil catalog, never from the open web.",
|
|
206
|
+
}
|
|
207
|
+
: {}),
|
|
255
208
|
});
|
|
256
209
|
},
|
|
257
210
|
});
|
|
258
211
|
}
|
|
259
|
-
|
|
260
|
-
* `sil_profile_remove` — remove ONE of the shopper's domain packs (artefact half).
|
|
261
|
-
*
|
|
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.
|
|
268
|
-
*/
|
|
269
|
-
function registerRemove(api) {
|
|
212
|
+
function registerGet(api) {
|
|
270
213
|
api.registerTool({
|
|
271
|
-
name: "
|
|
272
|
-
label: "
|
|
273
|
-
description: "
|
|
274
|
-
+ " (
|
|
275
|
-
+ "
|
|
276
|
-
+ "
|
|
277
|
-
+ "
|
|
278
|
-
+ "
|
|
279
|
-
+ "
|
|
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.",
|
|
214
|
+
name: "sil_profile_get",
|
|
215
|
+
label: "Read one sil shopper document (method or PRD)",
|
|
216
|
+
description: "Read ONE full body from the sil shopper's store. `domainSlug` alone → the method"
|
|
217
|
+
+ " body (buying guide + taste + search vocabulary); `domainSlug` + `prd` → that"
|
|
218
|
+
+ " PRD body (requirements + filled preferences). Discover coordinates with"
|
|
219
|
+
+ " sil_profile_search first. Missing → not_found; present-but-corrupt frontmatter"
|
|
220
|
+
+ " → unreadable (inspect/repair — do NOT overwrite, it may be recoverable), distinct"
|
|
221
|
+
+ " from not_found; a bad/traversal/\"main\" slug → invalid_request. Local-only, no"
|
|
222
|
+
+ " network.",
|
|
283
223
|
parameters: Type.Object({
|
|
284
224
|
domainSlug: Type.String({
|
|
285
|
-
description: "The domain slug to
|
|
286
|
-
+ " exactly one domain pack is affected; the shopper itself is not.",
|
|
225
|
+
description: "The domain slug to read (lower-kebab, not \"main\"). REQUIRED.",
|
|
287
226
|
}),
|
|
227
|
+
prd: Type.Optional(Type.String({ description: "OPTIONAL. A PRD key to read that PRD's body instead of the method." })),
|
|
288
228
|
}),
|
|
289
229
|
async execute(_callId, params) {
|
|
290
|
-
const
|
|
291
|
-
const result = removeAgentArtefacts(domainSlug);
|
|
230
|
+
const result = readArtefactBody(asString(params["domainSlug"]), optString(params["prd"]));
|
|
292
231
|
if (result.ok) {
|
|
293
|
-
api.logger.info("
|
|
294
|
-
return jsonResult({
|
|
295
|
-
status: "removed",
|
|
296
|
-
domainSlug: result.domainSlug,
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
if (result.kind === "invalid_request") {
|
|
300
|
-
api.logger.warn("sil_profile_remove_invalid_request", { field: result.field });
|
|
232
|
+
api.logger.info("sil_profile_read", { target: result.target, domain_slug: result.domain, prd: result.prd });
|
|
301
233
|
return jsonResult({
|
|
302
|
-
status: "
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
return jsonResult({
|
|
310
|
-
status: "not_found",
|
|
311
|
-
message: result.message,
|
|
312
|
-
recovery: "sil_profile_get",
|
|
234
|
+
status: "ok",
|
|
235
|
+
target: result.target,
|
|
236
|
+
domain: result.domain,
|
|
237
|
+
...(result.prd !== undefined ? { prd: result.prd } : {}),
|
|
238
|
+
fields: result.fields,
|
|
239
|
+
body: result.body,
|
|
240
|
+
path: result.path,
|
|
313
241
|
});
|
|
314
242
|
}
|
|
315
|
-
|
|
316
|
-
api.logger.error("sil_profile_remove_persistence_failed", { error: result.error });
|
|
317
|
-
return jsonResult({
|
|
318
|
-
status: "persistence_failed",
|
|
319
|
-
error: result.error,
|
|
320
|
-
message: result.message,
|
|
321
|
-
recovery: result.recovery,
|
|
322
|
-
});
|
|
243
|
+
return mapFailure(api, "sil_profile_get", result);
|
|
323
244
|
},
|
|
324
245
|
});
|
|
325
246
|
}
|
|
326
|
-
|
|
327
|
-
* `sil_remember` — the lightweight per-query APPEND memory verb.
|
|
328
|
-
*
|
|
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).
|
|
336
|
-
*
|
|
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).
|
|
340
|
-
*/
|
|
341
|
-
function registerRemember(api) {
|
|
247
|
+
function registerRemove(api) {
|
|
342
248
|
api.registerTool({
|
|
343
|
-
name: "
|
|
344
|
-
label: "
|
|
345
|
-
description: "
|
|
346
|
-
+ "
|
|
347
|
-
+ "
|
|
348
|
-
+ "
|
|
349
|
-
+ "
|
|
350
|
-
+ "
|
|
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.",
|
|
249
|
+
name: "sil_profile_remove",
|
|
250
|
+
label: "Remove a sil shopper domain, or one of its PRDs",
|
|
251
|
+
description: "Remove artefacts from the sil shopper's store. `domainSlug` alone removes the"
|
|
252
|
+
+ " WHOLE domain subtree (method + all PRDs + assets); `domainSlug` + `prd` removes"
|
|
253
|
+
+ " just that ONE PRD (method + siblings survive). Destructive — confirm with the"
|
|
254
|
+
+ " user first. A bad/traversal/\"main\" slug → invalid_request (deletes nothing); an"
|
|
255
|
+
+ " unregistered domain/PRD → not_found (idempotent); a filesystem failure →"
|
|
256
|
+
+ " persistence_failed. Never removes the shopper itself. Local-only, no network.",
|
|
364
257
|
parameters: Type.Object({
|
|
365
|
-
|
|
366
|
-
description: "
|
|
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.",
|
|
258
|
+
domainSlug: Type.String({
|
|
259
|
+
description: "The domain slug to remove from (lower-kebab, not \"main\"). REQUIRED.",
|
|
373
260
|
}),
|
|
374
|
-
|
|
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
|
-
})),
|
|
261
|
+
prd: Type.Optional(Type.String({ description: "OPTIONAL. A PRD key to remove just that PRD instead of the whole domain." })),
|
|
386
262
|
}),
|
|
387
263
|
async execute(_callId, params) {
|
|
388
|
-
|
|
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);
|
|
264
|
+
const result = removeArtefact(asString(params["domainSlug"]), optString(params["prd"]));
|
|
403
265
|
if (result.ok) {
|
|
404
|
-
|
|
405
|
-
// logged.
|
|
406
|
-
api.logger.info("sil_remembered", {
|
|
407
|
-
kind: result.kind,
|
|
408
|
-
domain_slug: result.domain,
|
|
409
|
-
});
|
|
410
|
-
return jsonResult({
|
|
411
|
-
status: "ok",
|
|
412
|
-
kind: result.kind,
|
|
413
|
-
...(result.domain !== undefined ? { domain: result.domain } : {}),
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
if (result.kind === "invalid_request") {
|
|
417
|
-
api.logger.warn("sil_remember_invalid_request", { field: result.field });
|
|
266
|
+
api.logger.info("sil_profile_removed", { domain_slug: result.domainSlug, prd: result.prd });
|
|
418
267
|
return jsonResult({
|
|
419
|
-
status: "
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
if (result.kind === "not_found") {
|
|
425
|
-
api.logger.info("sil_remember_not_found", {});
|
|
426
|
-
return jsonResult({
|
|
427
|
-
status: "not_found",
|
|
428
|
-
message: result.message,
|
|
429
|
-
recovery: "sil_profile_materialize",
|
|
268
|
+
status: "removed",
|
|
269
|
+
domainSlug: result.domainSlug,
|
|
270
|
+
...(result.prd !== undefined ? { prd: result.prd } : {}),
|
|
430
271
|
});
|
|
431
272
|
}
|
|
432
|
-
|
|
433
|
-
api.logger.error("sil_remember_persistence_failed", { error: result.error });
|
|
434
|
-
return jsonResult({
|
|
435
|
-
status: "persistence_failed",
|
|
436
|
-
error: result.error,
|
|
437
|
-
message: result.message,
|
|
438
|
-
recovery: result.recovery,
|
|
439
|
-
});
|
|
273
|
+
return mapFailure(api, "sil_profile_remove", result);
|
|
440
274
|
},
|
|
441
275
|
});
|
|
442
276
|
}
|
|
277
|
+
/** Map a store failure variant to the canonical structured envelope + a non-PII log. */
|
|
278
|
+
function mapFailure(api, tool, result) {
|
|
279
|
+
if (result.kind === "invalid_request") {
|
|
280
|
+
api.logger.warn(tool + "_invalid_request", { field: result.field });
|
|
281
|
+
return jsonResult({ status: "invalid_request", field: result.field, message: result.message });
|
|
282
|
+
}
|
|
283
|
+
if (result.kind === "not_found") {
|
|
284
|
+
api.logger.info(tool + "_not_found", {});
|
|
285
|
+
return jsonResult({ status: "not_found", message: result.message });
|
|
286
|
+
}
|
|
287
|
+
if (result.kind === "unreadable") {
|
|
288
|
+
// A present-but-corrupt artefact — steer the agent to inspect/repair, NEVER re-mint
|
|
289
|
+
// over it (silent data loss on a recoverable artefact). Distinct from not_found.
|
|
290
|
+
api.logger.warn(tool + "_unreadable", {});
|
|
291
|
+
return jsonResult({ status: "unreadable", message: result.message, recovery: "inspect_artefact" });
|
|
292
|
+
}
|
|
293
|
+
api.logger.error(tool + "_persistence_failed", { error: result.error });
|
|
294
|
+
return jsonResult({
|
|
295
|
+
status: "persistence_failed",
|
|
296
|
+
error: result.error,
|
|
297
|
+
message: result.message,
|
|
298
|
+
recovery: result.recovery,
|
|
299
|
+
});
|
|
300
|
+
}
|