@kyde/score 0.9.9 → 0.11.28
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/README.md +4 -3
- package/bin/kyde.js +175 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -14,9 +14,10 @@ One step, safe to rerun, written so an agent can run it alone:
|
|
|
14
14
|
(`~/.claude/settings.json`, global `env` block — never the agent
|
|
15
15
|
name; names belong where each agent is launched).
|
|
16
16
|
3. Installs the hook: after a tool call Kyde can warn the agent in its
|
|
17
|
-
own context
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
own context. Before a call it hashes the recipient fields (address,
|
|
18
|
+
IBAN, merchant, amount bucket) locally with a salt that stays on the
|
|
19
|
+
machine and sends only the hashes. It never pauses or blocks a call
|
|
20
|
+
(pause and block: waitlist at https://kyde.com/pricing/).
|
|
20
21
|
4. Sends a test event and confirms that Kyde sees this machine.
|
|
21
22
|
|
|
22
23
|
Equivalent to `curl -fsSL https://score.kyde.com/install.sh | sh` — this
|
package/bin/kyde.js
CHANGED
|
@@ -9,16 +9,18 @@
|
|
|
9
9
|
// Environment (all optional, passed straight through to the installer):
|
|
10
10
|
// KYDE_KEY use this scoring key instead of creating one
|
|
11
11
|
// KYDE_ENDPOINT service base URL (default https://score.kyde.com)
|
|
12
|
-
// KYDE_BLOCK hook mode:
|
|
12
|
+
// KYDE_BLOCK hook mode: off (default, warn only); ask|deny internal tests only
|
|
13
13
|
// KYDE_REMOVE_GLOBAL_NAME=1 drop a global OTEL_SERVICE_NAME from settings
|
|
14
14
|
"use strict";
|
|
15
15
|
|
|
16
16
|
const { spawnSync } = require("node:child_process");
|
|
17
|
+
const crypto = require("node:crypto");
|
|
17
18
|
const fs = require("node:fs");
|
|
18
19
|
const os = require("node:os");
|
|
19
20
|
const path = require("node:path");
|
|
20
21
|
|
|
21
22
|
const BASE = process.env.KYDE_ENDPOINT || "https://score.kyde.com";
|
|
23
|
+
const SHINE = process.env.KYDE_SHINE_ENDPOINT || "https://shine.kyde.com";
|
|
22
24
|
const VERSION = require("../package.json").version;
|
|
23
25
|
|
|
24
26
|
// Carried over from 0.1.0 (published 2026-11-04): the copy-paste line
|
|
@@ -32,13 +34,20 @@ function usage(code) {
|
|
|
32
34
|
|
|
33
35
|
Usage:
|
|
34
36
|
npx @kyde/score init set up this machine: scoring key, OpenTelemetry
|
|
35
|
-
export to ${BASE}, and the
|
|
37
|
+
export to ${BASE}, and the warning
|
|
36
38
|
hook for Claude Code. Safe to rerun.
|
|
37
39
|
npx @kyde/score prompt print the one-line setup prompt to paste into
|
|
38
40
|
a coding agent, which then runs init itself:
|
|
39
41
|
${SETUP_PROMPT}
|
|
42
|
+
npx @kyde/score verify <shine-id>
|
|
43
|
+
challenge the agent behind a Shine ID via
|
|
44
|
+
${SHINE}, wait for its
|
|
45
|
+
confirmation and print the Ed25519-signed
|
|
46
|
+
statement, verified locally against the JWKS.
|
|
47
|
+
Options: --challenger <name> --session <s>
|
|
48
|
+
--timeout <seconds, default 300>
|
|
40
49
|
|
|
41
|
-
Options via environment: KYDE_KEY, KYDE_ENDPOINT,
|
|
50
|
+
Options via environment: KYDE_KEY, KYDE_ENDPOINT, KYDE_SHINE_ENDPOINT,
|
|
42
51
|
KYDE_REMOVE_GLOBAL_NAME=1 — see https://score.kyde.com/llms.txt
|
|
43
52
|
`);
|
|
44
53
|
process.exit(code);
|
|
@@ -96,9 +105,172 @@ async function init() {
|
|
|
96
105
|
}
|
|
97
106
|
}
|
|
98
107
|
|
|
108
|
+
// --- verify: the challenger side of the Shine challenge (KYDE-439) ---------
|
|
109
|
+
|
|
110
|
+
function b64urlDecode(text) {
|
|
111
|
+
return Buffer.from(text, "base64url");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function shineJson(method, path, body, headers) {
|
|
115
|
+
const res = await fetch(`${SHINE}${path}`, {
|
|
116
|
+
method,
|
|
117
|
+
headers: { "content-type": "application/json", ...(headers || {}) },
|
|
118
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
119
|
+
signal: AbortSignal.timeout(15000),
|
|
120
|
+
});
|
|
121
|
+
let payload = {};
|
|
122
|
+
try {
|
|
123
|
+
payload = await res.json();
|
|
124
|
+
} catch {
|
|
125
|
+
/* non-JSON error body */
|
|
126
|
+
}
|
|
127
|
+
return { status: res.status, payload };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Verify the compact JWS against the JWKS, compare the nonce hash and
|
|
131
|
+
// the expiry — the same checks the MCP verify_agent tool runs, so both
|
|
132
|
+
// entry points accept exactly the same statements.
|
|
133
|
+
function verifyStatement(statement, jwks, nonce) {
|
|
134
|
+
const [head, payload, sig] = statement.split(".");
|
|
135
|
+
const header = JSON.parse(b64urlDecode(head).toString());
|
|
136
|
+
if (header.alg !== "EdDSA") {
|
|
137
|
+
throw new Error(`unexpected statement alg: ${header.alg}`);
|
|
138
|
+
}
|
|
139
|
+
const jwk = (jwks.keys || []).find(
|
|
140
|
+
(k) => k.kid === header.kid && k.kty === "OKP" && k.crv === "Ed25519",
|
|
141
|
+
);
|
|
142
|
+
if (!jwk) throw new Error("statement kid not found in shine JWKS");
|
|
143
|
+
const key = crypto.createPublicKey({
|
|
144
|
+
key: { kty: "OKP", crv: "Ed25519", x: jwk.x },
|
|
145
|
+
format: "jwk",
|
|
146
|
+
});
|
|
147
|
+
const ok = crypto.verify(
|
|
148
|
+
null,
|
|
149
|
+
Buffer.from(`${head}.${payload}`),
|
|
150
|
+
key,
|
|
151
|
+
b64urlDecode(sig),
|
|
152
|
+
);
|
|
153
|
+
if (!ok) throw new Error("statement signature does not verify");
|
|
154
|
+
const claims = JSON.parse(b64urlDecode(payload).toString());
|
|
155
|
+
const nonceHash = crypto.createHash("sha256").update(nonce).digest("hex");
|
|
156
|
+
if (claims.nonce_sha256 !== nonceHash) {
|
|
157
|
+
throw new Error("nonce mismatch: the statement answers a different challenge");
|
|
158
|
+
}
|
|
159
|
+
if (!(claims.exp > Date.now() / 1000)) {
|
|
160
|
+
throw new Error("statement expired — verify again");
|
|
161
|
+
}
|
|
162
|
+
return claims;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function verify(args) {
|
|
166
|
+
const flags = {};
|
|
167
|
+
const positional = [];
|
|
168
|
+
for (let i = 0; i < args.length; i++) {
|
|
169
|
+
if (args[i].startsWith("--")) {
|
|
170
|
+
flags[args[i]] = args[i + 1];
|
|
171
|
+
i++;
|
|
172
|
+
} else {
|
|
173
|
+
positional.push(args[i]);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const shineId = positional[0];
|
|
177
|
+
if (!shineId) {
|
|
178
|
+
process.stderr.write("usage: npx @kyde/score verify <shine-id> " +
|
|
179
|
+
"[--challenger <name>] [--session <s>] [--timeout <seconds>]\n");
|
|
180
|
+
process.exit(2);
|
|
181
|
+
}
|
|
182
|
+
const challenger = flags["--challenger"] || `npx-verify@${os.hostname()}`;
|
|
183
|
+
const session = flags["--session"] || "";
|
|
184
|
+
const timeoutS = Number(flags["--timeout"] || "300");
|
|
185
|
+
const nonce = crypto.randomBytes(18).toString("base64url");
|
|
186
|
+
|
|
187
|
+
const created = await shineJson("POST", "/shine/v0/challenges", {
|
|
188
|
+
shine_id: shineId,
|
|
189
|
+
nonce,
|
|
190
|
+
challenger,
|
|
191
|
+
session,
|
|
192
|
+
});
|
|
193
|
+
if (created.status !== 202) {
|
|
194
|
+
throw new Error(`shine rejected the challenge (${created.status}): ` +
|
|
195
|
+
`${created.payload.detail || JSON.stringify(created.payload)}`);
|
|
196
|
+
}
|
|
197
|
+
const { challenge_id: challengeId, result_token: resultToken } =
|
|
198
|
+
created.payload;
|
|
199
|
+
process.stderr.write(
|
|
200
|
+
`challenge ${challengeId} sent to ${shineId} as "${challenger}" — ` +
|
|
201
|
+
"waiting for the agent to confirm (it may poll only every 30 s)\n",
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const deadline = Date.now() + timeoutS * 1000;
|
|
205
|
+
for (;;) {
|
|
206
|
+
const res = await shineJson(
|
|
207
|
+
"GET",
|
|
208
|
+
`/shine/v0/challenges/${challengeId}/result`,
|
|
209
|
+
undefined,
|
|
210
|
+
{ "x-shine-result-token": resultToken },
|
|
211
|
+
);
|
|
212
|
+
if (res.status !== 200) {
|
|
213
|
+
throw new Error(`shine result lookup failed (${res.status})`);
|
|
214
|
+
}
|
|
215
|
+
if (res.payload.status === "confirmed") {
|
|
216
|
+
const jwks = (await shineJson("GET", "/.well-known/jwks.json")).payload;
|
|
217
|
+
const claims = verifyStatement(res.payload.statement, jwks, nonce);
|
|
218
|
+
const summary =
|
|
219
|
+
claims.band === "learning"
|
|
220
|
+
? "identity confirmed; behavior not yet scored (learning, <30 " +
|
|
221
|
+
"runs) — delegating to a learning agent is your policy call"
|
|
222
|
+
: claims.measured
|
|
223
|
+
? `identity confirmed; band ${claims.band}, score ${claims.score}` +
|
|
224
|
+
` over ${claims.runs} runs` +
|
|
225
|
+
(claims.v >= 1
|
|
226
|
+
? claims.contract
|
|
227
|
+
? `; confirmed contract (held: ${
|
|
228
|
+
claims.compliance && claims.compliance.state === "measured"
|
|
229
|
+
? claims.compliance.days + " days"
|
|
230
|
+
: "too young for a statement"
|
|
231
|
+
}, holds: ${claims.holds_band})`
|
|
232
|
+
: "; no confirmed contract"
|
|
233
|
+
: "")
|
|
234
|
+
: "identity confirmed; no behavioral measurement available " +
|
|
235
|
+
"(measured: false)";
|
|
236
|
+
process.stderr.write(
|
|
237
|
+
`confirmed and verified against ${SHINE}/.well-known/jwks.json\n` +
|
|
238
|
+
`${summary}\n`,
|
|
239
|
+
);
|
|
240
|
+
process.stdout.write(
|
|
241
|
+
JSON.stringify(
|
|
242
|
+
{ status: "confirmed", verified: true, claims,
|
|
243
|
+
statement: res.payload.statement,
|
|
244
|
+
jwks_url: `${SHINE}/.well-known/jwks.json` },
|
|
245
|
+
null,
|
|
246
|
+
2,
|
|
247
|
+
) + "\n",
|
|
248
|
+
);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (res.payload.status === "expired" || Date.now() >= deadline) {
|
|
252
|
+
process.stderr.write(
|
|
253
|
+
"not confirmed: the agent did not answer before the challenge " +
|
|
254
|
+
"expired — identity not proven (there is no attest fallback " +
|
|
255
|
+
"by design)\n",
|
|
256
|
+
);
|
|
257
|
+
process.stdout.write(JSON.stringify(
|
|
258
|
+
{ status: res.payload.status === "expired" ? "expired" : "timeout",
|
|
259
|
+
verified: false }) + "\n");
|
|
260
|
+
process.exit(3);
|
|
261
|
+
}
|
|
262
|
+
await new Promise((r) => setTimeout(r, 3000));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
99
266
|
const arg = process.argv[2];
|
|
100
267
|
if (arg === "init") {
|
|
101
268
|
init();
|
|
269
|
+
} else if (arg === "verify") {
|
|
270
|
+
verify(process.argv.slice(3)).catch((err) => {
|
|
271
|
+
process.stderr.write(`kyde verify: ${err.message}\n`);
|
|
272
|
+
process.exit(1);
|
|
273
|
+
});
|
|
102
274
|
} else if (arg === "prompt") {
|
|
103
275
|
process.stdout.write(SETUP_PROMPT + "\n");
|
|
104
276
|
} else if (!arg || arg === "--help" || arg === "-h" || arg === "help") {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyde/score",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "KYDE Score setup: `npx @kyde/score init` wires an agent harness (Claude Code first) to score.kyde.com — OpenTelemetry export plus the
|
|
3
|
+
"version": "0.11.28",
|
|
4
|
+
"description": "KYDE Score setup: `npx @kyde/score init` wires an agent harness (Claude Code first) to score.kyde.com — OpenTelemetry export plus the warning hook, in one step.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
7
7
|
"observability",
|