sil-openclaw 0.4.5 → 0.5.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +186 -0
  2. package/README.md +33 -45
  3. package/dist/gateway/search-results.js +11 -7
  4. package/dist/index.js +24 -24
  5. package/dist/lib/allowlist-script.js +13 -0
  6. package/dist/lib/artifacts.js +30 -0
  7. package/dist/lib/credentials.js +2 -3
  8. package/dist/lib/host-wiring.js +44 -15
  9. package/dist/lib/pkce.js +3 -3
  10. package/dist/lib/search-results-log.js +23 -0
  11. package/dist/lib/search-results-store.js +13 -10
  12. package/dist/lib/shopping-call.js +143 -0
  13. package/dist/lib/sil-client.js +185 -1046
  14. package/dist/lib/tool-result.js +10 -3
  15. package/dist/tools/catalog.js +311 -1197
  16. package/dist/tools/doctor.js +25 -63
  17. package/dist/tools/identity.js +110 -245
  18. package/openclaw.plugin.json +16 -12
  19. package/package.json +7 -6
  20. package/schema/PROVENANCE.md +15 -0
  21. package/schema/shopping-brief-create-request.schema.json +98 -0
  22. package/schema/shopping-brief-create-response.schema.json +24 -0
  23. package/schema/shopping-brief-edit-request.schema.json +125 -0
  24. package/schema/shopping-brief-edit-response.schema.json +24 -0
  25. package/schema/shopping-brief-read-request.schema.json +15 -0
  26. package/schema/shopping-brief-read-response.schema.json +235 -0
  27. package/schema/shopping-domain-create-request.schema.json +160 -0
  28. package/schema/shopping-domain-create-response.schema.json +60 -0
  29. package/schema/shopping-domain-get-request.schema.json +18 -0
  30. package/schema/shopping-domain-get-response.schema.json +307 -0
  31. package/schema/shopping-domain-search-request.schema.json +18 -0
  32. package/schema/shopping-domain-search-response.schema.json +92 -0
  33. package/schema/shopping-offers-request.schema.json +31 -0
  34. package/schema/shopping-offers-response.schema.json +172 -0
  35. package/schema/shopping-product-get-request.schema.json +24 -0
  36. package/schema/shopping-product-get-response.schema.json +121 -0
  37. package/schema/shopping-profile-edit-request.schema.json +97 -0
  38. package/schema/shopping-profile-edit-response.schema.json +17 -0
  39. package/schema/shopping-search-request.schema.json +106 -0
  40. package/schema/shopping-search-response.schema.json +182 -0
  41. package/schema/shopping-seller-get-request.schema.json +24 -0
  42. package/schema/shopping-seller-get-response.schema.json +342 -0
  43. package/scripts/allowlist-openclaw.mjs +4 -5
  44. package/sil-shopping/SKILL.md +196 -97
  45. package/sil-shopping/references/mint.md +190 -0
  46. package/dist/lib/bind-channel.js +0 -10
  47. package/dist/lib/creation-entrypoint.js +0 -111
  48. package/dist/lib/derive-agent-id.js +0 -36
  49. package/dist/lib/profile-store.js +0 -568
  50. package/dist/tools/profile.js +0 -300
  51. package/scripts/create-shopper.mjs +0 -677
  52. package/sil-shopping/examples/multi_domain_shopper_walkthrough.md +0 -65
  53. package/sil-shopping/references/agent_creation_engine.md +0 -223
  54. package/sil-shopping/references/fill_and_feedback.md +0 -102
  55. package/sil-shopping/references/method_and_prds.md +0 -143
  56. package/sil-shopping/references/setup_onboarding.md +0 -64
  57. package/sil-shopping/references/shop_loop.md +0 -118
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Host-wiring drift — is sil wired the way it thinks it is?
3
3
  *
4
- * A skill attaches per-agent at `agents.list[i].skills` by its PUBLISHED NAME
4
+ * A skill attaches per-agent in the roster's `skills` array by its PUBLISHED NAME
5
5
  * (`sil-shopping` = the skill-dir basename); tools admit by PLUGIN ID (`sil`).
6
6
  * Two different host keys, and conflating them seeded incident #1 — silently,
7
7
  * because the host fails a bad skill ref with a warning, not an error.
@@ -26,7 +26,7 @@
26
26
  import { readFileSync } from "node:fs";
27
27
  import { basename, dirname, join } from "node:path";
28
28
  import { fileURLToPath } from "node:url";
29
- import { resolveAllowlistScript } from "./creation-entrypoint.js";
29
+ import { resolveAllowlistScript } from "./allowlist-script.js";
30
30
  /** The shipped manifest, resolved relative to this module — two levels up from
31
31
  * both `src/lib/` and `dist/lib/`. It ships via `package.json#files`. */
32
32
  const MANIFEST_PATH = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "openclaw.plugin.json");
@@ -115,30 +115,48 @@ export function detectWiringDrift(config, facts) {
115
115
  * plugin id but NOT the published name.
116
116
  *
117
117
  * Both halves are load-bearing. "Lacks the published name" alone is not drift —
118
- * a host runs many agents and only one is the shopper, so that would fire on
118
+ * a host runs many agents and only some reach for sil at all, so that would fire on
119
119
  * every unrelated agent. And an agent carrying BOTH tokens is not drift either:
120
120
  * the published name attaches, the skill runs, nothing is degraded.
121
121
  */
122
122
  function findMisattachedAgents(config, facts) {
123
+ const labels = [];
124
+ for (const { label, skills: declared } of rosterAgents(config)) {
125
+ const skills = stringsOf(declared);
126
+ if (skills === null)
127
+ continue;
128
+ if (!skills.includes(facts.id) || skills.includes(facts.skill))
129
+ continue;
130
+ labels.push(label);
131
+ }
132
+ return labels;
133
+ }
134
+ /**
135
+ * Every roster agent as `{ label, skills }`, from BOTH host shapes: the `agents.entries`
136
+ * map keyed by id (2026.8.1+) and the `agents.list` array (<=2026.7.1). `label` is what
137
+ * the fix string points at, so an entry with no usable id is reported by its path.
138
+ */
139
+ function rosterAgents(config) {
123
140
  const agents = isRecord(config["agents"]) ? config["agents"] : undefined;
141
+ const found = [];
142
+ const entries = isRecord(agents?.["entries"]) ? agents["entries"] : undefined;
143
+ for (const [id, entry] of Object.entries(entries ?? {})) {
144
+ if (!isRecord(entry))
145
+ continue;
146
+ found.push({ label: id.length > 0 ? id : `agents.entries[""]`, skills: entry["skills"] });
147
+ }
124
148
  const list = Array.isArray(agents?.["list"]) ? agents["list"] : [];
125
- const labels = [];
126
149
  for (let i = 0; i < list.length; i += 1) {
127
150
  const entry = list[i];
128
151
  if (!isRecord(entry))
129
152
  continue;
130
- const skills = stringsOf(entry["skills"]);
131
- if (skills === null)
132
- continue;
133
- if (!skills.includes(facts.id) || skills.includes(facts.skill))
134
- continue;
135
- // The fix string points at this agent, so it must be legible. An entry with
136
- // no usable id is operator corruption — the drift is still real, so report
137
- // it positionally rather than printing `undefined` at the operator.
138
153
  const id = entry["id"];
139
- labels.push(typeof id === "string" && id.length > 0 ? id : `agents.list[${i}]`);
154
+ found.push({
155
+ label: typeof id === "string" && id.length > 0 ? id : `agents.list[${i}]`,
156
+ skills: entry["skills"],
157
+ });
140
158
  }
141
- return labels;
159
+ return found;
142
160
  }
143
161
  /**
144
162
  * Why sil's tools are filtered, if they are. Two independent causes, folded into
@@ -176,7 +194,7 @@ function findUnadmittedReasons(config, facts) {
176
194
  * stays byte-identical to today. Absence of a problem is not a finding, and an
177
195
  * always-present key is one consumers start depending on.
178
196
  *
179
- * Additive, never a wrapper: a `sil_search` result carrying an advisory is still
197
+ * Additive, never a wrapper: a search result carrying an advisory is still
180
198
  * the same search result, with the same products in the same order.
181
199
  *
182
200
  * It recurs on every result while the drift persists — that is the feature, not
@@ -192,6 +210,17 @@ export function wiringAdvisories(api) {
192
210
  const drift = detectWiringDrift(api.config, readSilWiringFacts());
193
211
  return drift.length === 0 ? {} : { advisories: drift };
194
212
  }
213
+ /**
214
+ * The same advisory as its OWN result block, or nothing at all.
215
+ *
216
+ * A shopping tool's payload IS the API's 200 body, passed through verbatim, so the
217
+ * advisory cannot ride as a key beside the contract's — it would either collide with
218
+ * one or teach a consumer to expect a field sil-services never sends.
219
+ */
220
+ export function wiringAdvisoryBlocks(api) {
221
+ const { advisories } = wiringAdvisories(api);
222
+ return advisories === undefined ? [] : [{ advisories }];
223
+ }
195
224
  function buildSkillMisattachedFinding(agentLabels, facts) {
196
225
  const agents = agentLabels.join(", ");
197
226
  const plural = agentLabels.length > 1;
package/dist/lib/pkce.js CHANGED
@@ -32,7 +32,7 @@ const VERIFIER_BYTES = 32;
32
32
  * Pure; no I/O. The result is a 43-char base64url string.
33
33
  *
34
34
  * Identical to sil-web's `deriveChallenge` — pinned by a shared test vector so
35
- * any drift fails in CI rather than silently as a runtime 404.
35
+ * any drift fails in the suite rather than silently as a runtime 404.
36
36
  */
37
37
  export function deriveChallenge(verifier) {
38
38
  return createHash("sha256").update(verifier).digest("base64url");
@@ -47,7 +47,7 @@ export function isValidCodeChallenge(value) {
47
47
  }
48
48
  /**
49
49
  * True iff `value` is a well-formed session id (UUID). This is the format gate
50
- * sil-web's `/authorize` and `/claim` apply to the incoming `session` param.
50
+ * sil-web's `/authorize/<session>` and its claim route apply to that segment.
51
51
  */
52
52
  export function isValidSessionId(value) {
53
53
  return UUID_RE.test(value);
@@ -60,7 +60,7 @@ export function newSessionId() {
60
60
  * Mint a fresh PKCE code verifier — 32 cryptographically-random bytes as a
61
61
  * base64url string. NEVER written to disk: it is the bearer secret for the
62
62
  * claim CAS; only its digest (the challenge) ever leaves the process, and only
63
- * inside the auth URL.
63
+ * inside the link the buyer opens.
64
64
  */
65
65
  export function newVerifier() {
66
66
  return randomBytes(VERIFIER_BYTES).toString("base64url");
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The `sil_search_results_*` operator markers, with their fields repeated INLINE in the
3
+ * message. The host hands the structured object to the log FILE only — the console line
4
+ * a container's `docker logs` shows is the message alone (`createSubsystemLogger`'s
5
+ * `emitLog`, vendor/openclaw). Fields-only, a delivery miss reads `[plugins]
6
+ * sil_search_results_miss` with no callId to join on and no cause.
7
+ */
8
+ // `severity`, never `level` — `docsNeedleExclusions()` drops any retired needle whose
9
+ // string occurs in live `src/`, and that word plus a colon is one: renaming REDs AC16.
10
+ /** Long enough for a host `callId` (28 chars) and every cause below, short enough that
11
+ * no single call can run the line away. */
12
+ const MAX_FIELD_CHARS = 128;
13
+ /** The `callId` is the CLIENT's string, checked only for being a non-empty one: raw, a
14
+ * newline in it forges a second marker on its own console line, whitespace splits one
15
+ * pair into several, and length is unbounded. The MESSAGE takes this; `fields` keeps the
16
+ * value as it arrived. */
17
+ const render = (value) => String(value)
18
+ .replace(/[^\x21-\x7E]/g, "_")
19
+ .slice(0, MAX_FIELD_CHARS);
20
+ export function logSearchResults(api, severity, event, fields) {
21
+ const pairs = Object.entries(fields).map(([key, value]) => `${key}=${render(value)}`);
22
+ api.logger[severity](`sil_search_results_${event} ${pairs.join(" ")}`, fields);
23
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The search-results delivery buffer.
3
3
  *
4
- * `sil_search` returns its full page to the agent exactly as it always has —
4
+ * `shopping_search` returns its full page to the agent exactly as it always has —
5
5
  * this store is a pure SIDE EFFECT on the `ok` path, invisible to every
6
6
  * channel. It exists because the host's projection of a tool result is not a
7
7
  * dependable transport for structured data: under codex `data.result` is absent
@@ -12,16 +12,19 @@
12
12
  * this map and answers over the paired `deviceToken` WS.
13
13
  *
14
14
  * The key is the HOST's `callId`, verbatim — never prefixed, hashed, or
15
- * re-minted. It is the one identifier that is reliably streamed (the client
16
- * already reads it off the tool identity frames as `data.itemId`), and
17
- * `execute()` receives it BEFORE any I/O, so a page can never be orphaned by a
18
- * failing search. Because that id is visible to anyone who can see the frames,
19
- * knowledge of a `callId` is NOT evidence of entitlement: the principal check
20
- * below is the only gate that matters.
15
+ * re-minted. `execute()` receives it BEFORE any I/O, so a page can never be
16
+ * orphaned by a failing search. A client joins on
17
+ * `data.toolCallId ?? data.itemId`, in that order: the id is the same string on
18
+ * every frame, but the FIELD NAME differs per family (`session.tool` carries
19
+ * only `toolCallId`, the `agent`/`stream:"item"` frames only `itemId`) and on
20
+ * the non-codex path `itemId` is `tool:`-prefixed — see
21
+ * `docs/decisions/search-results-pull-surface.md`. Because that id is visible to
22
+ * anyone who can see the frames, knowledge of a `callId` is NOT evidence of
23
+ * entitlement: the principal check below is the only gate that matters.
21
24
  *
22
25
  * In-memory, by choice. Process death is the strongest retention ceiling
23
26
  * available and costs nothing; an on-disk buffer would put prices, seller
24
- * identity, and `checkout_url` at rest, widen the plugin's declared filesystem
27
+ * identity, and buy URLs at rest, widen the plugin's declared filesystem
25
28
  * scope, and — with no timers allowed — leave the last pages there forever once
26
29
  * the user stops searching.
27
30
  *
@@ -32,8 +35,8 @@
32
35
  * screen on the first refresh.
33
36
  */
34
37
  /**
35
- * Fifteen minutes. A search result is point-in-time — price, availability, and
36
- * `checkout_url` are exactly the fields a shopper must re-fetch before buying —
38
+ * Fifteen minutes. A search result is point-in-time — the price range and the page it
39
+ * was read off are exactly what a shopper must re-read before buying —
37
40
  * so this is long enough for the settle edge, a client reload, a reconnect, and
38
41
  * a short step-away, and short enough that nothing renders as stale truth. It
39
42
  * is a delivery buffer, not scrollback and not history.
@@ -0,0 +1,143 @@
1
+ /**
2
+ * ONE authenticated call to sil-api, and the §4 envelopes every caller answers with.
3
+ * Shared because the 401 choreography must not drift between the tools that make it — a
4
+ * second copy is what `cross-tool-401-parity` forbids. The caller owns only the `ok` body.
5
+ */
6
+ import { getApiUrl } from "./config.js";
7
+ import { clearTokens, readTokens } from "./credentials.js";
8
+ import { callShopping, refreshAndRetryOnce, } from "./sil-client.js";
9
+ import { jsonResult } from "./tool-result.js";
10
+ /** The guide read, as one route constant: two spellings of one path is a route nobody
11
+ * owns. */
12
+ export const DOMAIN_GET_ROUTE = { method: "GET", path: "/catalog/domains/:path" };
13
+ function refused(status, result) {
14
+ return { kind: "refused", status, result };
15
+ }
16
+ /**
17
+ * Call one route with the stored credentials, refreshing and retrying at most once.
18
+ * Every non-`ok` outcome comes back as its finished envelope, so no caller re-derives
19
+ * the taxonomy.
20
+ */
21
+ export async function callRoute(api, call, args) {
22
+ const stored = readTokens();
23
+ if (stored === null)
24
+ return refused("not_registered", notRegistered(call.name));
25
+ const first = await callShopping(getApiUrl(), stored.access_token, call, args);
26
+ const recovered = await refreshAndRetryOnce(first, (o) => o.kind === "unauthorized", (accessToken) => callShopping(getApiUrl(), accessToken, call, args));
27
+ switch (recovered.kind) {
28
+ case "result":
29
+ if (recovered.refreshed)
30
+ api.logger.info(`${call.name}_refreshed`, {});
31
+ return mapOutcome(api, call, recovered.outcome);
32
+ case "must_reregister":
33
+ if (recovered.reason === "invalid_grant")
34
+ clearTokens();
35
+ api.logger.info(`${call.name}_must_reregister`, { cause: recovered.reason });
36
+ return refused("must_reregister", mustReregister(call.name));
37
+ case "second_unauthorized":
38
+ clearTokens();
39
+ api.logger.info(`${call.name}_must_reregister`, { cause: "retry_unauthorized" });
40
+ return refused("must_reregister", mustReregister(call.name));
41
+ case "retryable":
42
+ api.logger.info(`${call.name}_refresh_retryable`, {});
43
+ return refused("retryable", transient(call.name));
44
+ }
45
+ }
46
+ function mapOutcome(api, call, outcome) {
47
+ switch (outcome.kind) {
48
+ case "ok":
49
+ return { kind: "ok", body: outcome.body };
50
+ case "invalid_request":
51
+ api.logger.info(`${call.name}_invalid_request`, {});
52
+ return refused("invalid_request", refusal("invalid_request", outcome.message));
53
+ case "not_found":
54
+ case "already_exists":
55
+ api.logger.info(`${call.name}_${outcome.kind}`, {});
56
+ return refused(outcome.kind, refusal(outcome.kind, outcome.message, call.recovery?.[outcome.kind]));
57
+ case "forbidden":
58
+ return refused("forbidden", forbiddenResult(api, call.name, outcome.reason));
59
+ case "retryable":
60
+ api.logger.info(`${call.name}_retryable`, outcome.source ? { source: outcome.source } : {});
61
+ return refused("retryable", transient(call.name, outcome.source, outcome.detail));
62
+ case "unauthorized":
63
+ // Structurally unreachable past the 401 choreography, kept exhaustive so a
64
+ // refactor cannot silently drop a variant.
65
+ return refused("must_reregister", mustReregister(call.name));
66
+ }
67
+ }
68
+ /** Not registered: a distinct, actionable outcome naming the recovery tool, with
69
+ * no results field the agent could mistake for an empty answer. */
70
+ function notRegistered(tool) {
71
+ return jsonResult({
72
+ status: "not_registered",
73
+ message: `Not registered on sil. Run sil_register to authenticate, then call ${tool} again.`,
74
+ recovery: "sil_register",
75
+ });
76
+ }
77
+ /**
78
+ * A refusal the route made before it spent, surfaced VERBATIM: the message names the
79
+ * offender in sil's own words, so it IS the agent's recourse and is never rewritten or
80
+ * matched on here. Terminal but NOT fatal and NOT retryable — where a recovery exists it
81
+ * is the next tool to call, never the same call again. An `invalid_request` never carries
82
+ * one: a next call that fits one of its causes is a hint that misleads on the rest.
83
+ */
84
+ function refusal(status, message, recovery) {
85
+ return jsonResult({
86
+ status,
87
+ message,
88
+ ...(recovery !== undefined ? { recovery } : {}),
89
+ });
90
+ }
91
+ /** Terminal: the session is dead — reached only after the shared refresh-and-retry
92
+ * choreography has exhausted its one refresh + one retry. */
93
+ function mustReregister(tool) {
94
+ return jsonResult({
95
+ status: "must_reregister",
96
+ message: `Your sil session has expired. Run sil_register to sign in again, then call ${tool} again.`,
97
+ recovery: "sil_register",
98
+ });
99
+ }
100
+ /**
101
+ * A 403 — the token is valid but the user is not provisioned (or a principal
102
+ * mismatch). Refreshing cannot help; this is not a 401.
103
+ *
104
+ * The token CLEAR is gated on exactly `user_not_provisioned`: that token maps to no
105
+ * account on this backend and is structurally dead, so clearing it lets the next
106
+ * `sil_register` re-onboard instead of short-circuiting to already-registered. A
107
+ * `principal_mismatch` can be transient and MUST NOT clear — the exact-equality gate is
108
+ * the correctness boundary here, and a truthy or prefix check would wipe a good session.
109
+ */
110
+ function forbiddenResult(api, tool, reason) {
111
+ api.logger.warn(`${tool}_forbidden`, { reason });
112
+ if (reason === "user_not_provisioned")
113
+ clearTokens();
114
+ const message = reason === "user_not_provisioned"
115
+ ? "Your sil account is not fully set up. Complete onboarding (run"
116
+ + " sil_register) and try again."
117
+ : "sil rejected this request (" + reason + "). Run sil_register to"
118
+ + " re-establish your session, then try again.";
119
+ return jsonResult({ status: "forbidden", reason, message, recovery: "sil_register" });
120
+ }
121
+ /**
122
+ * Transient: retry, NOT a re-register (a false terminal on a transient sends the
123
+ * agent down a recovery that cannot fix it). The two causally distinct failures
124
+ * share `status: "retryable"` and split on ATTRIBUTION — `source` absent means
125
+ * sil or the network is down and the copy names nothing it cannot identify;
126
+ * `source` present means one named source is degraded and sil itself is fine, so
127
+ * the copy must never say "sil is unavailable". `detail` (the upstream cause) is
128
+ * relayed as its own field rather than folded into our sentence.
129
+ */
130
+ export function transient(tool, source, detail) {
131
+ if (source === undefined) {
132
+ return jsonResult({
133
+ status: "retryable",
134
+ message: `sil is temporarily unavailable. Please try ${tool} again.`,
135
+ });
136
+ }
137
+ return jsonResult({
138
+ status: "retryable",
139
+ message: `The catalog source "${source}" is temporarily unavailable.`
140
+ + ` sil itself is fine — retry ${tool} shortly.`,
141
+ ...(detail !== undefined ? { detail } : {}),
142
+ });
143
+ }