saktum 0.9.0 → 0.10.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/README.md +15 -1
- package/package.json +1 -1
- package/saktum.mjs +410 -101
package/README.md
CHANGED
|
@@ -11,6 +11,20 @@ npx saktum check https://your-server.example/mcp # a remote server (sign-in
|
|
|
11
11
|
|
|
12
12
|
Runs on your machine. Nothing is uploaded. Your own environment variables are never passed to the server.
|
|
13
13
|
|
|
14
|
+
## Enterprise pilot-ready (v0.10)
|
|
15
|
+
|
|
16
|
+
- **Remote MCP servers:** `saktum proxy --mandate m.json --enforce -- saktum bridge https://host/mcp` governs a remote
|
|
17
|
+
server exactly like a local one (headers forwarded, never logged).
|
|
18
|
+
- **Protected keys:** any key option accepts `env:VAR` or `keychain:NAME` (macOS Keychain, Linux Secret Service, Windows DPAPI).
|
|
19
|
+
- **Approvals by link:** `--approval-webhook` posts requests to Slack, Teams or an email relay; `saktum approvals serve`
|
|
20
|
+
lets the owner approve exactly one action in a browser with their key.
|
|
21
|
+
- **Central receipts:** `saktum receipts view logs/*.jsonl` verifies and combines many agents' logs into one view.
|
|
22
|
+
- **Bindings override:** `--bindings bindings.json` tells Saktum what third-party tools' arguments mean.
|
|
23
|
+
- **Agent inventory:** `saktum agents scan` lists agents, owners, operators, autonomy, risk and maturity; `assess` includes it.
|
|
24
|
+
- **Security pack and pilot kit:** [SECURITY.md](SECURITY.md), [threat model](docs/THREAT-MODEL.md),
|
|
25
|
+
[data flow](docs/DATA-FLOW.md), [vendor questionnaire](docs/VENDOR-QUESTIONNAIRE.md), [pilot runbook](docs/PILOT.md),
|
|
26
|
+
device-management scripts in `scripts/pilot/`, agreement and NDA templates in `templates/`.
|
|
27
|
+
|
|
14
28
|
## Evidence for governance (v0.9)
|
|
15
29
|
|
|
16
30
|
Saktum is the agent-controls layer of AI governance: identity, least privilege, tool permissions, human oversight and
|
|
@@ -220,7 +234,7 @@ servers not on your allowlist, and the weakest grades. Configured secrets are ne
|
|
|
220
234
|
|
|
221
235
|
```yaml
|
|
222
236
|
- uses: actions/checkout@v4
|
|
223
|
-
- uses: soodhere/saktum-check@v0.
|
|
237
|
+
- uses: soodhere/saktum-check@v0.10.0
|
|
224
238
|
with:
|
|
225
239
|
target: "-- node build/index.js" # or an https URL
|
|
226
240
|
args: "--active --tests saktum.tests.yaml" # optional; --active only for your own server
|
package/package.json
CHANGED
package/saktum.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Saktum Check 0.
|
|
2
|
+
// Saktum Check 0.10.0 (private beta). Licensed Apache-2.0; bundled dependencies keep their own licences.
|
|
3
3
|
import { createRequire as __saktumCreateRequire } from "node:module";
|
|
4
4
|
const require = __saktumCreateRequire(import.meta.url);
|
|
5
5
|
var __create = Object.create;
|
|
@@ -10417,6 +10417,7 @@ var require_dist = __commonJS({
|
|
|
10417
10417
|
});
|
|
10418
10418
|
|
|
10419
10419
|
// packages/sign/dist/index.js
|
|
10420
|
+
import { execFileSync } from "node:child_process";
|
|
10420
10421
|
import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, sign, verify } from "node:crypto";
|
|
10421
10422
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
10422
10423
|
import { dirname, join } from "node:path";
|
|
@@ -10483,7 +10484,55 @@ function generateSigningKey() {
|
|
|
10483
10484
|
const { privateKey, publicKey } = generateKeyPairSync("ed25519");
|
|
10484
10485
|
return { privateKey, publicKey, kid: didKeyFromPublicKey(publicKey) };
|
|
10485
10486
|
}
|
|
10487
|
+
function keyFromJwk(jwkText) {
|
|
10488
|
+
const privateKey = createPrivateKey({ key: JSON.parse(jwkText), format: "jwk" });
|
|
10489
|
+
const publicKey = createPublicKey(privateKey);
|
|
10490
|
+
return { privateKey, publicKey, kid: didKeyFromPublicKey(publicKey) };
|
|
10491
|
+
}
|
|
10492
|
+
function keychain(name) {
|
|
10493
|
+
if (!/^[A-Za-z0-9._-]{1,64}$/.test(name))
|
|
10494
|
+
throw new Error("Keychain names may use letters, digits, dot, dash and underscore.");
|
|
10495
|
+
const run = (cmd, args, input, env) => execFileSync(cmd, args, { encoding: "utf8", input, env: { ...process.env, ...env ?? {} }, stdio: ["pipe", "pipe", "ignore"] }).trim();
|
|
10496
|
+
const fresh = () => {
|
|
10497
|
+
const k = generateSigningKey();
|
|
10498
|
+
return { k, jwk: JSON.stringify(k.privateKey.export({ format: "jwk" })) };
|
|
10499
|
+
};
|
|
10500
|
+
if (process.platform === "darwin") {
|
|
10501
|
+
try {
|
|
10502
|
+
return keyFromJwk(run("security", ["find-generic-password", "-s", "saktum", "-a", name, "-w"]));
|
|
10503
|
+
} catch {
|
|
10504
|
+
const { k, jwk } = fresh();
|
|
10505
|
+
run("security", ["add-generic-password", "-s", "saktum", "-a", name, "-w", jwk, "-U"]);
|
|
10506
|
+
return k;
|
|
10507
|
+
}
|
|
10508
|
+
}
|
|
10509
|
+
if (process.platform === "win32") {
|
|
10510
|
+
const file = join(homedir(), ".saktum", "keys", `${name}.dpapi`);
|
|
10511
|
+
const ps = (script, env) => run("powershell", ["-NoProfile", "-NonInteractive", "-Command", "Add-Type -AssemblyName System.Security; " + script], void 0, env);
|
|
10512
|
+
if (existsSync(file))
|
|
10513
|
+
return keyFromJwk(ps("[Text.Encoding]::UTF8.GetString([Security.Cryptography.ProtectedData]::Unprotect([Convert]::FromBase64String((Get-Content -Raw $env:SAKTUM_F)), $null, 'CurrentUser'))", { SAKTUM_F: file }));
|
|
10514
|
+
const { k, jwk } = fresh();
|
|
10515
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
10516
|
+
writeFileSync(file, ps("[Convert]::ToBase64String([Security.Cryptography.ProtectedData]::Protect([Text.Encoding]::UTF8.GetBytes($env:SAKTUM_J), $null, 'CurrentUser'))", { SAKTUM_J: jwk }), { mode: 384 });
|
|
10517
|
+
return k;
|
|
10518
|
+
}
|
|
10519
|
+
try {
|
|
10520
|
+
return keyFromJwk(run("secret-tool", ["lookup", "service", "saktum", "account", name]));
|
|
10521
|
+
} catch {
|
|
10522
|
+
const { k, jwk } = fresh();
|
|
10523
|
+
run("secret-tool", ["store", "--label", `Saktum key ${name}`, "service", "saktum", "account", name], jwk);
|
|
10524
|
+
return k;
|
|
10525
|
+
}
|
|
10526
|
+
}
|
|
10486
10527
|
function loadOrCreateKey(path = defaultKeyPath()) {
|
|
10528
|
+
if (path.startsWith("env:")) {
|
|
10529
|
+
const v = process.env[path.slice(4)];
|
|
10530
|
+
if (!v)
|
|
10531
|
+
throw new Error(`Environment variable ${path.slice(4)} is not set.`);
|
|
10532
|
+
return keyFromJwk(v);
|
|
10533
|
+
}
|
|
10534
|
+
if (path.startsWith("keychain:"))
|
|
10535
|
+
return keychain(path.slice(9));
|
|
10487
10536
|
if (existsSync(path)) {
|
|
10488
10537
|
const jwk = JSON.parse(readFileSync(path, "utf8"));
|
|
10489
10538
|
const privateKey = createPrivateKey({ key: jwk, format: "jwk" });
|
|
@@ -33997,7 +34046,7 @@ var init_dist3 = __esm({
|
|
|
33997
34046
|
init_stdio2();
|
|
33998
34047
|
init_streamableHttp();
|
|
33999
34048
|
init_types2();
|
|
34000
|
-
USER_AGENT = "saktum-check/0.
|
|
34049
|
+
USER_AGENT = "saktum-check/0.10.0 (+https://saktum.dev/check)";
|
|
34001
34050
|
LIMITS = { requestTimeoutMs: 1e4, connectTimeoutMs: 6e4, maxResponseChars: 5e6 };
|
|
34002
34051
|
LimitError = class extends Error {
|
|
34003
34052
|
};
|
|
@@ -34035,7 +34084,7 @@ var init_dist3 = __esm({
|
|
|
34035
34084
|
jsonrpc: "2.0",
|
|
34036
34085
|
id: 1,
|
|
34037
34086
|
method: "initialize",
|
|
34038
|
-
params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "saktum-trust-check-probe", version: "0.
|
|
34087
|
+
params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "saktum-trust-check-probe", version: "0.10.0" } }
|
|
34039
34088
|
});
|
|
34040
34089
|
}
|
|
34041
34090
|
});
|
|
@@ -35407,7 +35456,7 @@ var init_engine = __esm({
|
|
|
35407
35456
|
init_runner();
|
|
35408
35457
|
init_safe();
|
|
35409
35458
|
init_scoring();
|
|
35410
|
-
ENGINE_VERSION = "0.
|
|
35459
|
+
ENGINE_VERSION = "0.10.0";
|
|
35411
35460
|
UNKNOWN_TOOL = "saktum_trust_check_no_such_tool";
|
|
35412
35461
|
INVALID_TOKEN = "saktum-check-deliberately-invalid-token";
|
|
35413
35462
|
baseOf = (pack, check) => ({
|
|
@@ -36393,6 +36442,17 @@ function trustStatement(entries, verified) {
|
|
|
36393
36442
|
function approvalRequestId(m, tool, args) {
|
|
36394
36443
|
return "apr_" + argumentsHash({ mandate: mandateDigest(m), tool, args: argumentsHash(args) }).replace(/^sha256:/, "").slice(0, 16);
|
|
36395
36444
|
}
|
|
36445
|
+
function recordPending(path, req) {
|
|
36446
|
+
const a = readApprovals(path);
|
|
36447
|
+
a.pending = (a.pending ?? []).filter((p) => p.id !== req.id);
|
|
36448
|
+
a.pending.push({ ...req, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
36449
|
+
_mkdir(_dirname(path), { recursive: true });
|
|
36450
|
+
_write(path, JSON.stringify(a, null, 2) + "\n");
|
|
36451
|
+
}
|
|
36452
|
+
function listPending(path = DEFAULT_APPROVALS()) {
|
|
36453
|
+
const a = readApprovals(path);
|
|
36454
|
+
return (a.pending ?? []).filter((p) => !a.used.includes(p.id) && !a.approvals.some((x) => x.approval === p.id));
|
|
36455
|
+
}
|
|
36396
36456
|
function approveAction(m, requestId, ownerKey, minutes = 60, path = DEFAULT_APPROVALS()) {
|
|
36397
36457
|
if (ownerKey.kid !== m.owner.id)
|
|
36398
36458
|
throw new Error("Only the mandate's owner can approve its actions.");
|
|
@@ -36913,6 +36973,72 @@ var init_crosswalk = __esm({
|
|
|
36913
36973
|
}
|
|
36914
36974
|
});
|
|
36915
36975
|
|
|
36976
|
+
// packages/testkit-core/dist/agents.js
|
|
36977
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync6, statSync as statSync2 } from "node:fs";
|
|
36978
|
+
import { join as join4 } from "node:path";
|
|
36979
|
+
function scanAgents(dirs, o = {}) {
|
|
36980
|
+
const found = [];
|
|
36981
|
+
const walk = (dir, depth) => {
|
|
36982
|
+
let names = [];
|
|
36983
|
+
try {
|
|
36984
|
+
names = readdirSync3(dir);
|
|
36985
|
+
} catch {
|
|
36986
|
+
return;
|
|
36987
|
+
}
|
|
36988
|
+
for (const n of names) {
|
|
36989
|
+
if (n === "node_modules" || n.startsWith(".git"))
|
|
36990
|
+
continue;
|
|
36991
|
+
const p = join4(dir, n);
|
|
36992
|
+
let st;
|
|
36993
|
+
try {
|
|
36994
|
+
st = statSync2(p);
|
|
36995
|
+
} catch {
|
|
36996
|
+
continue;
|
|
36997
|
+
}
|
|
36998
|
+
if (st.isDirectory()) {
|
|
36999
|
+
if (depth > 0)
|
|
37000
|
+
walk(p, depth - 1);
|
|
37001
|
+
continue;
|
|
37002
|
+
}
|
|
37003
|
+
if (!n.endsWith(".json") || st.size > 1e6)
|
|
37004
|
+
continue;
|
|
37005
|
+
let m;
|
|
37006
|
+
try {
|
|
37007
|
+
m = JSON.parse(readFileSync6(p, "utf8"));
|
|
37008
|
+
} catch {
|
|
37009
|
+
continue;
|
|
37010
|
+
}
|
|
37011
|
+
if (!m || typeof m !== "object" || !("mandateFormat" in m) || !m.agent?.id)
|
|
37012
|
+
continue;
|
|
37013
|
+
const op = checkOperator(m);
|
|
37014
|
+
found.push({
|
|
37015
|
+
name: m.agent.name,
|
|
37016
|
+
id: m.agent.id,
|
|
37017
|
+
owner: m.owner?.name ?? m.owner?.id ?? "",
|
|
37018
|
+
operator: op.present ? op.valid ? op.name ?? "" : "invalid countersignature" : "",
|
|
37019
|
+
purpose: m.purpose ?? "",
|
|
37020
|
+
autonomy: m.autonomy ?? "act",
|
|
37021
|
+
tools: m.allow?.tools?.length ?? 0,
|
|
37022
|
+
riskTier: agentRiskTier(m).tier,
|
|
37023
|
+
maturity: agentMaturity(m).label,
|
|
37024
|
+
expires: m.expires,
|
|
37025
|
+
valid: checkMandate(m).ok,
|
|
37026
|
+
revoked: Boolean(revocationOf(m, o.revocationsPath)),
|
|
37027
|
+
file: p
|
|
37028
|
+
});
|
|
37029
|
+
}
|
|
37030
|
+
};
|
|
37031
|
+
for (const d of dirs)
|
|
37032
|
+
walk(d, o.depth ?? 3);
|
|
37033
|
+
return found;
|
|
37034
|
+
}
|
|
37035
|
+
var init_agents = __esm({
|
|
37036
|
+
"packages/testkit-core/dist/agents.js"() {
|
|
37037
|
+
"use strict";
|
|
37038
|
+
init_agentid();
|
|
37039
|
+
}
|
|
37040
|
+
});
|
|
37041
|
+
|
|
36916
37042
|
// packages/testkit-core/dist/index.js
|
|
36917
37043
|
var dist_exports = {};
|
|
36918
37044
|
__export(dist_exports, {
|
|
@@ -37014,6 +37140,7 @@ __export(dist_exports, {
|
|
|
37014
37140
|
lintPaths: () => lintPaths,
|
|
37015
37141
|
lintSarif: () => lintSarif,
|
|
37016
37142
|
lintSource: () => lintSource,
|
|
37143
|
+
listPending: () => listPending,
|
|
37017
37144
|
loadEmbeddedPacks: () => loadEmbeddedPacks,
|
|
37018
37145
|
loadPack: () => loadPack,
|
|
37019
37146
|
loadPackDir: () => loadPackDir,
|
|
@@ -37035,6 +37162,7 @@ __export(dist_exports, {
|
|
|
37035
37162
|
perfAnalysers: () => perfAnalysers,
|
|
37036
37163
|
readinessFor: () => readinessFor,
|
|
37037
37164
|
receiptsToOtlp: () => receiptsToOtlp,
|
|
37165
|
+
recordPending: () => recordPending,
|
|
37038
37166
|
redactCommand: () => redactCommand,
|
|
37039
37167
|
redactUrl: () => redactUrl,
|
|
37040
37168
|
renderFix: () => renderFix,
|
|
@@ -37051,6 +37179,7 @@ __export(dist_exports, {
|
|
|
37051
37179
|
runTestCases: () => runTestCases,
|
|
37052
37180
|
runTrustCheck: () => runTrustCheck,
|
|
37053
37181
|
sanitizeText: () => sanitizeText,
|
|
37182
|
+
scanAgents: () => scanAgents,
|
|
37054
37183
|
schemaDialect: () => schemaDialect,
|
|
37055
37184
|
score: () => score,
|
|
37056
37185
|
searchCatalogue: () => searchCatalogue,
|
|
@@ -37114,6 +37243,7 @@ var init_dist4 = __esm({
|
|
|
37114
37243
|
init_vocab();
|
|
37115
37244
|
init_market();
|
|
37116
37245
|
init_crosswalk();
|
|
37246
|
+
init_agents();
|
|
37117
37247
|
}
|
|
37118
37248
|
});
|
|
37119
37249
|
|
|
@@ -37198,7 +37328,7 @@ function renderPassportGallery(entries) {
|
|
|
37198
37328
|
}).join("");
|
|
37199
37329
|
return page("MCP Server Passports: the Saktum trust ledger", `<div class="card"><small>SAKTUM TRUST LEDGER</small><h1>MCP Server Passports</h1><p class="muted">Servers whose publishers recorded a signed Saktum attestation in the public, append-only ledger. Anyone can verify every entry: <code>npx saktum ledger verify</code>. Add yours: <code>npx saktum attest saktum-report.json --publish</code>.</p></div>${cards || `<p class="muted">No entries yet.</p>`}`);
|
|
37200
37330
|
}
|
|
37201
|
-
function renderAssessment(org, f, receipts = [], roi, frameworks, disclaimer) {
|
|
37331
|
+
function renderAssessment(org, f, receipts = [], roi, frameworks, disclaimer, agents) {
|
|
37202
37332
|
const risky = /* @__PURE__ */ new Set(["code-execution", "money", "sends-messages", "writes-or-deletes", "reads-private-data"]);
|
|
37203
37333
|
const caps = ["code-execution", "money", "sends-messages", "writes-or-deletes", "reads-private-data", "network", "filesystem", "untrusted-content"];
|
|
37204
37334
|
const grades = ["A", "B", "C", "D", "F", "-"];
|
|
@@ -37226,11 +37356,20 @@ function renderAssessment(org, f, receipts = [], roi, frameworks, disclaimer) {
|
|
|
37226
37356
|
<div class="card"><h2>Servers needing attention</h2>${top ? `<div class="wrap"><table><tr><th>Server</th><th>Machines</th><th>Trust / readiness</th><th>Why</th></tr>${top}</table></div>` : `<p>None: every assessed server meets the policy.</p>`}</div>
|
|
37227
37357
|
${rc ? `<div class="card"><h2>Agent receipts</h2><div class="wrap"><table><tr><th>Agent</th><th>Calls</th><th>Blocked</th><th>Destructive</th><th>Repeated calls</th><th>Receipts</th></tr>${rc}</table></div></div>` : ""}
|
|
37228
37358
|
${roi ? `<div class="card"><h2>Business case</h2><div class="grid"><div class="kv"><small>Tool definitions cost a year</small><b>$${roi.annualToolCost.toLocaleString("en-US")}</b></div><div class="kv"><small>Savings from fixes</small><b>$${roi.tokenSavings.toLocaleString("en-US")}</b></div><div class="kv"><small>Review effort replaced by passports</small><b>$${roi.reviewSavings.toLocaleString("en-US")}</b></div><div class="kv"><small>Total a year</small><b>$${roi.totalSavings.toLocaleString("en-US")}</b></div></div><p class="muted">Estimate. Assumptions: ${esc2(roi.assumptions)}. Replace them with your own figures.</p></div>` : ""}
|
|
37359
|
+
${agents ? `<div class="card"><h2>Agents</h2>${agents.length ? `<div class="wrap"><table><tr><th>Agent</th><th>Owner</th><th>Operator</th><th>Autonomy</th><th>Risk</th><th>Maturity</th><th>Status</th></tr>${agents.map((a) => `<tr><td>${esc2(a.name)}</td><td>${esc2(a.owner)}</td><td>${esc2(a.operator || "none")}</td><td>${esc2(a.autonomy)}</td><td>${esc2(a.riskTier)}</td><td>${esc2(a.maturity)}</td><td>${a.revoked ? "revoked" : !a.valid ? "invalid or expired" : "active until " + esc2(a.expires)}</td></tr>`).join("")}</table></div>` : `<p>No agent mandates found.</p>`}<p class="muted">From <code>npx saktum agents scan</code>. Agents without an operator countersignature, or with broad autonomy on risky tiers, deserve review first.</p></div>` : ""}
|
|
37229
37360
|
${frameworks?.length ? `<div class="card"><h2>Evidence for the frameworks you are held to</h2><div class="wrap"><table><tr><th>Framework</th><th>Covered</th><th>Partly</th><th>Not covered</th></tr>${frameworks.map((x) => `<tr><td>${esc2(x.name)}</td><td>${x.summary.covered}</td><td>${x.summary.partial}</td><td>${x.summary.gap}</td></tr>`).join("")}</table></div><p class="muted">${esc2(disclaimer ?? "")} Details: <code>npx saktum evidence --framework all</code>.</p></div>` : ""}
|
|
37230
37361
|
<div class="card"><h2>Recommendations</h2><ol>${rec.map((x) => `<li>${esc2(x)}</li>`).join("")}</ol></div>
|
|
37231
37362
|
<div class="card"><h2>Next steps</h2><p>1. Agree the policy and exceptions with security. 2. Enforce it in CI on MCP repositories. 3. Deploy the allowlist to the MCP firewall or gateway. 4. Extend agent mandates and receipts to production agent workflows with the Saktum gateway (design partnership).</p><p class="muted">Findings describe the servers and agents at the time of assessment and are not a guarantee of security.</p></div>`;
|
|
37232
37363
|
return page(`MCP Trust Assessment: ${org}`, body2);
|
|
37233
37364
|
}
|
|
37365
|
+
function renderReceiptsView(logs) {
|
|
37366
|
+
const all = logs.flatMap((l) => l.entries.map((e) => ({ ...e, log: l.name }))).sort((a, b) => a.at.localeCompare(b.at));
|
|
37367
|
+
const sum = logs.map((l) => `<tr><td>${esc2(l.name)}</td><td>${l.entries.length}</td><td>${l.entries.filter((e) => e.outcome === "allow").length}</td><td>${l.entries.filter((e) => e.outcome === "deny").length}</td><td>${l.entries.reduce((n, e) => n + e.tokens, 0)}</td><td>${l.verified ? "\u2713 verified" : "\u2717 NOT verified"}</td></tr>`).join("");
|
|
37368
|
+
const rows = all.slice(-500).map((e) => `<tr><td><code>${esc2(e.at.slice(0, 19).replace("T", " "))}</code></td><td>${esc2(e.agent)}</td><td>${esc2(e.tool)}</td><td><span class="step ${e.outcome === "deny" ? "deny" : "ok"}">${e.outcome === "deny" ? "\u26D4 " + esc2(e.code) : "\u2713"}</span></td><td>${esc2(e.reason)}</td><td>${e.tokens || ""}</td></tr>`).join("");
|
|
37369
|
+
return page("Saktum receipts: combined view", `<div class="card"><small>RECEIPTS \xB7 COMBINED VIEW</small><h1>${all.length} agent calls across ${logs.length} log(s)</h1><p class="muted">Each log verified independently: every signature and every link of its hash chain.</p>
|
|
37370
|
+
<div class="wrap"><table><tr><th>Log</th><th>Calls</th><th>Allowed</th><th>Blocked</th><th>Tokens</th><th>Integrity</th></tr>${sum}</table></div></div>
|
|
37371
|
+
<div class="card"><h2>Timeline</h2><div class="wrap"><table><tr><th>Time (UTC)</th><th>Agent</th><th>Tool</th><th>Decision</th><th>Reason</th><th>Tokens</th></tr>${rows}</table></div>${all.length > 500 ? `<p class="muted">Latest 500 of ${all.length}.</p>` : ""}</div>`);
|
|
37372
|
+
}
|
|
37234
37373
|
var esc2, GRADE_COLOUR, chip, STYLE, page, levelBar, effect, passportSlug, evidenceLevel;
|
|
37235
37374
|
var init_passport = __esm({
|
|
37236
37375
|
"packages/report/dist/passport.js"() {
|
|
@@ -37581,9 +37720,9 @@ __export(init_exports, {
|
|
|
37581
37720
|
initProject: () => initProject
|
|
37582
37721
|
});
|
|
37583
37722
|
import { existsSync as existsSync4, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
37584
|
-
import { join as
|
|
37723
|
+
import { join as join5 } from "node:path";
|
|
37585
37724
|
function initProject(dir, lang, name) {
|
|
37586
|
-
if (existsSync4(
|
|
37725
|
+
if (existsSync4(join5(dir, "package.json")) || existsSync4(join5(dir, "pyproject.toml")) || existsSync4(join5(dir, "server.py")))
|
|
37587
37726
|
throw new Error(`${dir} already contains a project; choose an empty folder.`);
|
|
37588
37727
|
const id = name.replace(/[^a-z0-9-]/gi, "-").toLowerCase() || "my-mcp-server";
|
|
37589
37728
|
const files = {};
|
|
@@ -37672,8 +37811,8 @@ if __name__ == "__main__":
|
|
|
37672
37811
|
|
|
37673
37812
|
${AGENT_RULES}`;
|
|
37674
37813
|
for (const [p, text2] of Object.entries(files)) {
|
|
37675
|
-
const f =
|
|
37676
|
-
mkdirSync3(
|
|
37814
|
+
const f = join5(dir, p);
|
|
37815
|
+
mkdirSync3(join5(f, ".."), { recursive: true });
|
|
37677
37816
|
writeFileSync3(f, text2);
|
|
37678
37817
|
}
|
|
37679
37818
|
return Object.keys(files);
|
|
@@ -37761,7 +37900,7 @@ __export(proxy_exports, {
|
|
|
37761
37900
|
runProxy: () => runProxy
|
|
37762
37901
|
});
|
|
37763
37902
|
import { spawn as spawn3 } from "node:child_process";
|
|
37764
|
-
import { appendFileSync, existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as
|
|
37903
|
+
import { appendFileSync, existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync7 } from "node:fs";
|
|
37765
37904
|
import { dirname as dirname3 } from "node:path";
|
|
37766
37905
|
import { createInterface } from "node:readline";
|
|
37767
37906
|
import { randomUUID } from "node:crypto";
|
|
@@ -37770,7 +37909,7 @@ async function runProxy(o) {
|
|
|
37770
37909
|
let last;
|
|
37771
37910
|
let history = [];
|
|
37772
37911
|
if (existsSync5(o.receiptsPath)) {
|
|
37773
|
-
history = parseReceiptLog(
|
|
37912
|
+
history = parseReceiptLog(readFileSync7(o.receiptsPath, "utf8"));
|
|
37774
37913
|
last = history[history.length - 1];
|
|
37775
37914
|
}
|
|
37776
37915
|
const today = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
@@ -37853,8 +37992,18 @@ async function runProxy(o) {
|
|
|
37853
37992
|
const ap = consumeApproval(o.mandate, rid, o.approvalsPath);
|
|
37854
37993
|
if (ap.ok)
|
|
37855
37994
|
d = { allow: true, code: "ok", reason: `approved by ${ap.by} (${rid}), after: ${d.reason}` };
|
|
37856
|
-
else
|
|
37995
|
+
else {
|
|
37857
37996
|
d = { ...d, reason: `${d.reason} [approval request ${rid}]` };
|
|
37997
|
+
try {
|
|
37998
|
+
recordPending(o.approvalsPath ?? DEFAULT_APPROVALS(), { id: rid, tool, reason: d.reason, agent: o.mandate.agent.name });
|
|
37999
|
+
} catch {
|
|
38000
|
+
}
|
|
38001
|
+
if (o.approvalWebhook) {
|
|
38002
|
+
const link = o.approvalUrl ? `${o.approvalUrl}${o.approvalUrl.includes("?") ? "&" : "?"}id=${rid}` : "";
|
|
38003
|
+
const text2 = `Approval needed: ${o.mandate.agent.name} wants to run ${tool}. ${d.reason.replace(/ \[approval request [^\]]+\]/, "")}. Request ${rid}. ${link ? `Approve: ${link}` : `Approve with: npx saktum agent approve ${rid} --mandate <mandate>`}`;
|
|
38004
|
+
fetch(o.approvalWebhook, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text: text2, requestId: rid, tool, agent: o.mandate.agent.name, ...link ? { approveUrl: link } : {} }) }).catch(() => void 0);
|
|
38005
|
+
}
|
|
38006
|
+
}
|
|
37858
38007
|
}
|
|
37859
38008
|
if (d.allow && o.credential) {
|
|
37860
38009
|
const vc = verifyChain(o.credential, { revoked: o.revokedCredentials });
|
|
@@ -37921,8 +38070,10 @@ async function runProxy(o) {
|
|
|
37921
38070
|
}
|
|
37922
38071
|
if (kind === "tools/list" && Array.isArray(msg.result?.tools)) {
|
|
37923
38072
|
for (const t of msg.result.tools) {
|
|
38073
|
+
const ov = o.bindingsOverride?.[t.name];
|
|
38074
|
+
const def = ov ? { ...t, _meta: { ...t._meta ?? {}, ...ov.action ? { "io.saktum/action": ov.action } : {}, ...ov.bindings ? { "io.saktum/bindings": ov.bindings } : {} } } : t;
|
|
37924
38075
|
annotations.set(t.name, t.annotations);
|
|
37925
|
-
toolDefs.set(t.name,
|
|
38076
|
+
toolDefs.set(t.name, def);
|
|
37926
38077
|
}
|
|
37927
38078
|
pendingKinds.delete(k);
|
|
37928
38079
|
}
|
|
@@ -37947,6 +38098,77 @@ var init_proxy = __esm({
|
|
|
37947
38098
|
}
|
|
37948
38099
|
});
|
|
37949
38100
|
|
|
38101
|
+
// packages/cli/dist/bridge.js
|
|
38102
|
+
var bridge_exports = {};
|
|
38103
|
+
__export(bridge_exports, {
|
|
38104
|
+
runBridge: () => runBridge
|
|
38105
|
+
});
|
|
38106
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
38107
|
+
async function runBridge(url2, headers) {
|
|
38108
|
+
let session;
|
|
38109
|
+
const out = (m) => process.stdout.write(JSON.stringify(m) + "\n");
|
|
38110
|
+
const rl = createInterface2({ input: process.stdin });
|
|
38111
|
+
const pending = [];
|
|
38112
|
+
const forward = async (line) => {
|
|
38113
|
+
let msg = {};
|
|
38114
|
+
try {
|
|
38115
|
+
msg = JSON.parse(line);
|
|
38116
|
+
} catch {
|
|
38117
|
+
return;
|
|
38118
|
+
}
|
|
38119
|
+
try {
|
|
38120
|
+
const res = await fetch(url2, {
|
|
38121
|
+
method: "POST",
|
|
38122
|
+
body: line,
|
|
38123
|
+
headers: { "Content-Type": "application/json", Accept: "application/json, text/event-stream", ...session ? { "Mcp-Session-Id": session } : {}, ...headers }
|
|
38124
|
+
});
|
|
38125
|
+
const sid = res.headers.get("mcp-session-id");
|
|
38126
|
+
if (sid)
|
|
38127
|
+
session = sid;
|
|
38128
|
+
const text2 = await res.text();
|
|
38129
|
+
if (msg.id === void 0 || res.status === 202)
|
|
38130
|
+
return;
|
|
38131
|
+
if (!res.ok && !text2.trim()) {
|
|
38132
|
+
out({ jsonrpc: "2.0", id: msg.id, error: { code: -32e3, message: `upstream HTTP ${res.status}` } });
|
|
38133
|
+
return;
|
|
38134
|
+
}
|
|
38135
|
+
if ((res.headers.get("content-type") ?? "").includes("text/event-stream")) {
|
|
38136
|
+
for (const l of text2.split(/\r?\n/))
|
|
38137
|
+
if (l.startsWith("data:")) {
|
|
38138
|
+
const d = l.slice(5).trim();
|
|
38139
|
+
if (d)
|
|
38140
|
+
process.stdout.write(d + "\n");
|
|
38141
|
+
}
|
|
38142
|
+
} else if (text2.trim()) {
|
|
38143
|
+
const j = JSON.parse(text2);
|
|
38144
|
+
for (const m of Array.isArray(j) ? j : [j])
|
|
38145
|
+
out(m);
|
|
38146
|
+
}
|
|
38147
|
+
} catch (e) {
|
|
38148
|
+
if (msg.id !== void 0)
|
|
38149
|
+
out({ jsonrpc: "2.0", id: msg.id, error: { code: -32e3, message: `upstream unreachable: ${String(e.message).slice(0, 120)}` } });
|
|
38150
|
+
}
|
|
38151
|
+
};
|
|
38152
|
+
rl.on("line", (line) => {
|
|
38153
|
+
if (line.trim())
|
|
38154
|
+
pending.push(forward(line));
|
|
38155
|
+
});
|
|
38156
|
+
await new Promise((r) => rl.on("close", () => r()));
|
|
38157
|
+
await Promise.allSettled(pending);
|
|
38158
|
+
if (session) {
|
|
38159
|
+
try {
|
|
38160
|
+
await fetch(url2, { method: "DELETE", headers: { "Mcp-Session-Id": session, ...headers } });
|
|
38161
|
+
} catch {
|
|
38162
|
+
}
|
|
38163
|
+
}
|
|
38164
|
+
return 0;
|
|
38165
|
+
}
|
|
38166
|
+
var init_bridge = __esm({
|
|
38167
|
+
"packages/cli/dist/bridge.js"() {
|
|
38168
|
+
"use strict";
|
|
38169
|
+
}
|
|
38170
|
+
});
|
|
38171
|
+
|
|
37950
38172
|
// node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.2_zod@4.6.7/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/server.js
|
|
37951
38173
|
var ExperimentalServerTasks;
|
|
37952
38174
|
var init_server = __esm({
|
|
@@ -38629,8 +38851,8 @@ __export(demo_exports, {
|
|
|
38629
38851
|
runDemo: () => runDemo,
|
|
38630
38852
|
startDemoServer: () => startDemoServer
|
|
38631
38853
|
});
|
|
38632
|
-
import { mkdirSync as mkdirSync5, readFileSync as
|
|
38633
|
-
import { join as
|
|
38854
|
+
import { mkdirSync as mkdirSync5, readFileSync as readFileSync8, writeFileSync as writeFileSync4, existsSync as existsSync6, rmSync } from "node:fs";
|
|
38855
|
+
import { join as join6 } from "node:path";
|
|
38634
38856
|
async function startDemoServer(story = "autonomy") {
|
|
38635
38857
|
const tools = story === "grocery" ? GROCERY_TOOLS : story === "travel" ? TRAVEL_TOOLS : story === "finance" ? FINANCE_TOOLS : story === "coding" ? CODING_TOOLS : DEMO_TOOLS;
|
|
38636
38858
|
const server = new Server({ name: story === "travel" ? "demo-travel" : story === "finance" ? "demo-finance" : "demo-grocer", version: "1.0.0" }, { capabilities: { tools: {} } });
|
|
@@ -38688,7 +38910,7 @@ async function startDemoServer(story = "autonomy") {
|
|
|
38688
38910
|
}
|
|
38689
38911
|
async function runStory(dir, st, owner, log) {
|
|
38690
38912
|
const self = [...process.execArgv, process.argv[1]];
|
|
38691
|
-
const agentKey = loadOrCreateKey(
|
|
38913
|
+
const agentKey = loadOrCreateKey(join6(dir, `${st.id}-agent-key.json`));
|
|
38692
38914
|
const m = createMandate({
|
|
38693
38915
|
agentId: agentKey.kid,
|
|
38694
38916
|
agentName: `${st.id === "travel" ? "Travel" : "Shopping"} agent`,
|
|
@@ -38699,14 +38921,14 @@ async function runStory(dir, st, owner, log) {
|
|
|
38699
38921
|
...st.m
|
|
38700
38922
|
}, owner);
|
|
38701
38923
|
const operatorName = String(st.m.disclosures?.operator ?? "Demo operator");
|
|
38702
|
-
const cm = cosignMandate(m, loadOrCreateKey(
|
|
38703
|
-
const mf =
|
|
38924
|
+
const cm = cosignMandate(m, loadOrCreateKey(join6(dir, `${st.id}-operator-key.json`)), operatorName);
|
|
38925
|
+
const mf = join6(dir, `${st.id}-mandate.json`), rf = join6(dir, `${st.id}-receipts.jsonl`), revf = join6(dir, "revocations.json");
|
|
38704
38926
|
writeFileSync4(mf, JSON.stringify(cm, null, 2));
|
|
38705
38927
|
log(`\u2500\u2500 ${st.title}`);
|
|
38706
38928
|
log(` Signed by you; countersigned by the operator, ${operatorName}.`);
|
|
38707
38929
|
for (const line of describeMandate(m))
|
|
38708
38930
|
log(` ${line}`);
|
|
38709
|
-
const open2 = () => connect({ kind: "stdio", command: process.execPath, args: [...self, "proxy", "--mandate", mf, "--agent-key",
|
|
38931
|
+
const open2 = () => connect({ kind: "stdio", command: process.execPath, args: [...self, "proxy", "--mandate", mf, "--agent-key", join6(dir, `${st.id}-agent-key.json`), "--enforce", "--receipts", rf, "--revocations", revf, "--approvals", join6(dir, "approvals.json"), "--", process.execPath, ...self, "demo-server", "--story", st.server] });
|
|
38710
38932
|
const s = await open2();
|
|
38711
38933
|
try {
|
|
38712
38934
|
await s.listTools();
|
|
@@ -38714,7 +38936,7 @@ async function runStory(dir, st, owner, log) {
|
|
|
38714
38936
|
for (const step of st.steps) {
|
|
38715
38937
|
if (step.approveLast) {
|
|
38716
38938
|
const { approveAction: approveAction2 } = await Promise.resolve().then(() => (init_dist4(), dist_exports));
|
|
38717
|
-
approveAction2(cm, lastRid, owner, 60,
|
|
38939
|
+
approveAction2(cm, lastRid, owner, 60, join6(dir, "approvals.json"));
|
|
38718
38940
|
log(` \u270D ${step.say}: ${lastRid}`);
|
|
38719
38941
|
continue;
|
|
38720
38942
|
}
|
|
@@ -38724,9 +38946,9 @@ async function runStory(dir, st, owner, log) {
|
|
|
38724
38946
|
if (rid)
|
|
38725
38947
|
lastRid = rid[1];
|
|
38726
38948
|
const blocked = /^Blocked by Saktum \(([^)]+)\): (.+?)( \[approval request [^\]]+\])?\.( Ask| Tell|$)/.exec(txt);
|
|
38727
|
-
const lastR = parseReceiptLog(
|
|
38949
|
+
const lastR = parseReceiptLog(readFileSync8(rf, "utf8")).pop();
|
|
38728
38950
|
log(blocked ? ` \u26D4 ${step.say}: ${blocked[1]}: ${blocked[2]}` : ` \u2713 ${step.say}${/approved by/.test(String(lastR?.receipt.reason ?? "")) ? ": approved by you, once" : ""}`);
|
|
38729
|
-
const last = parseReceiptLog(
|
|
38951
|
+
const last = parseReceiptLog(readFileSync8(rf, "utf8")).pop();
|
|
38730
38952
|
for (const p of last?.result.rationale?.preferences ?? [])
|
|
38731
38953
|
if (!blocked)
|
|
38732
38954
|
log(` \xB7 ${p}`);
|
|
@@ -38751,12 +38973,12 @@ async function runStory(dir, st, owner, log) {
|
|
|
38751
38973
|
await new Promise((r) => setTimeout(r, 300));
|
|
38752
38974
|
}
|
|
38753
38975
|
}
|
|
38754
|
-
const entries = parseReceiptLog(
|
|
38976
|
+
const entries = parseReceiptLog(readFileSync8(rf, "utf8"));
|
|
38755
38977
|
const ts = trustStatement(entries, verifyReceiptLog(entries).ok);
|
|
38756
38978
|
log(" Track record:");
|
|
38757
38979
|
for (const l of ts.lines)
|
|
38758
38980
|
log(` ${l}`);
|
|
38759
|
-
const html =
|
|
38981
|
+
const html = join6(dir, `${st.id}-passport.html`);
|
|
38760
38982
|
writeFileSync4(html, renderAgentPassport(m, checkMandate(m).ok ? { ok: true } : { ok: false }, {
|
|
38761
38983
|
verified: verifyReceiptLog(entries).ok,
|
|
38762
38984
|
summary: summariseReceipts(entries),
|
|
@@ -38775,12 +38997,12 @@ async function runStory(dir, st, owner, log) {
|
|
|
38775
38997
|
}
|
|
38776
38998
|
async function runMarketplace(dir, log) {
|
|
38777
38999
|
const self = [...process.execArgv, process.argv[1]];
|
|
38778
|
-
const k = (n) => loadOrCreateKey(
|
|
39000
|
+
const k = (n) => loadOrCreateKey(join6(dir, `market-${n}-key.json`));
|
|
38779
39001
|
const acme = k("acme"), priya = k("priya"), agent = k("agent"), grocer = k("grocer"), travel = k("travel");
|
|
38780
39002
|
const exp = new Date(Date.now() + 180 * 864e5).toISOString().slice(0, 10);
|
|
38781
39003
|
const w = (f, x) => {
|
|
38782
|
-
writeFileSync4(
|
|
38783
|
-
return
|
|
39004
|
+
writeFileSync4(join6(dir, f), JSON.stringify(x, null, 2));
|
|
39005
|
+
return join6(dir, f);
|
|
38784
39006
|
};
|
|
38785
39007
|
log(`\u2500\u2500 Marketplace: "Acme's shopping agent finds a store, agrees terms, and pays per call in prepaid tokens"`);
|
|
38786
39008
|
const root = organisationRoot({ name: "Acme Corp", domain: "acme.example", expires: exp }, acme);
|
|
@@ -38806,11 +39028,11 @@ async function runMarketplace(dir, log) {
|
|
|
38806
39028
|
}, grocer), acme);
|
|
38807
39029
|
const agFile = w("market-agreement.json", ag);
|
|
38808
39030
|
log(` \u2713 agreement ${ag.id}: ${ag.terms.length} default terms + ${ag.specificTerms.length} specific, signed by Demo Grocer and Acme Corp (${verifyAgreement(ag).valid ? "verified" : "NOT valid"})`);
|
|
38809
|
-
const wf =
|
|
39031
|
+
const wf = join6(dir, "market-wallet.json");
|
|
38810
39032
|
topUp(wf, acme.kid, 12);
|
|
38811
39033
|
log(` \u2713 Acme tops up 12 prepaid tokens (bought outside Saktum; no money is handled here)`);
|
|
38812
39034
|
const m = cosignMandate(createMandate({ agentId: agent.kid, agentName: "Acme shopping agent", ownerName: "Priya", purpose: "Weekly office groceries", tools: gm.capabilities.map((c) => c.tool), destructive: false, expires: exp, autonomy: "act", approveAbove: { arg: "amount", value: 50 } }, priya), acme, "Acme Corp");
|
|
38813
|
-
const mf = w("market-mandate.json", m), rf =
|
|
39035
|
+
const mf = w("market-mandate.json", m), rf = join6(dir, "market-receipts.jsonl"), revf = join6(dir, "market-revoked-credentials.json");
|
|
38814
39036
|
writeFileSync4(revf, "[]");
|
|
38815
39037
|
const open2 = () => connect({ kind: "stdio", command: process.execPath, args: [
|
|
38816
39038
|
...self,
|
|
@@ -38818,7 +39040,7 @@ async function runMarketplace(dir, log) {
|
|
|
38818
39040
|
"--mandate",
|
|
38819
39041
|
mf,
|
|
38820
39042
|
"--agent-key",
|
|
38821
|
-
|
|
39043
|
+
join6(dir, "market-agent-key.json"),
|
|
38822
39044
|
"--enforce",
|
|
38823
39045
|
"--receipts",
|
|
38824
39046
|
rf,
|
|
@@ -38853,7 +39075,7 @@ async function runMarketplace(dir, log) {
|
|
|
38853
39075
|
const o = await s2.callTool(st1.tool, st1.args);
|
|
38854
39076
|
const txt = o.kind === "result" ? o.content.map((c) => c.text ?? "").join(" ") : o.kind;
|
|
38855
39077
|
const blocked = /^Blocked by Saktum \(([^)]+)\): (.+?)\.( Ask| Tell|$)/.exec(txt);
|
|
38856
|
-
const last = parseReceiptLog(
|
|
39078
|
+
const last = parseReceiptLog(readFileSync8(rf, "utf8")).pop();
|
|
38857
39079
|
log(blocked ? ` \u26D4 ${st1.say}: ${blocked[1]}: ${blocked[2]}` : ` \u2713 ${st1.say} \xB7 ${last?.result.metering?.tokens ?? 0} token(s), balance ${last?.result.metering?.balance ?? "-"}`);
|
|
38858
39080
|
}
|
|
38859
39081
|
} finally {
|
|
@@ -38862,7 +39084,7 @@ async function runMarketplace(dir, log) {
|
|
|
38862
39084
|
}
|
|
38863
39085
|
};
|
|
38864
39086
|
await run(steps);
|
|
38865
|
-
const entries = parseReceiptLog(
|
|
39087
|
+
const entries = parseReceiptLog(readFileSync8(rf, "utf8"));
|
|
38866
39088
|
const st = usageStatement(entries, ag, grocer);
|
|
38867
39089
|
log(` \u2713 usage statement signed by Demo Grocer: ${st.lines.map((l) => `${l.tool} ${l.calls}\xD7 = ${l.tokens}`).join(", ")}; total ${st.totalTokens} tokens`);
|
|
38868
39090
|
log(` \u2713 wallet (double-entry): Acme ${walletBalance(wf, acme.kid)} tokens, Demo Grocer ${walletBalance(wf, grocer.kid)} tokens`);
|
|
@@ -38871,10 +39093,10 @@ async function runMarketplace(dir, log) {
|
|
|
38871
39093
|
log(` \u26D4 Priya leaves Acme and her credential is revoked: the agent is now an orphan (${orphan?.reason})`);
|
|
38872
39094
|
topUp(wf, acme.kid, 5);
|
|
38873
39095
|
await run([{ tool: "search_products", args: { query: "milk" }, say: "the orphaned agent tries to search" }]);
|
|
38874
|
-
const all = parseReceiptLog(
|
|
39096
|
+
const all = parseReceiptLog(readFileSync8(rf, "utf8"));
|
|
38875
39097
|
const k2 = kpis(all);
|
|
38876
39098
|
log(` KPIs: ${k2.calls} calls \xB7 ${k2.allowed} allowed \xB7 ${k2.blocked} blocked (${k2.byOutcome.filter(([c]) => !c.startsWith("ok")).map(([c, n]) => `${n} ${c}`).join(", ")}) \xB7 ${k2.tokens} tokens`);
|
|
38877
|
-
const html =
|
|
39099
|
+
const html = join6(dir, "marketplace-passport.html");
|
|
38878
39100
|
const ts = trustStatement(all, verifyReceiptLog(all).ok);
|
|
38879
39101
|
writeFileSync4(html, renderAgentPassport(m, { ok: true }, { verified: verifyReceiptLog(all).ok, summary: summariseReceipts(all), timeline: all.map((e) => ({ tool: e.receipt.envelope.tool, outcome: e.receipt.outcome, status: e.result.status, repeated: false, why: [e.receipt.reason ?? "", e.result.metering ? `${e.result.metering.tokens} token(s), balance ${e.result.metering.balance}` : ""].filter(Boolean).join(" \xB7 ") })) }, agentRiskTier(m), [`Weekly office groceries for Acme Corp, under agreement ${ag.id} with Demo Grocer.`, `Accountable: ${verifyChain(agentCred).path.join(" \u2192 ")}.`, "Paid per call in prepaid tokens."], { operator: "Acme Corp", track: ts.lines, maturity: agentMaturity(m, { entries: all, verified: verifyReceiptLog(all).ok, chainValid: verifyChain(agentCred).valid }) }));
|
|
38880
39102
|
log(` ${all.length} signed receipts \xB7 ${verifyReceiptLog(all).ok ? "verified" : "NOT verified"} \xB7 passport: ${html}
|
|
@@ -38893,7 +39115,7 @@ async function runDemo(dir, log, story = "all") {
|
|
|
38893
39115
|
if (existsSync6(dir))
|
|
38894
39116
|
rmSync(dir, { recursive: true, force: true });
|
|
38895
39117
|
mkdirSync5(dir, { recursive: true });
|
|
38896
|
-
const owner = loadOrCreateKey(
|
|
39118
|
+
const owner = loadOrCreateKey(join6(dir, "owner-key.json"));
|
|
38897
39119
|
log("Saktum demo: agents acting on real instructions (rules, preferences, substitutions, upsells), every decision explained and signed.\n");
|
|
38898
39120
|
const files = [];
|
|
38899
39121
|
for (const st of story === "travel" ? [TRAVEL] : story === "grocery" ? [GROCERY] : story === "finance" ? [FINANCE] : story === "coding" ? [CODING] : [GROCERY, TRAVEL, FINANCE, CODING])
|
|
@@ -38914,7 +39136,7 @@ async function runAutonomyDemo(dir, log) {
|
|
|
38914
39136
|
if (existsSync6(dir))
|
|
38915
39137
|
rmSync(dir, { recursive: true, force: true });
|
|
38916
39138
|
mkdirSync5(dir, { recursive: true });
|
|
38917
|
-
const owner = loadOrCreateKey(
|
|
39139
|
+
const owner = loadOrCreateKey(join6(dir, "owner-key.json"));
|
|
38918
39140
|
const self = [...process.execArgv, process.argv[1]];
|
|
38919
39141
|
const tools = DEMO_TOOLS.map((t) => t.name);
|
|
38920
39142
|
const personas = [
|
|
@@ -38925,7 +39147,7 @@ async function runAutonomyDemo(dir, log) {
|
|
|
38925
39147
|
const files = [];
|
|
38926
39148
|
log("Saktum demo: one shopping agent, three mandates, every call governed and receipted.\n");
|
|
38927
39149
|
for (const p of personas) {
|
|
38928
|
-
const agentKey = loadOrCreateKey(
|
|
39150
|
+
const agentKey = loadOrCreateKey(join6(dir, `${p.id}-agent-key.json`));
|
|
38929
39151
|
const m = createMandate({
|
|
38930
39152
|
agentId: agentKey.kid,
|
|
38931
39153
|
agentName: `Shopping agent (${p.id})`,
|
|
@@ -38937,11 +39159,11 @@ async function runAutonomyDemo(dir, log) {
|
|
|
38937
39159
|
disclosures: { operator: "Demo Grocer", incentives: "None: no sponsored ranking", dataUse: "Order history used only to suggest your usual items" },
|
|
38938
39160
|
...p.m
|
|
38939
39161
|
}, owner);
|
|
38940
|
-
const mf =
|
|
39162
|
+
const mf = join6(dir, `${p.id}-mandate.json`), rf = join6(dir, `${p.id}-receipts.jsonl`);
|
|
38941
39163
|
writeFileSync4(mf, JSON.stringify(m, null, 2));
|
|
38942
39164
|
const tier = agentRiskTier(m);
|
|
38943
39165
|
log(`\u2500\u2500 ${p.title} autonomy ${m.autonomy} \xB7 risk ${tier.tier}`);
|
|
38944
|
-
const s = await connect({ kind: "stdio", command: process.execPath, args: [...self, "proxy", "--mandate", mf, "--agent-key",
|
|
39166
|
+
const s = await connect({ kind: "stdio", command: process.execPath, args: [...self, "proxy", "--mandate", mf, "--agent-key", join6(dir, `${p.id}-agent-key.json`), "--enforce", "--receipts", rf, "--", process.execPath, ...self, "demo-server"] });
|
|
38945
39167
|
try {
|
|
38946
39168
|
await s.listTools();
|
|
38947
39169
|
for (const st of p.steps) {
|
|
@@ -38954,13 +39176,13 @@ async function runAutonomyDemo(dir, log) {
|
|
|
38954
39176
|
await s.close();
|
|
38955
39177
|
await new Promise((r) => setTimeout(r, 300));
|
|
38956
39178
|
}
|
|
38957
|
-
const entries = parseReceiptLog(
|
|
39179
|
+
const entries = parseReceiptLog(readFileSync8(rf, "utf8"));
|
|
38958
39180
|
const counts = /* @__PURE__ */ new Map();
|
|
38959
39181
|
for (const e of entries) {
|
|
38960
39182
|
const k = `${e.receipt.envelope.tool}|${e.receipt.envelope.argumentsHash}`;
|
|
38961
39183
|
counts.set(k, (counts.get(k) ?? 0) + 1);
|
|
38962
39184
|
}
|
|
38963
|
-
const html =
|
|
39185
|
+
const html = join6(dir, `${p.id}-passport.html`);
|
|
38964
39186
|
writeFileSync4(html, renderAgentPassport(m, checkMandate(m).ok ? { ok: true } : { ok: false }, {
|
|
38965
39187
|
verified: verifyReceiptLog(entries).ok,
|
|
38966
39188
|
summary: summariseReceipts(entries),
|
|
@@ -39134,7 +39356,7 @@ __export(mcp_server_exports, {
|
|
|
39134
39356
|
splitTarget: () => splitTarget,
|
|
39135
39357
|
startMcpServer: () => startMcpServer
|
|
39136
39358
|
});
|
|
39137
|
-
import { readFileSync as
|
|
39359
|
+
import { readFileSync as readFileSync9 } from "node:fs";
|
|
39138
39360
|
function splitTarget(target) {
|
|
39139
39361
|
const t = target.trim();
|
|
39140
39362
|
if (/^https?:\/\//i.test(t))
|
|
@@ -39170,7 +39392,7 @@ async function handleSaktumTool(name, args, packs) {
|
|
|
39170
39392
|
case "diff_against_lock": {
|
|
39171
39393
|
if (typeof args.lock_path !== "string")
|
|
39172
39394
|
throw new Error("lock_path is required");
|
|
39173
|
-
const before = JSON.parse(
|
|
39395
|
+
const before = JSON.parse(readFileSync9(args.lock_path, "utf8"));
|
|
39174
39396
|
const d = diffLocks(before, { tools: (await listTools(targetOf(args.target))).tools });
|
|
39175
39397
|
return text([...d.changes.map((c) => `${c.kind}: ${c.tool}: ${c.detail}`), d.summary].join("\n"), { semver: d.semver, summary: d.summary, changes: d.changes });
|
|
39176
39398
|
}
|
|
@@ -39311,7 +39533,7 @@ var init_mcp_server = __esm({
|
|
|
39311
39533
|
});
|
|
39312
39534
|
|
|
39313
39535
|
// packages/cli/dist/main.js
|
|
39314
|
-
import { existsSync as existsSync7, readFileSync as
|
|
39536
|
+
import { existsSync as existsSync7, readFileSync as readFileSync10, writeFileSync as writeFileSync5 } from "node:fs";
|
|
39315
39537
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
39316
39538
|
|
|
39317
39539
|
// node_modules/.pnpm/commander@12.1.0/node_modules/commander/esm.mjs
|
|
@@ -39549,7 +39771,7 @@ async function main(argv = process.argv) {
|
|
|
39549
39771
|
if (o.tests) {
|
|
39550
39772
|
if (!existsSync7(o.tests))
|
|
39551
39773
|
throw new Error(`Test file not found: ${o.tests}. See docs/TESTS.md for the format.`);
|
|
39552
|
-
testCases = await parseTestCases(
|
|
39774
|
+
testCases = await parseTestCases(readFileSync10(o.tests, "utf8"));
|
|
39553
39775
|
}
|
|
39554
39776
|
const target = parseTarget(targetParts);
|
|
39555
39777
|
if (target.kind === "stdio" && o.env.length)
|
|
@@ -39581,7 +39803,7 @@ async function main(argv = process.argv) {
|
|
|
39581
39803
|
process.stdout.write(`Wrote baseline ${sanitizeText(o.baseline)} accepting ${failing.length} existing finding(s). Commit it; later runs fail only on new findings.
|
|
39582
39804
|
`);
|
|
39583
39805
|
} else if (o.baseline && existsSync7(o.baseline)) {
|
|
39584
|
-
accepted = new Set(JSON.parse(
|
|
39806
|
+
accepted = new Set(JSON.parse(readFileSync10(o.baseline, "utf8")).accepted.map(keyOf));
|
|
39585
39807
|
}
|
|
39586
39808
|
if (o.sarif)
|
|
39587
39809
|
writeFileSync5(o.sarif, JSON.stringify(toSarif(signed, o.sarifAnchor, accepted), null, 2) + "\n");
|
|
@@ -39680,8 +39902,8 @@ Watching ${sanitizeText(o.watchDir)} for changes (Ctrl+C to stop).
|
|
|
39680
39902
|
`);
|
|
39681
39903
|
});
|
|
39682
39904
|
program2.command("diff").description("Compare tools with a lock file: breaking changes, risky changes (silent tool changes), additions, and the version bump they need").argument("<lock>", "the lock file written by saktum snapshot").argument("[target...]", "a second lock file, or the server to compare (after --)").option("--allow-breaking", "do not fail on breaking or risky changes", false).option("--env <KEY=VALUE>", "environment variable for a local server (repeatable)", collect, []).option("--header <Name: value>", "HTTP header for a remote server (repeatable)", collect, []).action(async (lock, rest, o) => {
|
|
39683
|
-
const before = JSON.parse(
|
|
39684
|
-
const after = rest.length === 1 && rest[0].endsWith(".json") ? JSON.parse(
|
|
39905
|
+
const before = JSON.parse(readFileSync10(lock, "utf8"));
|
|
39906
|
+
const after = rest.length === 1 && rest[0].endsWith(".json") ? JSON.parse(readFileSync10(rest[0], "utf8")) : { tools: (await listTarget(rest, o.env, o.header)).tools };
|
|
39685
39907
|
const d = diffLocks(before, after);
|
|
39686
39908
|
const mark2 = { breaking: "\u2717 BREAKING", risky: "! REVIEW ", addition: "+ ADDED ", change: "~ CHANGED " };
|
|
39687
39909
|
for (const c of d.changes)
|
|
@@ -39698,7 +39920,7 @@ ${d.summary}
|
|
|
39698
39920
|
process.stdout.write(docsFor(tools, name, target.kind === "stdio" ? { command: target.command, args: target.args } : { url: target.url }));
|
|
39699
39921
|
});
|
|
39700
39922
|
program2.command("packet").description("Turn a signed result into a printable security packet for customers' security reviews").argument("<result>", "a signed result (saktum-report.json)").option("--out <file>", "HTML packet (print to PDF from a browser)", "saktum-security-packet.html").action((file, o) => {
|
|
39701
|
-
const doc = JSON.parse(
|
|
39923
|
+
const doc = JSON.parse(readFileSync10(file, "utf8"));
|
|
39702
39924
|
const v = verifyDocument(doc);
|
|
39703
39925
|
if (!v.valid)
|
|
39704
39926
|
throw new Error(`The result's signature is not valid (${v.reason}); a packet must be built from an unaltered signed result.`);
|
|
@@ -39712,7 +39934,7 @@ ${d.summary}
|
|
|
39712
39934
|
const check = verifyLedger(entries);
|
|
39713
39935
|
if (!check.ok)
|
|
39714
39936
|
throw new Error(`The ledger does not verify: ${check.errors[0]}`);
|
|
39715
|
-
const signers = o.trustedSigners ? new Set(
|
|
39937
|
+
const signers = o.trustedSigners ? new Set(readFileSync10(o.trustedSigners, "utf8").split(/\r?\n/).map((l) => l.trim()).filter(Boolean)) : void 0;
|
|
39716
39938
|
const list2 = allowlistFromLedger(entries, { minTrust: o.minTrust.toUpperCase(), minReadiness: o.minReadiness.toUpperCase(), trustedSigners: signers });
|
|
39717
39939
|
writeFileSync5(o.out, JSON.stringify(list2, null, 2) + "\n");
|
|
39718
39940
|
process.stdout.write(`Ledger verified (${check.count} entries). Wrote ${sanitizeText(o.out)}: ${list2.allowed.length} allowed, ${list2.excluded.length} excluded.
|
|
@@ -39722,7 +39944,7 @@ ${d.summary}
|
|
|
39722
39944
|
if (!files.length)
|
|
39723
39945
|
throw new Error("Give signed results, or use --from-ledger.");
|
|
39724
39946
|
const inputs = files.map((f) => {
|
|
39725
|
-
const doc = JSON.parse(
|
|
39947
|
+
const doc = JSON.parse(readFileSync10(f, "utf8"));
|
|
39726
39948
|
const v = verifyDocument(doc);
|
|
39727
39949
|
if (!v.valid)
|
|
39728
39950
|
throw new Error(`${f}: signature not valid (${v.reason}); only unaltered signed results can be allowlisted.`);
|
|
@@ -39809,7 +40031,7 @@ ${structured ? `structured: ${sanitizeText(JSON.stringify(structured), 1e3)}
|
|
|
39809
40031
|
expect.outputSchema = true;
|
|
39810
40032
|
expect.latencyMs = { lt: Math.max(2e3, outcome.latencyMs * 5) };
|
|
39811
40033
|
const tc = { id: o.saveTest, tool: toolName, input: args, ...tool.annotations?.readOnlyHint === true ? {} : { sideEffects: true }, expect };
|
|
39812
|
-
writeFileSync5(o.tests, await appendTestCase(existsSync7(o.tests) ?
|
|
40034
|
+
writeFileSync5(o.tests, await appendTestCase(existsSync7(o.tests) ? readFileSync10(o.tests, "utf8") : void 0, tc));
|
|
39813
40035
|
process.stdout.write(`Saved test case ${sanitizeText(o.saveTest, 60)} to ${sanitizeText(o.tests)}. Run: saktum test -- <start command>
|
|
39814
40036
|
`);
|
|
39815
40037
|
}
|
|
@@ -39817,7 +40039,7 @@ ${structured ? `structured: ${sanitizeText(JSON.stringify(structured), 1e3)}
|
|
|
39817
40039
|
program2.command("scan-config").description("Check every MCP server your agents load (Claude Desktop, Claude Code, Cursor, VS Code): total context cost, duplicate tools, unvetted servers").option("--config <file>", "a specific configuration file (repeatable); default: the known locations", collect, []).option("--yes", "start the servers without asking (they run with the settings in your configuration)", false).option("--turns-per-day <n>", "agent turns a day, for the monthly cost estimate", "50").option("--price-per-mtok <usd>", "your model's price per million input tokens", "3").option("--allowlist <file>", "saktum-allowlist.json: flag servers that are not on it").option("--out <file>", "also write the analysis as JSON (input for saktum fleet)").option("--policy <file>", "your organisation's policy: show which servers violate it").option("--machine <label>", "label for this machine in fleet reports (default: the host name)").action(async (o) => {
|
|
39818
40040
|
const { homedir: homedir2 } = await import("node:os");
|
|
39819
40041
|
const locations = o.config.length ? o.config.map((file) => ({ client: "configuration", file })) : configLocations(homedir2(), process.cwd(), process.platform, process.env.APPDATA);
|
|
39820
|
-
const servers = locations.filter((l) => existsSync7(l.file)).flatMap((l) => parseClientConfig(
|
|
40042
|
+
const servers = locations.filter((l) => existsSync7(l.file)).flatMap((l) => parseClientConfig(readFileSync10(l.file, "utf8"), l.client, l.file)).filter((x) => !x.disabled);
|
|
39821
40043
|
if (!servers.length) {
|
|
39822
40044
|
process.stdout.write("No MCP servers found in the known configuration locations. Point to one with --config <file>.\n");
|
|
39823
40045
|
return;
|
|
@@ -39867,7 +40089,7 @@ ${structured ? `structured: ${sanitizeText(JSON.stringify(structured), 1e3)}
|
|
|
39867
40089
|
scans.push({ name: x.name, client: x.client, trustGrade: null, readinessGrade: null, tools: [], tokens: 0, target: x.url ? redactUrl(x.url) : redactCommand(x.command, x.args), error: sanitizeText(e.message, 120) });
|
|
39868
40090
|
}
|
|
39869
40091
|
}
|
|
39870
|
-
const allow = o.allowlist ? new Set(JSON.parse(
|
|
40092
|
+
const allow = o.allowlist ? new Set(JSON.parse(readFileSync10(o.allowlist, "utf8")).allowed.map((a) => a.toolsFingerprint).filter((f) => Boolean(f))) : void 0;
|
|
39871
40093
|
const report = analyseSetup(scans, { turnsPerDay: Number(o.turnsPerDay) || 50, pricePerMTokUsd: Number(o.pricePerMtok) || 3, allowlistFingerprints: allow });
|
|
39872
40094
|
process.stdout.write("\n" + renderSetup(report));
|
|
39873
40095
|
if (o.policy) {
|
|
@@ -39883,7 +40105,7 @@ POLICY${policy.name ? ` (${sanitizeText(policy.name, 80)})` : ""}
|
|
|
39883
40105
|
writeFileSync5(o.out, JSON.stringify({ ...report, machine: o.machine ?? hostname() }, null, 2) + "\n");
|
|
39884
40106
|
});
|
|
39885
40107
|
program2.command("vc").description("W3C Verifiable Credentials made by saktum attest --vc").command("verify").description("Verify a Saktum credential (vc+jwt): signature and issuer did:key").argument("<file>", "the .vc.jwt file").action((f) => {
|
|
39886
|
-
const r = verifyCredentialJwt(
|
|
40108
|
+
const r = verifyCredentialJwt(readFileSync10(f, "utf8"));
|
|
39887
40109
|
if (r.valid) {
|
|
39888
40110
|
const cs = r.credential.credentialSubject ?? {};
|
|
39889
40111
|
process.stdout.write(`\u2713 Valid credential from ${r.issuer}: ${sanitizeText(String(cs.server ?? ""), 80)} trust ${cs.trustGrade ?? "-"}, readiness ${cs.readinessGrade ?? "-"}.
|
|
@@ -39928,8 +40150,8 @@ ${r.errors.slice(0, 10).map((e) => ` ${sanitizeText(e, 200)}`).join("\n")}
|
|
|
39928
40150
|
`);
|
|
39929
40151
|
});
|
|
39930
40152
|
ledger.command("append").description("Append a signed attestation to a ledger file after verifying it (used by the ledger bot)").argument("<input>", "attestation JSON, or a text file (such as an issue body) containing it").requiredOption("--ledger <file>", "ledger file to append to").option("--issue <n>", "issue number that requested it").action((input, o) => {
|
|
39931
|
-
const att = extractJson(
|
|
39932
|
-
const { text: text2, entry } = appendToLedger(existsSync7(o.ledger) ?
|
|
40153
|
+
const att = extractJson(readFileSync10(input, "utf8"));
|
|
40154
|
+
const { text: text2, entry } = appendToLedger(existsSync7(o.ledger) ? readFileSync10(o.ledger, "utf8") : "", att, { via: "saktum-index issue", ...o.issue ? { issue: Number(o.issue) } : {} });
|
|
39933
40155
|
writeFileSync5(o.ledger, text2);
|
|
39934
40156
|
process.stdout.write(`Recorded entry #${entry.seq} for ${sanitizeText(entry.subject.server, 80)} (signed by ${entry.signer}); entry hash ${entry.entryHash}.
|
|
39935
40157
|
`);
|
|
@@ -39976,7 +40198,7 @@ ${r.errors.slice(0, 10).map((e) => ` ${sanitizeText(e, 200)}`).join("\n")}
|
|
|
39976
40198
|
approveAbove: aa,
|
|
39977
40199
|
disclosures: { ...o.operator ? { operator: o.operator } : {}, ...o.incentives ? { incentives: o.incentives } : {}, ...o.dataUse ? { dataUse: o.dataUse } : {} },
|
|
39978
40200
|
delegation: o.allowDelegation,
|
|
39979
|
-
...o.intent ? JSON.parse(
|
|
40201
|
+
...o.intent ? JSON.parse(readFileSync10(o.intent, "utf8")) : {}
|
|
39980
40202
|
}, loadOrCreateKey(o.key));
|
|
39981
40203
|
if (o.software) {
|
|
39982
40204
|
const { signature: _old, ...body2 } = m;
|
|
@@ -39996,7 +40218,7 @@ Wrote ${sanitizeText(o.out)} and the agent key ${sanitizeText(o.agentKey)} (keep
|
|
|
39996
40218
|
`);
|
|
39997
40219
|
});
|
|
39998
40220
|
agent.command("verify").description("Check a mandate: the principal's signature, the operator's countersignature, expiry and revocation").argument("<mandate>", "mandate file").action((f) => {
|
|
39999
|
-
const m = JSON.parse(
|
|
40221
|
+
const m = JSON.parse(readFileSync10(f, "utf8"));
|
|
40000
40222
|
const c = checkMandate(m), op = checkOperator(m), rev = revocationOf(m);
|
|
40001
40223
|
process.stdout.write(c.ok ? `\u2713 Valid mandate for ${sanitizeText(m.agent.name, 80)} (${m.agent.id}), signed by ${m.owner.name ?? m.owner.id}, until ${m.expires}.
|
|
40002
40224
|
` : `\u2717 ${c.reason}
|
|
@@ -40011,7 +40233,7 @@ Wrote ${sanitizeText(o.out)} and the agent key ${sanitizeText(o.agentKey)} (keep
|
|
|
40011
40233
|
exitCode = c.ok && (!op.present || op.valid) && !rev ? 0 : 1;
|
|
40012
40234
|
});
|
|
40013
40235
|
agent.command("cosign").description("As the operator (who runs the agent and is accountable), countersign a principal's mandate").argument("<mandate>", "mandate file (updated in place)").requiredOption("--name <operator>", "the operator's name").option("--key <path>", "the operator's signing key (created if missing)", "saktum-operator-key.json").action((f, o) => {
|
|
40014
|
-
const m = JSON.parse(
|
|
40236
|
+
const m = JSON.parse(readFileSync10(f, "utf8"));
|
|
40015
40237
|
if (!checkMandate(m).ok)
|
|
40016
40238
|
throw new Error("The mandate is not valid; it cannot be countersigned.");
|
|
40017
40239
|
const signed = cosignMandate(m, loadOrCreateKey(o.key), o.name);
|
|
@@ -40020,23 +40242,23 @@ Wrote ${sanitizeText(o.out)} and the agent key ${sanitizeText(o.agentKey)} (keep
|
|
|
40020
40242
|
`);
|
|
40021
40243
|
});
|
|
40022
40244
|
agent.command("approve").description("As the mandate's owner, approve exactly one pending action (by its request id), for a limited time, once").argument("<request-id>", "the approval request id from the blocked call (apr_...)").requiredOption("--mandate <file>", "the mandate").option("--key <path>", "the owner's signing key (the one that signed the mandate)").option("--minutes <n>", "how long the approval stays valid", "60").option("--approvals <file>", "approvals file the proxy reads (default ~/.saktum/approvals.json)").action((rid, o) => {
|
|
40023
|
-
const m = JSON.parse(
|
|
40245
|
+
const m = JSON.parse(readFileSync10(o.mandate, "utf8"));
|
|
40024
40246
|
const a = approveAction(m, rid, loadOrCreateKey(o.key), Number(o.minutes), o.approvals);
|
|
40025
40247
|
process.stdout.write(`Approved ${sanitizeText(rid, 40)} for ${sanitizeText(m.agent.name, 80)}, valid until ${a.expires}, once. The agent can now retry exactly that action.
|
|
40026
40248
|
`);
|
|
40027
40249
|
});
|
|
40028
40250
|
agent.command("revoke").description("Stop an agent now: every Saktum proxy on this machine refuses calls under this mandate").argument("<mandate>", "mandate file").option("--reason <text>", "why").action((f, o) => {
|
|
40029
|
-
const m = JSON.parse(
|
|
40251
|
+
const m = JSON.parse(readFileSync10(f, "utf8"));
|
|
40030
40252
|
const r = revokeMandate(m, o.reason);
|
|
40031
40253
|
process.stdout.write(`Revoked the mandate for ${sanitizeText(m.agent.name, 80)} at ${r.at}. Its calls are now refused (code: revoked).
|
|
40032
40254
|
`);
|
|
40033
40255
|
});
|
|
40034
|
-
program2.command("proxy").description("Put Saktum between an agent and a local MCP server: signed receipts for every tool call, and the agent's mandate observed or enforced (preview)").argument("<command...>", "the server command, after --").option("--mandate <file>", "the agent's mandate (from saktum agent create)").option("--agent-key <file>", "the agent's key, which signs receipts", "agent-key.json").option("--enforce", "block calls outside the mandate (default: observe and record only)", false).option("--receipts <file>", "receipt log (append-only, hash-chained)").option("--revocations <file>", "revocation list to honour (default ~/.saktum/revocations.json)").option("--approvals <file>", "signed approvals to honour (default ~/.saktum/approvals.json)").option("--credential <file>", "the agent's credential: its accountability chain is verified on every call").option("--revoked-credentials <file>", "JSON list of revoked credential ids").option("--agreement <file>", "the signed agreement with the provider: calls outside it are refused and every call is metered").option("--wallet <file>", "prepaid token wallet charged per call under the agreement").action(async (parts, o) => {
|
|
40256
|
+
program2.command("proxy").description("Put Saktum between an agent and a local MCP server: signed receipts for every tool call, and the agent's mandate observed or enforced (preview)").argument("<command...>", "the server command, after --").option("--mandate <file>", "the agent's mandate (from saktum agent create)").option("--agent-key <file>", "the agent's key, which signs receipts", "agent-key.json").option("--enforce", "block calls outside the mandate (default: observe and record only)", false).option("--receipts <file>", "receipt log (append-only, hash-chained)").option("--revocations <file>", "revocation list to honour (default ~/.saktum/revocations.json)").option("--approvals <file>", "signed approvals to honour (default ~/.saktum/approvals.json)").option("--credential <file>", "the agent's credential: its accountability chain is verified on every call").option("--revoked-credentials <file>", "JSON list of revoked credential ids").option("--agreement <file>", "the signed agreement with the provider: calls outside it are refused and every call is metered").option("--wallet <file>", "prepaid token wallet charged per call under the agreement").option("--approval-webhook <url>", "post approval requests to this webhook (Slack, Teams or an email relay)").option("--approval-url <url>", "base link of saktum approvals serve, included in approval requests").option("--bindings <file>", "bindings override: JSON { tool: { action, bindings: { arg: field } } } for tools that declare nothing").action(async (parts, o) => {
|
|
40035
40257
|
const { homedir: homedir2 } = await import("node:os");
|
|
40036
|
-
const { join:
|
|
40258
|
+
const { join: join7 } = await import("node:path");
|
|
40037
40259
|
let mandate;
|
|
40038
40260
|
if (o.mandate) {
|
|
40039
|
-
mandate = JSON.parse(
|
|
40261
|
+
mandate = JSON.parse(readFileSync10(o.mandate, "utf8"));
|
|
40040
40262
|
const c = checkMandate(mandate);
|
|
40041
40263
|
if (!c.ok)
|
|
40042
40264
|
throw new Error(`Mandate refused: ${c.reason}`);
|
|
@@ -40048,16 +40270,19 @@ Wrote ${sanitizeText(o.out)} and the agent key ${sanitizeText(o.agentKey)} (keep
|
|
|
40048
40270
|
exitCode = await runProxy2({
|
|
40049
40271
|
command: parts[0],
|
|
40050
40272
|
args: parts.slice(1),
|
|
40051
|
-
receiptsPath: o.receipts ??
|
|
40273
|
+
receiptsPath: o.receipts ?? join7(homedir2(), ".saktum", "receipts.jsonl"),
|
|
40052
40274
|
agentKey,
|
|
40053
40275
|
mandate,
|
|
40054
40276
|
enforce: o.enforce,
|
|
40055
40277
|
...o.revocations ? { revocationsPath: o.revocations } : {},
|
|
40056
40278
|
...o.approvals ? { approvalsPath: o.approvals } : {},
|
|
40057
|
-
...o.credential ? { credential: JSON.parse(
|
|
40058
|
-
...o.revokedCredentials ? { revokedCredentials: JSON.parse(
|
|
40059
|
-
...o.agreement ? { agreement: JSON.parse(
|
|
40279
|
+
...o.credential ? { credential: JSON.parse(readFileSync10(o.credential, "utf8")) } : {},
|
|
40280
|
+
...o.revokedCredentials ? { revokedCredentials: JSON.parse(readFileSync10(o.revokedCredentials, "utf8")) } : {},
|
|
40281
|
+
...o.agreement ? { agreement: JSON.parse(readFileSync10(o.agreement, "utf8")) } : {},
|
|
40060
40282
|
...o.wallet ? { walletPath: o.wallet } : {},
|
|
40283
|
+
...o.approvalWebhook ? { approvalWebhook: o.approvalWebhook } : {},
|
|
40284
|
+
...o.approvalUrl ? { approvalUrl: o.approvalUrl } : {},
|
|
40285
|
+
...o.bindings ? { bindingsOverride: JSON.parse(readFileSync10(o.bindings, "utf8")) } : {},
|
|
40061
40286
|
log: (m) => process.stderr.write(`saktum: ${m}
|
|
40062
40287
|
`)
|
|
40063
40288
|
});
|
|
@@ -40065,8 +40290,8 @@ Wrote ${sanitizeText(o.out)} and the agent key ${sanitizeText(o.agentKey)} (keep
|
|
|
40065
40290
|
const receipts = program2.command("receipts").description("Signed receipts of agent tool calls (from saktum proxy)");
|
|
40066
40291
|
receipts.command("verify").description("Verify every receipt's signature and the hash chain").argument("[file]", "receipt log").action(async (f) => {
|
|
40067
40292
|
const { homedir: homedir2 } = await import("node:os");
|
|
40068
|
-
const { join:
|
|
40069
|
-
const r = verifyReceiptLog(parseReceiptLog(
|
|
40293
|
+
const { join: join7 } = await import("node:path");
|
|
40294
|
+
const r = verifyReceiptLog(parseReceiptLog(readFileSync10(f ?? join7(homedir2(), ".saktum", "receipts.jsonl"), "utf8")));
|
|
40070
40295
|
process.stdout.write(r.ok ? `\u2713 ${r.count} receipts verified: every signature valid, chain intact.
|
|
40071
40296
|
` : `\u2717 Receipts do NOT verify:
|
|
40072
40297
|
${r.errors.slice(0, 10).map((e) => ` ${e}`).join("\n")}
|
|
@@ -40075,8 +40300,8 @@ ${r.errors.slice(0, 10).map((e) => ` ${e}`).join("\n")}
|
|
|
40075
40300
|
});
|
|
40076
40301
|
receipts.command("export").description("Export receipts as OpenTelemetry traces (OTLP/JSON) for your observability or security tools").argument("[file]", "receipt log").option("--otel <file>", "write OTLP/JSON traces to this file", "saktum-receipts.otlp.json").option("--endpoint <url>", "also send them to an OpenTelemetry collector (OTLP/HTTP), for example http://localhost:4318").action(async (f, o) => {
|
|
40077
40302
|
const { homedir: homedir2 } = await import("node:os");
|
|
40078
|
-
const { join:
|
|
40079
|
-
const entries = parseReceiptLog(
|
|
40303
|
+
const { join: join7 } = await import("node:path");
|
|
40304
|
+
const entries = parseReceiptLog(readFileSync10(f ?? join7(homedir2(), ".saktum", "receipts.jsonl"), "utf8"));
|
|
40080
40305
|
const v = verifyReceiptLog(entries);
|
|
40081
40306
|
const otlp = receiptsToOtlp(entries, { verified: v.ok, version: ENGINE_VERSION });
|
|
40082
40307
|
writeFileSync5(o.otel, JSON.stringify(otlp, null, 2) + "\n");
|
|
@@ -40091,10 +40316,20 @@ ${r.errors.slice(0, 10).map((e) => ` ${e}`).join("\n")}
|
|
|
40091
40316
|
exitCode = 1;
|
|
40092
40317
|
}
|
|
40093
40318
|
});
|
|
40319
|
+
receipts.command("view").description("One verified view across many agents' receipt logs (for example collected in a shared folder)").argument("<files...>", "receipt logs").option("--html <file>", "output", "saktum-receipts.html").action((fs3, o) => {
|
|
40320
|
+
const logs = fs3.map((f) => {
|
|
40321
|
+
const e = parseReceiptLog(readFileSync10(f, "utf8"));
|
|
40322
|
+
return { name: f, verified: verifyReceiptLog(e).ok, entries: e.map((x) => ({ at: x.receipt.issuedAt, agent: x.receipt.envelope.caller.agent?.slice(0, 24) ?? "", tool: x.receipt.envelope.tool, outcome: x.receipt.outcome, code: x.result.code ?? "", reason: String(x.receipt.reason ?? ""), tokens: x.result.metering?.tokens ?? 0 })) };
|
|
40323
|
+
});
|
|
40324
|
+
writeFileSync5(o.html, renderReceiptsView(logs));
|
|
40325
|
+
process.stdout.write(`Combined ${logs.reduce((n, l) => n + l.entries.length, 0)} receipts from ${logs.length} log(s) into ${sanitizeText(o.html)}; ${logs.filter((l) => !l.verified).length} log(s) failed verification.
|
|
40326
|
+
`);
|
|
40327
|
+
exitCode = logs.every((l) => l.verified) ? 0 : 1;
|
|
40328
|
+
});
|
|
40094
40329
|
receipts.command("summary").description("The path, not the answer: which tools were called, how often, in what order, retries, denials, destructive actions").argument("[file]", "receipt log").option("--json", "print JSON", false).action(async (f, o) => {
|
|
40095
40330
|
const { homedir: homedir2 } = await import("node:os");
|
|
40096
|
-
const { join:
|
|
40097
|
-
const entries = parseReceiptLog(
|
|
40331
|
+
const { join: join7 } = await import("node:path");
|
|
40332
|
+
const entries = parseReceiptLog(readFileSync10(f ?? join7(homedir2(), ".saktum", "receipts.jsonl"), "utf8"));
|
|
40098
40333
|
const v = verifyReceiptLog(entries), s = summariseReceipts(entries);
|
|
40099
40334
|
if (o.json) {
|
|
40100
40335
|
process.stdout.write(JSON.stringify({ verified: v.ok, ...s }, null, 2) + "\n");
|
|
@@ -40108,11 +40343,11 @@ ${r.errors.slice(0, 10).map((e) => ` ${e}`).join("\n")}
|
|
|
40108
40343
|
});
|
|
40109
40344
|
program2.command("passport").description("A visual passport: for an MCP server (checks it first) or, with --agent, for an agent (mandate and receipt timeline)").argument("[target...]", "the server: https URL, or -- <command that starts it>").option("--agent <mandate>", "make an Agent Passport from this mandate instead").option("--receipts <file>", "with --agent: the agent's receipt log, for the timeline").option("--out <file>", "HTML file", "saktum-passport.html").option("--key <path>", "signing key for the server's result").option("--env <KEY=VALUE>", "environment variable for a local server (repeatable)", collect, []).option("--header <Name: value>", "HTTP header for a remote server (repeatable)", collect, []).action(async (parts, o) => {
|
|
40110
40345
|
if (o.agent) {
|
|
40111
|
-
const m = JSON.parse(
|
|
40346
|
+
const m = JSON.parse(readFileSync10(o.agent, "utf8"));
|
|
40112
40347
|
const valid = checkMandate(m);
|
|
40113
40348
|
let receipts2;
|
|
40114
40349
|
if (o.receipts) {
|
|
40115
|
-
const entries = parseReceiptLog(
|
|
40350
|
+
const entries = parseReceiptLog(readFileSync10(o.receipts, "utf8"));
|
|
40116
40351
|
const counts = /* @__PURE__ */ new Map();
|
|
40117
40352
|
for (const e of entries) {
|
|
40118
40353
|
const k = `${e.receipt.envelope.tool}|${e.receipt.envelope.argumentsHash}`;
|
|
@@ -40125,11 +40360,11 @@ ${r.errors.slice(0, 10).map((e) => ` ${e}`).join("\n")}
|
|
|
40125
40360
|
};
|
|
40126
40361
|
}
|
|
40127
40362
|
const rev = revocationOf(m), op = checkOperator(m);
|
|
40128
|
-
const ts = o.receipts ? trustStatement(parseReceiptLog(
|
|
40363
|
+
const ts = o.receipts ? trustStatement(parseReceiptLog(readFileSync10(o.receipts, "utf8")), receipts2?.verified ?? false) : void 0;
|
|
40129
40364
|
writeFileSync5(o.out, renderAgentPassport(m, rev ? { ok: false, reason: `Revoked on ${rev.at.slice(0, 10)}${rev.reason ? `: ${rev.reason}` : ""}` } : valid.ok ? { ok: true } : { ok: false, reason: valid.reason }, receipts2, agentRiskTier(m), describeMandate(m), {
|
|
40130
40365
|
operator: op.present && op.valid ? `${op.name} (${op.id})` : void 0,
|
|
40131
40366
|
track: ts?.lines,
|
|
40132
|
-
maturity: agentMaturity(m, { entries: o.receipts ? parseReceiptLog(
|
|
40367
|
+
maturity: agentMaturity(m, { entries: o.receipts ? parseReceiptLog(readFileSync10(o.receipts, "utf8")) : [], verified: receipts2?.verified, revoked: Boolean(rev) })
|
|
40133
40368
|
}));
|
|
40134
40369
|
process.stdout.write(`Wrote the Agent Passport for ${sanitizeText(m.agent.name, 80)} to ${sanitizeText(o.out)}. Open it in a browser.
|
|
40135
40370
|
`);
|
|
@@ -40154,7 +40389,7 @@ ${r.errors.slice(0, 10).map((e) => ` ${e}`).join("\n")}
|
|
|
40154
40389
|
`);
|
|
40155
40390
|
});
|
|
40156
40391
|
program2.command("watch").description("Continuous monitoring: re-check every server on an allowlist and alert on changed tools, grade drops or unreachable servers").argument("<allowlist>", "saktum-allowlist.json (from saktum allowlist)").option("--out <file>", "write the results as JSON").option("--webhook <url>", "POST a summary to this URL when something changed (for example a chat or incident webhook)").action(async (file, o) => {
|
|
40157
|
-
const list = JSON.parse(
|
|
40392
|
+
const list = JSON.parse(readFileSync10(file, "utf8"));
|
|
40158
40393
|
const packs = existsSync7(bundledPacks) ? loadPackDir(bundledPacks) : loadEmbeddedPacks();
|
|
40159
40394
|
const r = await watchAllowlist(list.allowed ?? [], packs);
|
|
40160
40395
|
const mark2 = { unchanged: "\u2713", changed: "\u2717", degraded: "!", unreachable: "?" };
|
|
@@ -40189,21 +40424,21 @@ Total: about ${usd(r.totalSavings)} a year.
|
|
|
40189
40424
|
Assumptions: ${r.assumptions}.
|
|
40190
40425
|
`);
|
|
40191
40426
|
});
|
|
40192
|
-
program2.command("assess").description("An executive MCP Trust Assessment for an organisation, from a fleet inventory and agent receipts (pilot deliverable)").requiredOption("--fleet <file>", "inventory JSON from saktum fleet --out").option("--org <name>", "organisation name", "Your organisation").option("--receipts <file>", "an agent's receipt log (repeatable)", collect, []).option("--out <file>", "HTML report (print to PDF from a browser)", "saktum-assessment.html").option("--agents <n>", "agents in production, for the business case", "10").option("--turns-per-day <n>", "turns a day per agent", "1000").option("--price-per-mtok <usd>", "price per million input tokens", "3").option("--vendor-reviews <n>", "AI vendor or tool security reviews a year", "20").action((o) => {
|
|
40193
|
-
const fleet = JSON.parse(
|
|
40427
|
+
program2.command("assess").description("An executive MCP Trust Assessment for an organisation, from a fleet inventory and agent receipts (pilot deliverable)").requiredOption("--fleet <file>", "inventory JSON from saktum fleet --out").option("--org <name>", "organisation name", "Your organisation").option("--receipts <file>", "an agent's receipt log (repeatable)", collect, []).option("--out <file>", "HTML report (print to PDF from a browser)", "saktum-assessment.html").option("--agents <n>", "agents in production, for the business case", "10").option("--turns-per-day <n>", "turns a day per agent", "1000").option("--price-per-mtok <usd>", "price per million input tokens", "3").option("--vendor-reviews <n>", "AI vendor or tool security reviews a year", "20").option("--agents-inventory <file>", "agent inventory from saktum agents scan --out").action((o) => {
|
|
40428
|
+
const fleet = JSON.parse(readFileSync10(o.fleet, "utf8"));
|
|
40194
40429
|
const rec = o.receipts.map((f) => {
|
|
40195
|
-
const e = parseReceiptLog(
|
|
40430
|
+
const e = parseReceiptLog(readFileSync10(f, "utf8"));
|
|
40196
40431
|
return { agent: e[0]?.receipt.envelope.caller.agent?.slice(0, 32) ?? f, summary: summariseReceipts(e), verified: verifyReceiptLog(e).ok };
|
|
40197
40432
|
});
|
|
40198
40433
|
const distinctTokens = (fleet.servers ?? []).reduce((a, x) => a + (x.tokens ?? 0), 0);
|
|
40199
40434
|
const roi = roiEstimate({ ...ROI_DEFAULTS, tokensPerTurn: distinctTokens, agents: Number(o.agents), turnsPerDay: Number(o.turnsPerDay), pricePerMTok: Number(o.pricePerMtok), vendorReviews: Number(o.vendorReviews) });
|
|
40200
|
-
writeFileSync5(o.out, renderAssessment(o.org, fleet, rec, roi, crosswalk().map((x) => ({ name: x.name, summary: coverageSummary(x) })), DISCLAIMER));
|
|
40435
|
+
writeFileSync5(o.out, renderAssessment(o.org, fleet, rec, roi, crosswalk().map((x) => ({ name: x.name, summary: coverageSummary(x) })), DISCLAIMER, o.agentsInventory ? JSON.parse(readFileSync10(o.agentsInventory, "utf8")) : void 0));
|
|
40201
40436
|
process.stdout.write(`Wrote the MCP Trust Assessment for ${sanitizeText(o.org, 80)} to ${sanitizeText(o.out)}: ${fleet.servers?.length ?? 0} servers, ${fleet.nonCompliant ?? 0} violating policy. Open it in a browser and print to PDF.
|
|
40202
40437
|
`);
|
|
40203
40438
|
});
|
|
40204
40439
|
program2.command("fleet").description("Merge scan-config results from many machines into one organisation inventory, checked against your policy").argument("<setups...>", "JSON files written by saktum scan-config --out").option("--policy <file>", "your organisation's policy").option("--out <file>", "inventory as JSON").option("--html <file>", "inventory as an HTML page").action(async (files, o) => {
|
|
40205
40440
|
const setups = files.map((f) => {
|
|
40206
|
-
const j = JSON.parse(
|
|
40441
|
+
const j = JSON.parse(readFileSync10(f, "utf8"));
|
|
40207
40442
|
return { machine: j.machine ?? f, servers: j.servers ?? [] };
|
|
40208
40443
|
});
|
|
40209
40444
|
const pol = o.policy ? await loadPolicy(o.policy) : void 0;
|
|
@@ -40253,20 +40488,20 @@ To declare them, add to each tool's definition (MCP tools accept _meta):
|
|
|
40253
40488
|
const subject = o.subject ?? (o.subjectKey ? loadOrCreateKey(o.subjectKey).kid : void 0);
|
|
40254
40489
|
if (!subject)
|
|
40255
40490
|
throw new Error("Give --subject <did:key> or --subject-key <file>.");
|
|
40256
|
-
const c = issueCredential(JSON.parse(
|
|
40491
|
+
const c = issueCredential(JSON.parse(readFileSync10(o.from, "utf8")), loadOrCreateKey(o.key), { type: o.type, id: subject, name: o.name, role: o.role, expires: o.expires });
|
|
40257
40492
|
writeFileSync5(o.out, JSON.stringify(c, null, 2) + "\n");
|
|
40258
40493
|
process.stdout.write(`Issued ${c.id} to ${sanitizeText(o.name, 80)} (${o.type}). Chain: ${verifyChain(c).path.join(" -> ")}
|
|
40259
40494
|
`);
|
|
40260
40495
|
});
|
|
40261
40496
|
identity.command("verify").description("Walk a credential's chain to its organisation").argument("<credential>").option("--revoked <file>", "JSON list of revoked credential ids").action((f, o) => {
|
|
40262
|
-
const v = verifyChain(JSON.parse(
|
|
40497
|
+
const v = verifyChain(JSON.parse(readFileSync10(f, "utf8")), { revoked: o.revoked ? JSON.parse(readFileSync10(o.revoked, "utf8")) : [] });
|
|
40263
40498
|
process.stdout.write(v.valid ? `\u2713 ${v.path.join(" -> ")}: accountable organisation ${v.organisation}
|
|
40264
40499
|
` : `\u2717 ${v.reason}
|
|
40265
40500
|
`);
|
|
40266
40501
|
exitCode = v.valid ? 0 : 1;
|
|
40267
40502
|
});
|
|
40268
40503
|
identity.command("orphans").description("Agents whose accountability chain is broken (expired, revoked or invalid)").argument("<credentials...>").option("--revoked <file>", "JSON list of revoked credential ids").action((fs, o) => {
|
|
40269
|
-
const orphans = findOrphans(fs.map((f) => JSON.parse(
|
|
40504
|
+
const orphans = findOrphans(fs.map((f) => JSON.parse(readFileSync10(f, "utf8"))), { revoked: o.revoked ? JSON.parse(readFileSync10(o.revoked, "utf8")) : [] });
|
|
40270
40505
|
for (const x of orphans)
|
|
40271
40506
|
process.stdout.write(`\u2717 ${sanitizeText(x.agent, 80)} (${x.id}): ${x.reason}
|
|
40272
40507
|
`);
|
|
@@ -40299,16 +40534,16 @@ To declare them, add to each tool's definition (MCP tools accept _meta):
|
|
|
40299
40534
|
});
|
|
40300
40535
|
const catalog = program2.command("catalog").description("A catalogue of signed manifests, searchable by intent");
|
|
40301
40536
|
catalog.command("add").argument("<manifest>").option("--catalog <file>", "catalogue file", "saktum-catalog.json").action((f, o) => {
|
|
40302
|
-
const m = JSON.parse(
|
|
40537
|
+
const m = JSON.parse(readFileSync10(f, "utf8"));
|
|
40303
40538
|
if (!verifyDocument(m).valid)
|
|
40304
40539
|
throw new Error("The manifest's signature is not valid.");
|
|
40305
|
-
const c = existsSync7(o.catalog) ? JSON.parse(
|
|
40540
|
+
const c = existsSync7(o.catalog) ? JSON.parse(readFileSync10(o.catalog, "utf8")) : [];
|
|
40306
40541
|
writeFileSync5(o.catalog, JSON.stringify([...c.filter((x) => x.server.name !== m.server.name || x.publisher.id !== m.publisher.id), m], null, 2) + "\n");
|
|
40307
40542
|
process.stdout.write(`Added ${sanitizeText(m.server.name, 80)} by ${sanitizeText(m.publisher.name, 80)} to ${sanitizeText(o.catalog)}.
|
|
40308
40543
|
`);
|
|
40309
40544
|
});
|
|
40310
40545
|
catalog.command("search").argument("<query...>").option("--catalog <file>", "catalogue file", "saktum-catalog.json").option("--max-risk <tier>", "only servers at or below this risk tier").action((q, o) => {
|
|
40311
|
-
const res = searchCatalogue(JSON.parse(
|
|
40546
|
+
const res = searchCatalogue(JSON.parse(readFileSync10(o.catalog, "utf8")), q.join(" "), { maxRisk: o.maxRisk });
|
|
40312
40547
|
for (const r of res.slice(0, 10))
|
|
40313
40548
|
process.stdout.write(`${String(r.score).padStart(3)} ${sanitizeText(r.manifest.server.name, 40).padEnd(24)} ${sanitizeText(r.manifest.publisher.name, 40).padEnd(20)} trust ${r.manifest.quality?.trustGrade ?? "-"} \xB7 risk ${r.manifest.quality?.riskTier ?? "-"} \xB7 ${r.matched.join(", ")}
|
|
40314
40549
|
`);
|
|
@@ -40317,19 +40552,19 @@ To declare them, add to each tool's definition (MCP tools accept _meta):
|
|
|
40317
40552
|
});
|
|
40318
40553
|
const agreement = program2.command("agreement").description("Agreements between providers and invokers (smart contracts as signed documents)");
|
|
40319
40554
|
agreement.command("draft").description("As the provider, draft and sign an agreement from the default template").requiredOption("--manifest <file>").requiredOption("--invoker-name <name>").requiredOption("--invoker <did>", "the invoker organisation's id").requiredOption("--purpose <text>").option("--tools <list>", "comma-separated tools in scope").option("--tokens-per-month <n>").option("--term <text>", "a specific term (repeatable)", collect, []).option("--valid-until <date>", "YYYY-MM-DD", new Date(Date.now() + 365 * 864e5).toISOString().slice(0, 10)).option("--key <path>", "the provider's key", "saktum-publisher-key.json").option("--out <file>", "agreement file", "saktum-agreement.json").action((o) => {
|
|
40320
|
-
const a = draftAgreement({ manifest: JSON.parse(
|
|
40555
|
+
const a = draftAgreement({ manifest: JSON.parse(readFileSync10(o.manifest, "utf8")), invoker: { id: o.invoker, name: o.invokerName }, purpose: o.purpose, tools: o.tools?.split(",").map((x) => x.trim()), tokensPerMonth: o.tokensPerMonth ? Number(o.tokensPerMonth) : void 0, specificTerms: o.term, validUntil: o.validUntil }, loadOrCreateKey(o.key));
|
|
40321
40556
|
writeFileSync5(o.out, JSON.stringify(a, null, 2) + "\n");
|
|
40322
40557
|
process.stdout.write(`Drafted ${a.id} (${a.terms.length} default terms, ${a.specificTerms?.length ?? 0} specific), signed by the provider. The invoker accepts with: npx saktum agreement accept ${sanitizeText(o.out)} --key <invoker-key>
|
|
40323
40558
|
`);
|
|
40324
40559
|
});
|
|
40325
40560
|
agreement.command("accept").argument("<agreement>").requiredOption("--key <path>", "the invoker's key").action((f, o) => {
|
|
40326
|
-
const a = acceptAgreement(JSON.parse(
|
|
40561
|
+
const a = acceptAgreement(JSON.parse(readFileSync10(f, "utf8")), loadOrCreateKey(o.key));
|
|
40327
40562
|
writeFileSync5(f, JSON.stringify(a, null, 2) + "\n");
|
|
40328
40563
|
process.stdout.write(`Accepted ${a.id}: signed by both parties.
|
|
40329
40564
|
`);
|
|
40330
40565
|
});
|
|
40331
40566
|
agreement.command("verify").argument("<agreement>").action((f) => {
|
|
40332
|
-
const a = JSON.parse(
|
|
40567
|
+
const a = JSON.parse(readFileSync10(f, "utf8"));
|
|
40333
40568
|
const v = verifyAgreement(a);
|
|
40334
40569
|
process.stdout.write(v.valid ? `\u2713 ${a.id}: ${sanitizeText(a.provider.name, 80)} and ${sanitizeText(a.invoker.name, 80)}, until ${a.validUntil}.
|
|
40335
40570
|
` : `\u2717 ${v.reason}
|
|
@@ -40347,8 +40582,8 @@ To declare them, add to each tool's definition (MCP tools accept _meta):
|
|
|
40347
40582
|
});
|
|
40348
40583
|
program2.command("usage").description("A usage statement for an agreement, from the receipts (optionally signed)").requiredOption("--agreement <file>").argument("[receipts]").option("--key <path>", "sign the statement with this key").option("--out <file>").action(async (f, o) => {
|
|
40349
40584
|
const { homedir: homedir2 } = await import("node:os");
|
|
40350
|
-
const { join:
|
|
40351
|
-
const st = usageStatement(parseReceiptLog(
|
|
40585
|
+
const { join: join7 } = await import("node:path");
|
|
40586
|
+
const st = usageStatement(parseReceiptLog(readFileSync10(f ?? join7(homedir2(), ".saktum", "receipts.jsonl"), "utf8")), JSON.parse(readFileSync10(o.agreement, "utf8")), o.key ? loadOrCreateKey(o.key) : void 0);
|
|
40352
40587
|
for (const l of st.lines)
|
|
40353
40588
|
process.stdout.write(`${sanitizeText(l.tool, 60).padEnd(24)} ${String(l.calls).padStart(5)} calls ${String(l.tokens).padStart(7)} tokens
|
|
40354
40589
|
`);
|
|
@@ -40359,8 +40594,8 @@ To declare them, add to each tool's definition (MCP tools accept _meta):
|
|
|
40359
40594
|
});
|
|
40360
40595
|
program2.command("kpi").description("KPIs over receipts: calls, outcomes, approvals, tokens, latency, by tool").argument("[receipts]").option("--tool <name>").option("--agent <did>").option("--since <date>").action(async (f, o) => {
|
|
40361
40596
|
const { homedir: homedir2 } = await import("node:os");
|
|
40362
|
-
const { join:
|
|
40363
|
-
const k = kpis(parseReceiptLog(
|
|
40597
|
+
const { join: join7 } = await import("node:path");
|
|
40598
|
+
const k = kpis(parseReceiptLog(readFileSync10(f ?? join7(homedir2(), ".saktum", "receipts.jsonl"), "utf8")), o);
|
|
40364
40599
|
process.stdout.write(`Calls ${k.calls} \xB7 allowed ${k.allowed} \xB7 blocked ${k.blocked} \xB7 approved ${k.approvals} \xB7 tokens ${k.tokens} \xB7 latency p50 ${k.latencyP50 ?? "-"} ms, p95 ${k.latencyP95 ?? "-"} ms
|
|
40365
40600
|
`);
|
|
40366
40601
|
process.stdout.write(`By outcome: ${k.byOutcome.map(([c, n]) => `${c} ${n}`).join(", ")}
|
|
@@ -40368,7 +40603,7 @@ By tool: ${k.byTool.map(([c, n]) => `${c} ${n}`).join(", ")}
|
|
|
40368
40603
|
`);
|
|
40369
40604
|
});
|
|
40370
40605
|
program2.command("bounty").description("Bounties (contract only for now)").command("validate").argument("<file>").action((f) => {
|
|
40371
|
-
const ok = compileContract("bounty.schema.json")(JSON.parse(
|
|
40606
|
+
const ok = compileContract("bounty.schema.json")(JSON.parse(readFileSync10(f, "utf8")));
|
|
40372
40607
|
process.stdout.write(ok ? "\u2713 Valid bounty document.\n" : "\u2717 Not a valid bounty document.\n");
|
|
40373
40608
|
exitCode = ok ? 0 : 1;
|
|
40374
40609
|
});
|
|
@@ -40406,6 +40641,80 @@ ${" ".repeat(36)}${i.evidence}${i.commands.length ? ` (${i.commands.join("; ")})
|
|
|
40406
40641
|
${DISCLAIMER}
|
|
40407
40642
|
`);
|
|
40408
40643
|
});
|
|
40644
|
+
program2.command("bridge").description("Present a remote MCP server (Streamable HTTP) as a local one, so saktum proxy can govern it: saktum proxy ... -- saktum bridge https://host/mcp").argument("<url>", "the remote server's URL").option("--header <Name: value>", "HTTP header to send, for example Authorization (repeatable; never logged)", collect, []).action(async (url2, o) => {
|
|
40645
|
+
if (!/^https?:\/\//.test(url2))
|
|
40646
|
+
throw new Error("Give the remote server's http(s) URL.");
|
|
40647
|
+
const { runBridge: runBridge2 } = await Promise.resolve().then(() => (init_bridge(), bridge_exports));
|
|
40648
|
+
exitCode = await runBridge2(url2, parseHeaders(o.header));
|
|
40649
|
+
});
|
|
40650
|
+
const approvals = program2.command("approvals").description("Approvals by link (v0.10)");
|
|
40651
|
+
approvals.command("list").option("--approvals <file>", "approvals file").action((o) => {
|
|
40652
|
+
const p = listPending(o.approvals);
|
|
40653
|
+
for (const x of p)
|
|
40654
|
+
process.stdout.write(`${x.id} ${sanitizeText(x.agent, 40)} ${sanitizeText(x.tool, 40)} ${sanitizeText(x.reason, 160)} (${x.at.slice(0, 16).replace("T", " ")})
|
|
40655
|
+
`);
|
|
40656
|
+
process.stdout.write(`${p.length} waiting.
|
|
40657
|
+
`);
|
|
40658
|
+
});
|
|
40659
|
+
approvals.command("serve").description("A local page where the mandate's owner approves exactly one pending action with their key").requiredOption("--mandate <file>").option("--key <path>", "the owner's key (file, env:VAR or keychain:NAME)").option("--approvals <file>", "approvals file shared with the proxy").option("--port <n>", "port", "8787").option("--host <host>", "interface to listen on", "127.0.0.1").option("--minutes <n>", "approval validity", "60").action(async (o) => {
|
|
40660
|
+
const http = await import("node:http");
|
|
40661
|
+
const { randomBytes } = await import("node:crypto");
|
|
40662
|
+
const m = JSON.parse(readFileSync10(o.mandate, "utf8"));
|
|
40663
|
+
const key = loadOrCreateKey(o.key);
|
|
40664
|
+
const token = randomBytes(16).toString("hex");
|
|
40665
|
+
if (key.kid !== m.owner.id)
|
|
40666
|
+
throw new Error("This key is not the mandate owner's key.");
|
|
40667
|
+
const esc22 = (x) => String(x).replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
40668
|
+
const pageOf = (body2) => `<!doctype html><meta name="viewport" content="width=device-width, initial-scale=1"><title>Saktum approvals</title><body style="font:15px system-ui;max-width:760px;margin:24px auto;padding:0 16px"><h1>Approvals for ${esc22(m.agent.name)}</h1>${body2}</body>`;
|
|
40669
|
+
const server = http.createServer((req, res) => {
|
|
40670
|
+
const u = new URL(req.url ?? "/", `http://${req.headers.host}`);
|
|
40671
|
+
if (u.searchParams.get("token") !== token) {
|
|
40672
|
+
res.writeHead(403);
|
|
40673
|
+
res.end("Forbidden");
|
|
40674
|
+
return;
|
|
40675
|
+
}
|
|
40676
|
+
if (req.method === "POST") {
|
|
40677
|
+
let b = "";
|
|
40678
|
+
req.on("data", (c) => {
|
|
40679
|
+
b += c;
|
|
40680
|
+
if (b.length > 2e3)
|
|
40681
|
+
req.destroy();
|
|
40682
|
+
});
|
|
40683
|
+
req.on("end", () => {
|
|
40684
|
+
const id = new URLSearchParams(b).get("id") ?? "";
|
|
40685
|
+
if (!listPending(o.approvals).some((p2) => p2.id === id)) {
|
|
40686
|
+
res.writeHead(400, { "Content-Type": "text/html" });
|
|
40687
|
+
res.end(pageOf(`<p>No pending request ${esc22(id)}.</p>`));
|
|
40688
|
+
return;
|
|
40689
|
+
}
|
|
40690
|
+
approveAction(m, id, key, Number(o.minutes), o.approvals);
|
|
40691
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
40692
|
+
res.end(pageOf(`<p>\u2713 Approved <code>${esc22(id)}</code>, once, for ${esc22(o.minutes)} minutes. The agent can retry exactly that action.</p><p><a href="/?token=${token}">Back</a></p>`));
|
|
40693
|
+
});
|
|
40694
|
+
return;
|
|
40695
|
+
}
|
|
40696
|
+
const only = u.searchParams.get("id");
|
|
40697
|
+
const p = listPending(o.approvals).filter((x) => !only || x.id === only);
|
|
40698
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
40699
|
+
res.end(pageOf(p.length ? p.map((x) => `<form method="post" action="/?token=${token}" style="border:1px solid #ddd;border-radius:12px;padding:12px;margin:10px 0"><b>${esc22(x.tool)}</b> <code>${esc22(x.id)}</code><p>${esc22(x.reason)}</p><small>${esc22(x.at)}</small><input type="hidden" name="id" value="${esc22(x.id)}"><p><button type="submit">Approve exactly this action, once</button></p></form>`).join("") : "<p>Nothing is waiting for approval.</p>"));
|
|
40700
|
+
});
|
|
40701
|
+
server.listen(Number(o.port), o.host, () => process.stdout.write(`Approvals page: http://${o.host}:${o.port}/?token=${token}
|
|
40702
|
+
Give the proxy --approval-url "http://${o.host}:${o.port}/?token=${token}" so requests carry a one-click link. Ctrl+C to stop.
|
|
40703
|
+
`));
|
|
40704
|
+
await new Promise(() => void 0);
|
|
40705
|
+
});
|
|
40706
|
+
program2.command("agents").description("Agent inventory (v0.10)").command("scan").argument("[dirs...]", "folders to search for agent mandates (default: this folder and ~/.saktum)").option("--out <file>", "write the inventory as JSON (for saktum assess --agents)").action(async (dirs, o) => {
|
|
40707
|
+
const { homedir: homedir2 } = await import("node:os");
|
|
40708
|
+
const { join: join7 } = await import("node:path");
|
|
40709
|
+
const a = scanAgents(dirs.length ? dirs : [".", join7(homedir2(), ".saktum")]);
|
|
40710
|
+
for (const x of a)
|
|
40711
|
+
process.stdout.write(`${x.revoked ? "\u26D4" : x.valid ? "\u2713" : "\u2717"} ${sanitizeText(x.name, 40).padEnd(26)} owner ${sanitizeText(x.owner, 30).padEnd(16)} ${x.operator ? "operator " + sanitizeText(x.operator, 30) : "no operator"} \xB7 ${x.autonomy} \xB7 ${x.riskTier} \xB7 ${x.maturity}
|
|
40712
|
+
`);
|
|
40713
|
+
process.stdout.write(`${a.length} agent(s); ${a.filter((x) => !x.operator).length} without an operator countersignature; ${a.filter((x) => x.revoked).length} revoked.
|
|
40714
|
+
`);
|
|
40715
|
+
if (o.out)
|
|
40716
|
+
writeFileSync5(o.out, JSON.stringify(a, null, 2) + "\n");
|
|
40717
|
+
});
|
|
40409
40718
|
program2.command("demo").description("See permissions, autonomy, risk and receipts in 60 seconds: one shopping agent under three mandates").option("--out <dir>", "folder for the demo's mandates, receipts and passports", "saktum-demo").option("--story <name>", "grocery, travel, finance, coding, marketplace, autonomy, or all (grocery, travel, finance, coding and marketplace)", "all").action(async (o) => {
|
|
40410
40719
|
const { runDemo: runDemo2 } = await Promise.resolve().then(() => (init_demo(), demo_exports));
|
|
40411
40720
|
await runDemo2(o.out, (l) => process.stdout.write(l + "\n"), o.story);
|
|
@@ -40420,7 +40729,7 @@ ${DISCLAIMER}
|
|
|
40420
40729
|
await startMcpServer2(packs);
|
|
40421
40730
|
});
|
|
40422
40731
|
program2.command("attest").description("Turn a signed result into a compact signed attestation for your README or registry listing").argument("<result>", "a signed result (saktum-report.json)").option("--out <file>", "attestation file", "saktum-attestation.json").option("--key <path>", "signing key file").option("--publish", "also print a link that publishes it to the public Saktum trust ledger (a pre-filled GitHub issue)", false).option("--vc", "also write it as a W3C Verifiable Credential (vc+jwt, issued by your did:key)", false).action((file, o) => {
|
|
40423
|
-
const doc = JSON.parse(
|
|
40732
|
+
const doc = JSON.parse(readFileSync10(file, "utf8"));
|
|
40424
40733
|
const v = verifyDocument(doc);
|
|
40425
40734
|
if (!v.valid)
|
|
40426
40735
|
throw new Error(`The result's signature is not valid (${v.reason}); attestations are built only from unaltered signed results.`);
|
|
@@ -40463,7 +40772,7 @@ ${url2}
|
|
|
40463
40772
|
exitCode = r.code;
|
|
40464
40773
|
});
|
|
40465
40774
|
program2.command("verify").description("Verify a signed Saktum Check result").argument("<file>").action((file) => {
|
|
40466
|
-
const doc = JSON.parse(
|
|
40775
|
+
const doc = JSON.parse(readFileSync10(file, "utf8"));
|
|
40467
40776
|
const validate2 = compileContract("result.schema.json");
|
|
40468
40777
|
if (!validate2(doc)) {
|
|
40469
40778
|
process.stdout.write(`Invalid result format: ${JSON.stringify(validate2.errors?.slice(0, 2))}
|