sil-openclaw 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +128 -0
- package/README.md +68 -4
- package/dist/index.js +2 -0
- package/dist/lib/poller.js +9 -3
- package/dist/lib/profile-store.js +426 -0
- package/dist/tools/identity.js +201 -23
- package/dist/tools/profile.js +283 -0
- package/openclaw.plugin.json +7 -3
- package/package.json +1 -1
- package/skill/SKILL.md +29 -36
- package/skill/examples/road_cycling_expert_walkthrough.md +106 -0
- package/skill/references/agent_creation_engine.md +65 -0
- package/skill/references/brainstorm_interview.md +68 -0
- package/skill/references/catalog_tools_reference.md +46 -0
- package/skill/references/expert_shopping.md +112 -0
- package/skill/references/manage_experts.md +100 -0
- package/skill/references/refine_expert.md +41 -0
- package/skill/references/search_param_mapping.md +35 -0
package/dist/tools/identity.js
CHANGED
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
* inside execute(), never at register time.
|
|
31
31
|
*/
|
|
32
32
|
import { Type } from "typebox";
|
|
33
|
-
import { getWebUrl, getApiUrl } from "../lib/config.js";
|
|
34
|
-
import { clearTokens, hasTokens, readConfig, readTokens, writeConfig, writeTokens, } from "../lib/credentials.js";
|
|
33
|
+
import { getWebUrl, getWebUrlSource, getApiUrl } from "../lib/config.js";
|
|
34
|
+
import { clearTokens, getTokensPath, hasTokens, readConfig, readTokens, writeConfig, writeTokens, } from "../lib/credentials.js";
|
|
35
35
|
import { deriveChallenge, newSessionId, newVerifier } from "../lib/pkce.js";
|
|
36
36
|
import { POLL_DEADLINE_MS, POLL_INTERVAL_MS, startPoll, } from "../lib/poller.js";
|
|
37
37
|
import { claimSession, fetchIdentity, refreshAndRetryOnce, } from "../lib/sil-client.js";
|
|
@@ -59,14 +59,21 @@ function registerRegister(api) {
|
|
|
59
59
|
user: config?.user ?? null,
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
+
// A fresh registration attempt clears any prior in-process persist-failure
|
|
63
|
+
// marker: this process is starting over, so a stale marker from an earlier
|
|
64
|
+
// failed attempt must not make a later genuine `not_registered` (or this
|
|
65
|
+
// attempt's own outcome) masquerade as `persistence_failed`. (FIX C.)
|
|
66
|
+
clearPersistFailure();
|
|
62
67
|
// 2 — mint PKCE. The verifier stays in this closure (never on disk).
|
|
63
68
|
const sessionId = newSessionId();
|
|
64
69
|
const verifier = newVerifier();
|
|
65
70
|
const challenge = deriveChallenge(verifier);
|
|
66
|
-
|
|
71
|
+
// The sil-WEB origin (auth authority) — this is what the auth URL is built
|
|
72
|
+
// from. The local was historically misnamed `apiUrl`; it is the web origin.
|
|
73
|
+
const webUrl = getWebUrl();
|
|
67
74
|
// 3 — build the auth URL. Opening it (by the user's browser) is what
|
|
68
75
|
// creates the pending session server-side; the plugin does not pre-POST.
|
|
69
|
-
const authUrl = `${stripTrailingSlash(
|
|
76
|
+
const authUrl = `${stripTrailingSlash(webUrl)}/authorize`
|
|
70
77
|
+ `?session=${sessionId}&code_challenge=${challenge}`;
|
|
71
78
|
// 4 — fire-and-forget bounded poll. Not awaited: execute() returns now.
|
|
72
79
|
// The poll step maps each claim outcome to the loop's done/continue
|
|
@@ -76,18 +83,35 @@ function registerRegister(api) {
|
|
|
76
83
|
startPoll({
|
|
77
84
|
intervalMs: POLL_INTERVAL_MS,
|
|
78
85
|
deadlineMs: POLL_DEADLINE_MS,
|
|
79
|
-
poll: () => claimStep(
|
|
86
|
+
poll: () => claimStep(webUrl, sessionId, verifier),
|
|
80
87
|
onDone: (result) => handleDone(api, sessionId, result),
|
|
81
88
|
});
|
|
82
89
|
api.logger.info("sil_register_started", { session_id: sessionId });
|
|
83
90
|
return jsonResult({
|
|
84
91
|
status: "awaiting_browser",
|
|
85
|
-
|
|
92
|
+
// The steer lead line routes the user into their OWN default browser
|
|
93
|
+
// BEFORE the Auth0 leg (where Auth0's session cookie works on its own
|
|
94
|
+
// domain), instead of an in-app/embedded webview that partitions it and
|
|
95
|
+
// dead-ends the login. It is a SEPARATE line ABOVE the link, so the link
|
|
96
|
+
// line stays exactly `<authUrl>` — ONE atomic, angle-bracket-wrapped
|
|
97
|
+
// target that a greedy chat auto-linker captures WHOLE (`&code_challenge`
|
|
98
|
+
// included) instead of truncating at the `&` and 400-ing
|
|
99
|
+
// `invalid_code_challenge`. `auth_url` below stays the canonical,
|
|
100
|
+
// UNWRAPPED machine field agents parse. (FIX A + system-browser steer.)
|
|
101
|
+
message: BROWSER_STEER_HUMAN
|
|
102
|
+
+ "\n"
|
|
103
|
+
+ presentAuthLink(authUrl),
|
|
86
104
|
auth_url: authUrl,
|
|
87
105
|
session_id: sessionId,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
106
|
+
// The agent-facing steer MUST agree with the human `message` (both built
|
|
107
|
+
// from the shared BROWSER_STEER_NEGATIVE clause) so an agent relaying the
|
|
108
|
+
// instruction can't paraphrase it back to a generic "a browser" and
|
|
109
|
+
// re-open the cookie-blocking-webview gap.
|
|
110
|
+
instructions: "Share the auth URL with the user and tell them to "
|
|
111
|
+
+ BROWSER_STEER_AGENT
|
|
112
|
+
+ " The plugin is polling in the background — once the user finishes"
|
|
113
|
+
+ " signing in, call sil_register again to confirm (it will report"
|
|
114
|
+
+ " already_registered).",
|
|
91
115
|
});
|
|
92
116
|
},
|
|
93
117
|
});
|
|
@@ -132,11 +156,35 @@ function registerWhoami(api) {
|
|
|
132
156
|
+ " the recovery action (run sil_register).",
|
|
133
157
|
parameters: Type.Object({}),
|
|
134
158
|
async execute() {
|
|
135
|
-
// 1 — not registered: terminal, zero network calls.
|
|
159
|
+
// 1 — not registered: terminal, zero network calls. If THIS process saw a
|
|
160
|
+
// token-persist failure (auth succeeded but the write failed), surface the
|
|
161
|
+
// distinct `persistence_failed` state instead — the no-tokens.json state on
|
|
162
|
+
// disk is identical for both, so the in-process marker is the only signal
|
|
163
|
+
// that tells them apart (FIX C; cold-restart correctly degrades to
|
|
164
|
+
// not_registered — see the persistence_failed/notRegistered helpers).
|
|
136
165
|
const stored = readTokens();
|
|
137
166
|
if (stored === null) {
|
|
138
|
-
|
|
167
|
+
const failure = getPersistFailure();
|
|
168
|
+
return failure !== null ? persistenceFailed(failure) : notRegistered();
|
|
139
169
|
}
|
|
170
|
+
// B (origin visibility): resolve the sil-WEB origin (the origin the
|
|
171
|
+
// registration link is built from) + its source, surface it on the success
|
|
172
|
+
// payload so a wrong/staging origin is diagnosable BEFORE anything 404s,
|
|
173
|
+
// and emit a single warn when the source is non-default. Warn-only — a
|
|
174
|
+
// staging/self-host origin is legitimate, so it is NEVER rejected. Scope is
|
|
175
|
+
// the WEB origin only; the sil-api read origin is out of scope. (FIX B.)
|
|
176
|
+
const webOrigin = getWebUrl();
|
|
177
|
+
const webOriginSource = getWebUrlSource();
|
|
178
|
+
if (webOriginSource !== "default") {
|
|
179
|
+
api.logger.warn("sil_whoami_web_origin_override", {
|
|
180
|
+
web_origin: webOrigin,
|
|
181
|
+
web_origin_source: webOriginSource,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
const originBlock = {
|
|
185
|
+
web_origin: webOrigin,
|
|
186
|
+
web_origin_source: webOriginSource,
|
|
187
|
+
};
|
|
140
188
|
// 2 — read identity; on a 401 refresh-and-retry ONCE via the shared
|
|
141
189
|
// choreography (the SAME `refreshAndRetryOnce` path sil_search /
|
|
142
190
|
// sil_product_get use — 401 recovery is uniform across every
|
|
@@ -152,7 +200,7 @@ function registerWhoami(api) {
|
|
|
152
200
|
// logs-only, no token material, NOT a payload field (the agent never sees it).
|
|
153
201
|
if (recovered.refreshed)
|
|
154
202
|
api.logger.info("sil_whoami_refreshed", {});
|
|
155
|
-
return identityOutcomeToResult(api, recovered.outcome);
|
|
203
|
+
return identityOutcomeToResult(api, recovered.outcome, originBlock);
|
|
156
204
|
case "must_reregister":
|
|
157
205
|
// The refresh token is dead (invalid_grant) → clear the now-known-dead
|
|
158
206
|
// pair so the user's sil_register recovery is not blocked by stale
|
|
@@ -175,11 +223,13 @@ function registerWhoami(api) {
|
|
|
175
223
|
});
|
|
176
224
|
}
|
|
177
225
|
/** Map a non-401 identity outcome to the agent-facing result. (401 is handled
|
|
178
|
-
* inline by the refresh path; it never reaches here.)
|
|
179
|
-
|
|
226
|
+
* inline by the refresh path; it never reaches here.) The origin block rides the
|
|
227
|
+
* SUCCESS payload (the point is pre-failure diagnosis); the terminal/transient
|
|
228
|
+
* envelopes don't carry it. */
|
|
229
|
+
function identityOutcomeToResult(api, outcome, originBlock) {
|
|
180
230
|
switch (outcome.kind) {
|
|
181
231
|
case "ok":
|
|
182
|
-
return identityResult(outcome.identity);
|
|
232
|
+
return identityResult(outcome.identity, originBlock);
|
|
183
233
|
case "forbidden":
|
|
184
234
|
// Decision B — the dead-token clear is UNIFORM across all three sil-api tools.
|
|
185
235
|
// `sil_whoami` is the tool that is legible TODAY; an agent that diagnoses the
|
|
@@ -203,9 +253,11 @@ function identityOutcomeToResult(api, outcome) {
|
|
|
203
253
|
return mustReregister();
|
|
204
254
|
}
|
|
205
255
|
}
|
|
206
|
-
/** Success: the identity payload
|
|
207
|
-
|
|
208
|
-
|
|
256
|
+
/** Success: the identity payload + the web-origin visibility block (FIX B) —
|
|
257
|
+
* no token, no Bearer header. The origin block (strings only) lets the agent
|
|
258
|
+
* relay the resolved origin + its source so a wrong origin is diagnosable. */
|
|
259
|
+
function identityResult(identity, originBlock) {
|
|
260
|
+
return jsonResult({ status: "ok", identity, ...originBlock });
|
|
209
261
|
}
|
|
210
262
|
/** Not registered: a distinct, actionable outcome naming the recovery tool. No
|
|
211
263
|
* identity fields (name/addresses) so the agent can't mistake it for a read. */
|
|
@@ -217,6 +269,25 @@ function notRegistered() {
|
|
|
217
269
|
recovery: "sil_register",
|
|
218
270
|
});
|
|
219
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Registered-but-persistence-failed (FIX C): auth succeeded in THIS process but
|
|
274
|
+
* the token write failed, so nothing reached disk. DISTINCT from `not_registered`
|
|
275
|
+
* because the recovery differs — the user must FIX THE DATA DIR (the path + cause
|
|
276
|
+
* name what to fix), THEN re-register; a bare "run sil_register" would just fail
|
|
277
|
+
* to persist again, looping. `error` carries the "<path>: <cause>" from the
|
|
278
|
+
* in-process marker. No identity fields (the tokens never landed).
|
|
279
|
+
*/
|
|
280
|
+
function persistenceFailed(error) {
|
|
281
|
+
return jsonResult({
|
|
282
|
+
status: "persistence_failed",
|
|
283
|
+
message: "Registration authenticated but the credentials could NOT be written to"
|
|
284
|
+
+ " disk, so it did not stick. Fix the data directory (it must be writable"
|
|
285
|
+
+ " — check permissions / free space / that $SIL_DATA_DIR is a directory),"
|
|
286
|
+
+ " then run sil_register again.",
|
|
287
|
+
error,
|
|
288
|
+
recovery: "sil_register",
|
|
289
|
+
});
|
|
290
|
+
}
|
|
220
291
|
/** Terminal: the session is fully expired (refresh rejected). Re-register. */
|
|
221
292
|
function mustReregister() {
|
|
222
293
|
return jsonResult({
|
|
@@ -243,6 +314,29 @@ function transient() {
|
|
|
243
314
|
message: "sil is temporarily unavailable. Please try sil_whoami again.",
|
|
244
315
|
});
|
|
245
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* In-process persist-failure marker (FIX C). A failed token write leaves NO
|
|
319
|
+
* `tokens.json` on disk — exactly the state a never-registered user has — so the
|
|
320
|
+
* two are indistinguishable from disk alone. This module-level marker is the only
|
|
321
|
+
* signal that tells `sil_whoami` "auth succeeded in THIS process but persistence
|
|
322
|
+
* failed" apart from a bare `not_registered`. It is intentionally in-process only:
|
|
323
|
+
* the failure mode IS an unwritable data dir, so an on-disk sentinel would fail to
|
|
324
|
+
* write for the same reason — and after a cold restart `not_registered` is the
|
|
325
|
+
* TRUE state (no creds exist), with a re-run of `sil_register` re-surfacing the
|
|
326
|
+
* write failure loudly. Set by `claimStep` on the persist_failed terminal; reset
|
|
327
|
+
* on a fresh `sil_register` start so a stale marker can't mislabel a later genuine
|
|
328
|
+
* not_registered (and resettable in tests via that same fresh-start path).
|
|
329
|
+
*/
|
|
330
|
+
let _persistFailure = null;
|
|
331
|
+
function setPersistFailure(error) {
|
|
332
|
+
_persistFailure = error;
|
|
333
|
+
}
|
|
334
|
+
function getPersistFailure() {
|
|
335
|
+
return _persistFailure;
|
|
336
|
+
}
|
|
337
|
+
function clearPersistFailure() {
|
|
338
|
+
_persistFailure = null;
|
|
339
|
+
}
|
|
246
340
|
/**
|
|
247
341
|
* One poll step: claim, then map the outcome to the loop's done/continue signal.
|
|
248
342
|
* `pending`/`retryable`/`not_found` keep the loop alive (`done:false`). The 404
|
|
@@ -263,11 +357,26 @@ async function claimStep(apiUrl, sessionId, verifier) {
|
|
|
263
357
|
case "not_found":
|
|
264
358
|
return { done: false };
|
|
265
359
|
case "success":
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
360
|
+
// Persist the bearer pair + identity. FIX C: wrap ONLY the persist calls
|
|
361
|
+
// (never the whole step — a too-wide catch could mislabel a genuine claim
|
|
362
|
+
// success). A write failure (unwritable / missing-and-uncreatable / full
|
|
363
|
+
// $SIL_DATA_DIR) is TERMINAL, not transient: re-polling the claim cannot
|
|
364
|
+
// make the data dir writable, and the claim is single-use server-side. So
|
|
365
|
+
// return a descriptive `persist_failed` terminal (path + cause) and set the
|
|
366
|
+
// in-process marker — instead of letting the throw reach the poller's catch,
|
|
367
|
+
// which would swallow it as a retry and end the run as a misleading timeout.
|
|
368
|
+
try {
|
|
369
|
+
await writeTokens({
|
|
370
|
+
access_token: outcome.access_token,
|
|
371
|
+
refresh_token: outcome.refresh_token,
|
|
372
|
+
});
|
|
373
|
+
await writeConfig({ user: outcome.user });
|
|
374
|
+
}
|
|
375
|
+
catch (err) {
|
|
376
|
+
const error = `${getTokensPath()}: ${describeCause(err)}`;
|
|
377
|
+
setPersistFailure(error);
|
|
378
|
+
return { done: true, outcome: "persist_failed", error };
|
|
379
|
+
}
|
|
271
380
|
return { done: true, outcome: "success", user_id: outcome.user.id };
|
|
272
381
|
case "expired":
|
|
273
382
|
case "already_claimed":
|
|
@@ -289,6 +398,18 @@ function handleDone(api, sessionId, result) {
|
|
|
289
398
|
});
|
|
290
399
|
return;
|
|
291
400
|
}
|
|
401
|
+
// FIX C: a token-persist failure is logged LOUDLY at error — the most severe
|
|
402
|
+
// terminal, distinct from the routine info/warn terminals — carrying the path +
|
|
403
|
+
// cause (in `step.error`) so an operator sees persistence failed, NOT that the
|
|
404
|
+
// user abandoned the flow. The tokens never reached disk, so there is no token
|
|
405
|
+
// material to leak; only the session id + the path/cause error are logged.
|
|
406
|
+
if (step.outcome === "persist_failed") {
|
|
407
|
+
api.logger.error("sil_register_persist_failed", {
|
|
408
|
+
session_id: sessionId,
|
|
409
|
+
error: typeof step.error === "string" ? step.error : "",
|
|
410
|
+
});
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
292
413
|
if ("timedOut" in step && step.timedOut === true) {
|
|
293
414
|
api.logger.info("sil_register_timeout", { session_id: sessionId });
|
|
294
415
|
return;
|
|
@@ -310,3 +431,60 @@ function handleDone(api, sessionId, result) {
|
|
|
310
431
|
function stripTrailingSlash(url) {
|
|
311
432
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
312
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* Render an errno-style cause from a caught (unknown) persist error, for the
|
|
436
|
+
* loud log + whoami `persistence_failed` state (FIX C). A Node fs error carries
|
|
437
|
+
* a `.code` (EACCES/ENOSPC/ENOTDIR/ENOENT…) and a `.message` that already names
|
|
438
|
+
* the code and the human cause ("not a directory") — surface the code first
|
|
439
|
+
* (prominent for an operator) then the full message. Carries NO token material:
|
|
440
|
+
* an fs error names paths/errnos only, and the tokens never reached this point.
|
|
441
|
+
*/
|
|
442
|
+
function describeCause(err) {
|
|
443
|
+
if (err instanceof Error) {
|
|
444
|
+
const code = err.code;
|
|
445
|
+
return code ? `${code}: ${err.message}` : err.message;
|
|
446
|
+
}
|
|
447
|
+
return String(err);
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Present an auth URL as a single atomic link target for a human-rendered chat
|
|
451
|
+
* surface: angle-bracket wrapped (`<…>`). The angle brackets are the RFC-3986 /
|
|
452
|
+
* Markdown convention that bounds a URL so a greedy auto-linker captures the
|
|
453
|
+
* WHOLE span — including the `&code_challenge=…` query param — instead of
|
|
454
|
+
* terminating the link at the first `&` (the reported production break that
|
|
455
|
+
* dropped `code_challenge` and 400-ed `invalid_code_challenge`). The caller puts
|
|
456
|
+
* the returned token on its OWN line so no surrounding prose can be folded into
|
|
457
|
+
* the link. Pure (no I/O) — the [unit] seam for the atomic-link contract. The
|
|
458
|
+
* structured `auth_url` field is the UNWRAPPED canonical URL; this is the
|
|
459
|
+
* human-presentation form only, and it carries the same params byte-for-byte (it
|
|
460
|
+
* never re-encodes, never adds the verifier).
|
|
461
|
+
*/
|
|
462
|
+
function presentAuthLink(authUrl) {
|
|
463
|
+
return `<${authUrl}>`;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* System-browser steer copy (the proactive webview → default-browser handoff).
|
|
467
|
+
*
|
|
468
|
+
* Auth0's hosted login sets its session cookie on its OWN domain; an app's
|
|
469
|
+
* embedded/in-app webview routinely partitions or blocks that cookie, so opening
|
|
470
|
+
* the auth URL there dead-ends the login. The plugin CANNOT detect the surface —
|
|
471
|
+
* the host `api` exposes no client/UA/surface signal (see openclaw.d.ts) and a
|
|
472
|
+
* tool's execute receives no request context — so the steer ships UNCONDITIONALLY
|
|
473
|
+
* at presentation time, BEFORE the Auth0 leg (not as a post-failure recovery; that
|
|
474
|
+
* reactive path is sil-services #50). Phrased as a neutral setup step, not a
|
|
475
|
+
* warning — onboarding first-impression is the metric.
|
|
476
|
+
*
|
|
477
|
+
* One shared NEGATIVE clause feeds both the human `message` and the agent
|
|
478
|
+
* `instructions` so the two copies cannot drift — an agent paraphrasing must
|
|
479
|
+
* carry the same "not the in-app browser" half, never collapse it back to a
|
|
480
|
+
* generic "a browser". Plain "default browser (Safari/Chrome)" is used over the
|
|
481
|
+
* term "system browser": it names the concrete action a non-technical user can
|
|
482
|
+
* follow on their own device.
|
|
483
|
+
*/
|
|
484
|
+
const BROWSER_STEER_NEGATIVE = "your device's default browser (Safari, Chrome, …), not this app's"
|
|
485
|
+
+ " built-in / in-app browser";
|
|
486
|
+
/** Human-facing lead line — the line ABOVE the atomic link in `message`. */
|
|
487
|
+
const BROWSER_STEER_HUMAN = `Open this link in ${BROWSER_STEER_NEGATIVE}:`;
|
|
488
|
+
/** Agent-facing steer — embedded mid-sentence in `instructions` (lower-cased lead
|
|
489
|
+
* so it reads naturally after "tell them to …"). */
|
|
490
|
+
const BROWSER_STEER_AGENT = `open the link in ${BROWSER_STEER_NEGATIVE}.`;
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sil shopping-expert profile tools.
|
|
3
|
+
*
|
|
4
|
+
* `sil_profile_materialize` is the plugin's half of the agent-creation engine:
|
|
5
|
+
* it writes the created expert's *behaviour* artefacts (persona + optional
|
|
6
|
+
* domain sub-skill playbook + a typed manifest) into the plugin's own data
|
|
7
|
+
* directory (`$SIL_DATA_DIR`, the disclosed `filesystemScope`). The *wiring*
|
|
8
|
+
* half — the host `agents.list[]` entry, the enabled `sil` plugin, the attached
|
|
9
|
+
* `sil` skill — is the host agent driving its own `openclaw …` CLI under the
|
|
10
|
+
* bundled `skill/SKILL.md` procedure; the plugin never writes `~/.openclaw`
|
|
11
|
+
* (`security.noChildProcess: true`, host config is outside `filesystemScope`).
|
|
12
|
+
*
|
|
13
|
+
* Why a tool (not skill-driven `write`-tool prose): the host agent's only way
|
|
14
|
+
* to invoke plugin code is a registered tool, and a plugin write buys
|
|
15
|
+
* host-validated typed inputs, the structured-error envelope, and ATOMIC
|
|
16
|
+
* all-or-nothing writes — all of which serve the goal's primary correctness
|
|
17
|
+
* bar (a created expert that actually shops). The artefact write lives here;
|
|
18
|
+
* the host-config write stays host-CLI.
|
|
19
|
+
*
|
|
20
|
+
* This follows `identity.ts` (the reference group): a `registerXTools(api)`
|
|
21
|
+
* function, a `Type.Object` schema the host validates inputs against, the
|
|
22
|
+
* `jsonResult` success/structured-error envelope, and ALL I/O inside
|
|
23
|
+
* `execute()` (register() opens nothing).
|
|
24
|
+
*/
|
|
25
|
+
import { Type } from "typebox";
|
|
26
|
+
import { listAgentProfiles, materializeProfile, readAgentProfile, removeAgentArtefacts, } from "../lib/profile-store.js";
|
|
27
|
+
import { jsonResult } from "../lib/tool-result.js";
|
|
28
|
+
export function registerProfileTools(api) {
|
|
29
|
+
registerMaterialize(api);
|
|
30
|
+
registerList(api);
|
|
31
|
+
registerGet(api);
|
|
32
|
+
registerRemove(api);
|
|
33
|
+
}
|
|
34
|
+
function registerMaterialize(api) {
|
|
35
|
+
api.registerTool({
|
|
36
|
+
name: "sil_profile_materialize",
|
|
37
|
+
label: "Materialize a sil shopping-expert's behaviour artefacts",
|
|
38
|
+
description: "Write a created sil shopping expert's behaviour artefacts into the sil"
|
|
39
|
+
+ " data directory: the persona/instructions, an optional generated domain"
|
|
40
|
+
+ " sub-skill (playbook), and a typed manifest the sil skill reads at"
|
|
41
|
+
+ " runtime to load them. Call this AFTER the host agent has been created"
|
|
42
|
+
+ " (openclaw agents add) and BEFORE openclaw config validate. It does NOT"
|
|
43
|
+
+ " touch the host OpenClaw config — the plugin enable + skill attach are"
|
|
44
|
+
+ " driven by the host CLI, not this tool. Writes are atomic: an invalid"
|
|
45
|
+
+ " spec writes nothing, and a write failure leaves nothing partial.",
|
|
46
|
+
parameters: Type.Object({
|
|
47
|
+
agentId: Type.String({
|
|
48
|
+
description: "The host agent id the expert was created under (agents.list[].id),"
|
|
49
|
+
+ " lower-kebab; not \"main\" (host-reserved). Keys the artefact dir.",
|
|
50
|
+
}),
|
|
51
|
+
name: Type.String({
|
|
52
|
+
description: "The human-readable expert name (recorded in the manifest).",
|
|
53
|
+
}),
|
|
54
|
+
persona: Type.String({
|
|
55
|
+
description: "The shopping persona/instructions — the expert's expertise, tone, and"
|
|
56
|
+
+ " standing rules. Non-empty. Materialized as persona.md and copied"
|
|
57
|
+
+ " into the agent workspace SOUL.md by the skill.",
|
|
58
|
+
}),
|
|
59
|
+
playbook: Type.Optional(Type.String({
|
|
60
|
+
description: "The generated domain sub-skill: how this expert shops on sil (which"
|
|
61
|
+
+ " sil_* tool for which intent, refinement rules). Materialized as"
|
|
62
|
+
+ " playbook.md and loaded by the sil skill at session start. Omit"
|
|
63
|
+
+ " when the expert needs no domain playbook.",
|
|
64
|
+
})),
|
|
65
|
+
}),
|
|
66
|
+
async execute(_callId, params) {
|
|
67
|
+
// The host validates `params` against the schema above before we run, but
|
|
68
|
+
// narrow at the read site (the SDK types params as Record<string,unknown>)
|
|
69
|
+
// and let the store do the real, structured-error validation.
|
|
70
|
+
const spec = {
|
|
71
|
+
agentId: typeof params["agentId"] === "string" ? params["agentId"] : "",
|
|
72
|
+
name: typeof params["name"] === "string" ? params["name"] : "",
|
|
73
|
+
persona: typeof params["persona"] === "string" ? params["persona"] : "",
|
|
74
|
+
...(typeof params["playbook"] === "string"
|
|
75
|
+
? { playbook: params["playbook"] }
|
|
76
|
+
: {}),
|
|
77
|
+
};
|
|
78
|
+
const result = materializeProfile(spec);
|
|
79
|
+
if (result.ok) {
|
|
80
|
+
api.logger.info("sil_profile_materialized", {
|
|
81
|
+
agent_id: result.agentId,
|
|
82
|
+
has_playbook: result.playbookPath !== undefined,
|
|
83
|
+
});
|
|
84
|
+
return jsonResult({
|
|
85
|
+
status: "ok",
|
|
86
|
+
agentId: result.agentId,
|
|
87
|
+
dir: result.dir,
|
|
88
|
+
personaPath: result.personaPath,
|
|
89
|
+
...(result.playbookPath ? { playbookPath: result.playbookPath } : {}),
|
|
90
|
+
profilePath: result.profilePath,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (result.kind === "invalid_request") {
|
|
94
|
+
api.logger.warn("sil_profile_invalid_request", { field: result.field });
|
|
95
|
+
return jsonResult({
|
|
96
|
+
status: "invalid_request",
|
|
97
|
+
field: result.field,
|
|
98
|
+
message: result.message,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// persistence_failed — the path + cause are in `error` (never a token/PII).
|
|
102
|
+
api.logger.error("sil_profile_persistence_failed", { error: result.error });
|
|
103
|
+
return jsonResult({
|
|
104
|
+
status: "persistence_failed",
|
|
105
|
+
error: result.error,
|
|
106
|
+
message: result.message,
|
|
107
|
+
recovery: "fix_data_dir",
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* `sil_profile_list` — enumerate the user's sil shopping experts (read-only).
|
|
114
|
+
*
|
|
115
|
+
* The artefact store is the source of truth for "what is a sil expert" (a
|
|
116
|
+
* readable `agents/<id>/profile.json`), not the host agent list. Returns each
|
|
117
|
+
* expert summarized from its manifest, most-recently-created first, plus an
|
|
118
|
+
* `unreadable[]` bucket so one corrupt manifest never blinds the user to the
|
|
119
|
+
* rest. An empty store is a normal `ok` outcome (like an empty `sil_search`).
|
|
120
|
+
*/
|
|
121
|
+
function registerList(api) {
|
|
122
|
+
api.registerTool({
|
|
123
|
+
name: "sil_profile_list",
|
|
124
|
+
label: "List the user's sil shopping experts",
|
|
125
|
+
description: "List the sil shopping experts the user has created — read-only, no"
|
|
126
|
+
+ " arguments. Sourced from the sil data directory's artefact store (each"
|
|
127
|
+
+ " agents/<id>/profile.json is the authoritative \"is a sil expert\""
|
|
128
|
+
+ " signal — a bare host agent without one is not listed). Returns the"
|
|
129
|
+
+ " experts most-recently-created first, each with its agentId, name,"
|
|
130
|
+
+ " whether it carries a domain playbook, and createdAt. An empty store is"
|
|
131
|
+
+ " a normal, successful empty listing — not an error. One unreadable or"
|
|
132
|
+
+ " corrupt manifest is reported inline in `unreadable` and never aborts"
|
|
133
|
+
+ " the listing. Reads no token and writes nothing.",
|
|
134
|
+
parameters: Type.Object({}),
|
|
135
|
+
async execute(_callId, _params) {
|
|
136
|
+
const { experts, unreadable } = listAgentProfiles();
|
|
137
|
+
api.logger.info("sil_profile_listed", {
|
|
138
|
+
expert_count: experts.length,
|
|
139
|
+
unreadable_count: unreadable.length,
|
|
140
|
+
});
|
|
141
|
+
return jsonResult({
|
|
142
|
+
status: "ok",
|
|
143
|
+
experts,
|
|
144
|
+
unreadable,
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* `sil_profile_get` — view one expert's full detail (read-only).
|
|
151
|
+
*
|
|
152
|
+
* Re-runs the writer's `agentId` gate before any read (a traversal-shaped id →
|
|
153
|
+
* `invalid_request`). Returns the manifest plus the persona/playbook bodies so
|
|
154
|
+
* the skill can render a complete view. An unknown or unloadable expert →
|
|
155
|
+
* `not_found` (the skill lists the healthy experts) — never a stack trace or a
|
|
156
|
+
* raw path. Reads no token and writes nothing.
|
|
157
|
+
*/
|
|
158
|
+
function registerGet(api) {
|
|
159
|
+
api.registerTool({
|
|
160
|
+
name: "sil_profile_get",
|
|
161
|
+
label: "View one sil shopping expert's detail",
|
|
162
|
+
description: "Show one sil shopping expert's full detail — read-only. Pass its"
|
|
163
|
+
+ " `agentId`. Returns the expert's name, its persona/instructions, its"
|
|
164
|
+
+ " domain playbook when one exists, the manifest path, and createdAt,"
|
|
165
|
+
+ " read from the artefact store so the agent can summarize the expert."
|
|
166
|
+
+ " An unknown expert returns `not_found` (list the experts to see which"
|
|
167
|
+
+ " exist) — never a stack trace or a raw path. A malformed/traversal id"
|
|
168
|
+
+ " returns `invalid_request`. Reads no token and writes nothing.",
|
|
169
|
+
parameters: Type.Object({
|
|
170
|
+
agentId: Type.String({
|
|
171
|
+
description: "The expert's host agent id (lower-kebab, e.g. \"gift-buyer\"; not"
|
|
172
|
+
+ " \"main\"). Keys the artefact directory the detail is read from.",
|
|
173
|
+
}),
|
|
174
|
+
}),
|
|
175
|
+
async execute(_callId, params) {
|
|
176
|
+
const agentId = typeof params["agentId"] === "string" ? params["agentId"] : "";
|
|
177
|
+
const result = readAgentProfile(agentId);
|
|
178
|
+
if (result.ok) {
|
|
179
|
+
api.logger.info("sil_profile_viewed", {
|
|
180
|
+
agent_id: result.agentId,
|
|
181
|
+
has_playbook: result.playbook !== undefined,
|
|
182
|
+
});
|
|
183
|
+
return jsonResult({
|
|
184
|
+
status: "ok",
|
|
185
|
+
agentId: result.agentId,
|
|
186
|
+
name: result.name,
|
|
187
|
+
persona: result.persona,
|
|
188
|
+
...(result.playbook !== undefined ? { playbook: result.playbook } : {}),
|
|
189
|
+
profilePath: result.profilePath,
|
|
190
|
+
createdAt: result.createdAt,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (result.kind === "invalid_request") {
|
|
194
|
+
api.logger.warn("sil_profile_get_invalid_request", { field: result.field });
|
|
195
|
+
return jsonResult({
|
|
196
|
+
status: "invalid_request",
|
|
197
|
+
field: result.field,
|
|
198
|
+
message: result.message,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
// not_found — a normal outcome; steer the agent to list-then-retry.
|
|
202
|
+
api.logger.info("sil_profile_get_not_found", { agent_id: result.agentId });
|
|
203
|
+
return jsonResult({
|
|
204
|
+
status: "not_found",
|
|
205
|
+
agentId: result.agentId,
|
|
206
|
+
message: result.message,
|
|
207
|
+
recovery: "sil_profile_list",
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* `sil_profile_remove` — remove one expert's behaviour artefacts (the sil-side
|
|
214
|
+
* half of a clean removal).
|
|
215
|
+
*
|
|
216
|
+
* This is the ARTEFACT half ONLY. The host-wiring half (the `agents.list[]`
|
|
217
|
+
* entry) is the skill's `openclaw agents remove <agentId>` CLI step, which the
|
|
218
|
+
* skill runs FIRST — the plugin cannot write `~/.openclaw` (`noChildProcess`).
|
|
219
|
+
*
|
|
220
|
+
* Fail-closed: re-runs the `agentId` gate itself, deletes only the single
|
|
221
|
+
* validated leaf directory under `agents/`, and deletes NOTHING on a bad id.
|
|
222
|
+
* Absent target → `not_found` (idempotent — safe to re-run after a partial host
|
|
223
|
+
* failure). A genuine `rmSync` failure → `persistence_failed`. Reads no token.
|
|
224
|
+
*/
|
|
225
|
+
function registerRemove(api) {
|
|
226
|
+
api.registerTool({
|
|
227
|
+
name: "sil_profile_remove",
|
|
228
|
+
label: "Remove a sil shopping expert's behaviour artefacts",
|
|
229
|
+
description: "Remove one sil shopping expert's behaviour artefacts from the sil data"
|
|
230
|
+
+ " directory (its agents/<id>/ directory). This is the SIL-SIDE half of"
|
|
231
|
+
+ " removal only — the host wiring (the agents.list[] entry) is removed"
|
|
232
|
+
+ " separately by the host CLI, which the skill runs FIRST (this plugin"
|
|
233
|
+
+ " cannot write the host config). Pass the `agentId`. Scoped to exactly"
|
|
234
|
+
+ " that one expert: a malformed/traversal/\"main\" id returns"
|
|
235
|
+
+ " `invalid_request` and deletes nothing; an unknown id returns"
|
|
236
|
+
+ " `not_found` (idempotent — safe to re-run after a partial failure); a"
|
|
237
|
+
+ " genuine filesystem failure returns `persistence_failed`. Confirm with"
|
|
238
|
+
+ " the user before removing — it is destructive and irreversible.",
|
|
239
|
+
parameters: Type.Object({
|
|
240
|
+
agentId: Type.String({
|
|
241
|
+
description: "The expert's host agent id (lower-kebab, e.g. \"gift-buyer\"; not"
|
|
242
|
+
+ " \"main\"). Keys the artefact directory to remove. Exactly one"
|
|
243
|
+
+ " expert is affected.",
|
|
244
|
+
}),
|
|
245
|
+
}),
|
|
246
|
+
async execute(_callId, params) {
|
|
247
|
+
const agentId = typeof params["agentId"] === "string" ? params["agentId"] : "";
|
|
248
|
+
const result = removeAgentArtefacts(agentId);
|
|
249
|
+
if (result.ok) {
|
|
250
|
+
api.logger.info("sil_profile_removed", { agent_id: result.agentId });
|
|
251
|
+
return jsonResult({
|
|
252
|
+
status: "removed",
|
|
253
|
+
agentId: result.agentId,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (result.kind === "invalid_request") {
|
|
257
|
+
api.logger.warn("sil_profile_remove_invalid_request", { field: result.field });
|
|
258
|
+
return jsonResult({
|
|
259
|
+
status: "invalid_request",
|
|
260
|
+
field: result.field,
|
|
261
|
+
message: result.message,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
if (result.kind === "not_found") {
|
|
265
|
+
api.logger.info("sil_profile_remove_not_found", { agent_id: result.agentId });
|
|
266
|
+
return jsonResult({
|
|
267
|
+
status: "not_found",
|
|
268
|
+
agentId: result.agentId,
|
|
269
|
+
message: result.message,
|
|
270
|
+
recovery: "sil_profile_list",
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
// persistence_failed — the path + cause are in `error` (never a token/PII).
|
|
274
|
+
api.logger.error("sil_profile_remove_persistence_failed", { error: result.error });
|
|
275
|
+
return jsonResult({
|
|
276
|
+
status: "persistence_failed",
|
|
277
|
+
error: result.error,
|
|
278
|
+
message: result.message,
|
|
279
|
+
recovery: result.recovery,
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
}
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "sil",
|
|
3
3
|
"name": "sil",
|
|
4
4
|
"description": "sil commerce plugin for OpenClaw — register on sil, read your identity, and search and look up products in the sil catalog.",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.3.0",
|
|
6
6
|
"skills": ["./skill"],
|
|
7
7
|
"activation": {
|
|
8
8
|
"onCapabilities": ["tool"]
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
"contracts": {
|
|
11
11
|
"tools": [
|
|
12
12
|
"sil_product_get",
|
|
13
|
+
"sil_profile_get",
|
|
14
|
+
"sil_profile_list",
|
|
15
|
+
"sil_profile_materialize",
|
|
16
|
+
"sil_profile_remove",
|
|
13
17
|
"sil_register",
|
|
14
18
|
"sil_search",
|
|
15
19
|
"sil_whoami"
|
|
@@ -47,7 +51,7 @@
|
|
|
47
51
|
},
|
|
48
52
|
"security": {
|
|
49
53
|
"shipsRuntimeCode": true,
|
|
50
|
-
"packagingNote": "Compiled JavaScript ships under ./dist. register() stays synchronous and opens nothing — it only registers tools. ALL I/O happens inside a tool's execute(): sil_register calls sil-web over the network, writes tokens.json + config.json to the plugin data directory (owner-only, 0600), and arms a bounded background poll timer that stops on the first terminal claim outcome or after the session deadline. sil_whoami reads the stored access token and calls sil-api for the user's identity, refreshing transparently via sil-web on a 401 (at most one refresh + one retry per call, no timer); a confirmed-dead session clears tokens.json. sil_search and sil_product_get read the stored access token and call sil-api's catalog endpoints (search / lookup) with it — read-only, no token write, no timer, a single round-trip (a 401 is a terminal re-register hint, no refresh). The PKCE verifier is held only in memory and is never written to disk. Tokens and identity PII are never logged.",
|
|
54
|
+
"packagingNote": "Compiled JavaScript ships under ./dist. register() stays synchronous and opens nothing — it only registers tools. ALL I/O happens inside a tool's execute(): sil_register calls sil-web over the network, writes tokens.json + config.json to the plugin data directory (owner-only, 0600), and arms a bounded background poll timer that stops on the first terminal claim outcome or after the session deadline. sil_whoami reads the stored access token and calls sil-api for the user's identity, refreshing transparently via sil-web on a 401 (at most one refresh + one retry per call, no timer); a confirmed-dead session clears tokens.json. sil_search and sil_product_get read the stored access token and call sil-api's catalog endpoints (search / lookup) with it — read-only, no token write, no timer, a single round-trip (a 401 is a terminal re-register hint, no refresh). sil_profile_materialize makes no network call and reads no token: it writes a created shopping expert's behaviour artefacts (persona.md, optional playbook.md, profile.json) atomically into $SIL_DATA_DIR/agents/<agentId>/ (owner-only, 0600) — the agent's host-config wiring is driven separately by the host CLI, never by this plugin. sil_profile_list / sil_profile_get / sil_profile_remove are the local expert lifecycle over the same artefact store, also making no network call and reading no token: list enumerates $SIL_DATA_DIR/agents/*/profile.json read-only, get reads one expert's manifest + persona/playbook bodies read-only, and remove deletes exactly one validated agents/<agentId>/ leaf directory (fail-closed on a malformed/traversal id — deletes nothing) — the host-wiring half of removal is the host CLI's, not this plugin's. The PKCE verifier is held only in memory and is never written to disk. Tokens and identity PII are never logged.",
|
|
51
55
|
"registersLongLivedService": false,
|
|
52
56
|
"serviceIds": [],
|
|
53
57
|
"runsTimers": true,
|
|
@@ -57,7 +61,7 @@
|
|
|
57
61
|
"https://sil.4gpts.com"
|
|
58
62
|
],
|
|
59
63
|
"filesystemScope": [
|
|
60
|
-
"$SIL_DATA_DIR (default $XDG_DATA_HOME/sil, else ~/.local/share/sil) — tokens.json, config.json"
|
|
64
|
+
"$SIL_DATA_DIR (default $XDG_DATA_HOME/sil, else ~/.local/share/sil) — tokens.json, config.json, agents/<agentId>/{persona.md,playbook.md,profile.json} (shopping-expert behaviour artefacts written by sil_profile_materialize)"
|
|
61
65
|
],
|
|
62
66
|
"credentialsOnDisk": [
|
|
63
67
|
"tokens.json (access + refresh token)",
|
package/package.json
CHANGED