@clagentic/console 1.10.0-beta.3 → 1.10.0-beta.4
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/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +29 -0
- package/lib/daemon.js +5 -9
- package/lib/grant-keys.js +24 -137
- package/lib/identity/config.js +118 -0
- package/lib/identity/contract.js +61 -0
- package/lib/identity/delivery.js +224 -0
- package/lib/identity/holder.js +87 -0
- package/lib/identity/index.js +229 -0
- package/lib/identity/jose.js +13 -0
- package/lib/identity/origin.js +28 -0
- package/lib/identity/owner.js +30 -0
- package/lib/identity/providers/gatekeeper.js +91 -0
- package/lib/identity/providers/jwks-self.js +85 -0
- package/lib/identity/providers/module.js +98 -0
- package/lib/identity/providers/signing-key.js +118 -0
- package/lib/identity/record.js +23 -0
- package/lib/identity/unavailable.js +29 -0
- package/lib/project-notifications.js +2 -3
- package/lib/prompt-kinds/permission.js +0 -18
- package/lib/prompt-registry.js +5 -13
- package/lib/public/css/notifications-center.css +2 -8
- package/lib/public/css/rewind.css +0 -1
- package/lib/public/modules/app-notifications.js +4 -7
- package/lib/public/modules/build-notice-gate.js +73 -0
- package/lib/public/modules/diagnostics.js +43 -1
- package/lib/public/modules/prompt-banner.js +0 -12
- package/lib/public/modules/prompt-kinds/permission-choices.js +1 -6
- package/lib/public/modules/prompt-kinds/permission.js +0 -15
- package/lib/sdk-bridge.js +82 -3
- package/lib/sessions.js +7 -0
- package/lib/turn-initiator.js +29 -14
- package/lib/utils.js +4 -7
- package/lib/ws-schema.js +3 -3
- package/lib/yoke/adapters/claude-worker.js +5 -5
- package/lib/yoke/adapters/claude.js +5 -5
- package/package.json +3 -1
- package/scripts/vendor-identity-vectors.js +52 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Class 1: an attestation provider that issues Identity Assertions.
|
|
4
|
+
//
|
|
5
|
+
// Transport. The console runs the issuer's published client, `gatekeeper hook
|
|
6
|
+
// process`, documented for a launcher that starts a runtime as a subprocess. The
|
|
7
|
+
// socket protocol itself is not part of the published contract documents, so it
|
|
8
|
+
// is not spoken here.
|
|
9
|
+
//
|
|
10
|
+
// Launcher binding. The issuer binds the assertion to the runtime above the
|
|
11
|
+
// requesting process, which for the process adapter is its parent: the console
|
|
12
|
+
// process that starts the session. The client is therefore started directly by
|
|
13
|
+
// this process (execFile, no shell, no wrapper), never through `sh -c`.
|
|
14
|
+
//
|
|
15
|
+
// Origin passing. The origin is handed over as `--origin`. The adapter does not
|
|
16
|
+
// issue the origin "human" (follow-up in the issuer: lr-f184b8), so for a typed
|
|
17
|
+
// session no client is run at all: the session starts without an identity, with
|
|
18
|
+
// the stable reason code origin_human_not_issued and no notice, and is graded
|
|
19
|
+
// declared by consumers. It is never given an identity claiming another origin.
|
|
20
|
+
// The runtime id is not sent: the issuer derives `rt` from the launcher itself.
|
|
21
|
+
|
|
22
|
+
var childProcess = require("child_process");
|
|
23
|
+
var contract = require("../contract");
|
|
24
|
+
var unavailableModule = require("../unavailable");
|
|
25
|
+
|
|
26
|
+
var unavailable = unavailableModule.unavailable;
|
|
27
|
+
|
|
28
|
+
var OUTPUT_PATTERN = new RegExp("^" + contract.IDENTITY_DIR_ENV + "=(/[A-Za-z0-9._/+-]+)\\n?$");
|
|
29
|
+
var MAX_OUTPUT_BYTES = 4096;
|
|
30
|
+
var HUMAN_ORIGIN_CODE = "origin_human_not_issued";
|
|
31
|
+
|
|
32
|
+
function clientArgs(cfg, definition, origin) {
|
|
33
|
+
var args = ["hook", "process", "--socket", cfg.socket];
|
|
34
|
+
if (contract.matches(contract.NAME_PATTERN, definition)) args.push("--definition", definition);
|
|
35
|
+
if (origin) args.push("--origin", origin);
|
|
36
|
+
return args;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function createGatekeeperProvider(cfg, deps) {
|
|
40
|
+
var execFile = (deps && deps.execFile) || childProcess.execFile;
|
|
41
|
+
var warn = (deps && deps.warn) || console.warn;
|
|
42
|
+
|
|
43
|
+
function obtainSession(definition, origin, rt, ctx) {
|
|
44
|
+
// The issuer never issues a session for a typed turn; the human signal is the
|
|
45
|
+
// per-turn origin, not the session assertion. Asking would only fail, so no
|
|
46
|
+
// client is run and the absence is expected (no notice), never worked around
|
|
47
|
+
// by another class.
|
|
48
|
+
if (origin === "human") {
|
|
49
|
+
return Promise.resolve(unavailable(HUMAN_ORIGIN_CODE,
|
|
50
|
+
"the issuer does not issue sessions for a human-typed turn", { quiet: true }));
|
|
51
|
+
}
|
|
52
|
+
if (ctx && ctx.owner && ctx.owner.uid !== process.getuid()) {
|
|
53
|
+
return Promise.resolve(unavailable("owner_unsupported",
|
|
54
|
+
"the issuer delivers to the console's own user only, not to a per-user OS account"));
|
|
55
|
+
}
|
|
56
|
+
var env = Object.assign({}, process.env);
|
|
57
|
+
delete env[contract.IDENTITY_DIR_ENV];
|
|
58
|
+
return new Promise(function (resolve) {
|
|
59
|
+
execFile(cfg.binary, clientArgs(cfg, definition, origin), {
|
|
60
|
+
env: env,
|
|
61
|
+
timeout: cfg.timeoutMs,
|
|
62
|
+
maxBuffer: MAX_OUTPUT_BYTES,
|
|
63
|
+
signal: ctx && ctx.signal,
|
|
64
|
+
windowsHide: true,
|
|
65
|
+
}, function (err, stdout, stderr) {
|
|
66
|
+
if (err) {
|
|
67
|
+
var detail = String(stderr || err.message || "").trim().split("\n")[0].slice(0, 200);
|
|
68
|
+
warn("[identity] gatekeeper client failed: " + (err.code === "ENOENT" ? "executable not found" : detail));
|
|
69
|
+
if (err.code === "ENOENT") {
|
|
70
|
+
resolve(unavailable("issuer_client_missing", "the identity issuer's client program was not found"));
|
|
71
|
+
} else if (err.killed) {
|
|
72
|
+
resolve(unavailable("issuer_timeout", "the identity issuer did not answer in time"));
|
|
73
|
+
} else {
|
|
74
|
+
resolve(unavailable("issuer_unavailable", "the identity issuer could not issue a session"));
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
var match = OUTPUT_PATTERN.exec(String(stdout));
|
|
79
|
+
if (!match) {
|
|
80
|
+
resolve(unavailable("issuer_output_invalid", "the identity issuer's client answered in a form the console does not recognise"));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
resolve({ provider: contract.PROVIDERS.GATEKEEPER, dir: match[1] });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return { name: contract.PROVIDERS.GATEKEEPER, obtainSession: obtainSession };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = { createGatekeeperProvider: createGatekeeperProvider };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Class 2: the console is its own issuer. It signs contract-conformant session
|
|
4
|
+
// assertions with its own key and publishes the matching key set, so any verifier
|
|
5
|
+
// that trusts this console's `iss` can check them with a standard JWS library and
|
|
6
|
+
// no other software installed.
|
|
7
|
+
//
|
|
8
|
+
// What this is, and is not. The console asserts what it knows about its own
|
|
9
|
+
// session. Its key is readable by the console's own user, so the assertion is
|
|
10
|
+
// attribution-grade (grade "harness": an actor that exists inside a host process,
|
|
11
|
+
// asserted by that host) and never workload-grade.
|
|
12
|
+
//
|
|
13
|
+
// No human. The console never signs a `human:` subject or actor. `sub` is the
|
|
14
|
+
// runtime and `act.sub` the persona agent when the session has one, else the
|
|
15
|
+
// runtime again. That a person typed the turn is carried by the `origin` claim
|
|
16
|
+
// only.
|
|
17
|
+
|
|
18
|
+
var crypto = require("crypto");
|
|
19
|
+
var contract = require("../contract");
|
|
20
|
+
var signingKey = require("./signing-key");
|
|
21
|
+
var unavailableModule = require("../unavailable");
|
|
22
|
+
var pkg = require("../../../package.json");
|
|
23
|
+
|
|
24
|
+
var unavailable = unavailableModule.unavailable;
|
|
25
|
+
|
|
26
|
+
function runtimeActor(rt) {
|
|
27
|
+
return "runtime:" + rt;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function buildClaims(cfg, definition, origin, rt, dir) {
|
|
31
|
+
var now = Math.floor(Date.now() / 1000);
|
|
32
|
+
var hasDefinition = contract.matches(contract.NAME_PATTERN, definition);
|
|
33
|
+
return {
|
|
34
|
+
iss: cfg.issuer,
|
|
35
|
+
sub: runtimeActor(rt),
|
|
36
|
+
act: { sub: hasDefinition ? "agent:" + definition : runtimeActor(rt) },
|
|
37
|
+
roles: cfg.roles.slice(),
|
|
38
|
+
grade: "harness",
|
|
39
|
+
rt: { id: rt, version: pkg.version },
|
|
40
|
+
sid: crypto.randomUUID(),
|
|
41
|
+
spawn: crypto.randomUUID(),
|
|
42
|
+
origin: origin,
|
|
43
|
+
dir: dir,
|
|
44
|
+
iat: now,
|
|
45
|
+
exp: now + cfg.ttlSeconds,
|
|
46
|
+
jti: crypto.randomUUID(),
|
|
47
|
+
cia: contract.CONTRACT_MAJOR,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createJwksSelfProvider(cfg) {
|
|
52
|
+
var signerPromise = null;
|
|
53
|
+
|
|
54
|
+
function signer() {
|
|
55
|
+
if (!signerPromise) {
|
|
56
|
+
signerPromise = signingKey.loadSigner(cfg).catch(function (err) {
|
|
57
|
+
// A failure is not cached: fixing the key and starting the next session works.
|
|
58
|
+
signerPromise = null;
|
|
59
|
+
throw err;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return signerPromise;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function obtainSession(definition, origin, rt, ctx) {
|
|
66
|
+
if (!contract.matches(contract.NAME_PATTERN, rt)) return unavailable("runtime_invalid", "the runtime id is not a valid actor name");
|
|
67
|
+
if (contract.ORIGINS.indexOf(origin) === -1) return unavailable("origin_invalid", "the turn's origin is not one the contract defines");
|
|
68
|
+
var s;
|
|
69
|
+
try {
|
|
70
|
+
s = await signer();
|
|
71
|
+
} catch (err) {
|
|
72
|
+
if (err && err.identityCode) return unavailable(err.identityCode, err.message);
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
var dir = await ctx.allocateDir();
|
|
76
|
+
var assertion = await new s.jose.SignJWT(buildClaims(cfg, definition, origin, rt, dir))
|
|
77
|
+
.setProtectedHeader({ alg: s.alg, kid: s.kid })
|
|
78
|
+
.sign(s.privateKey);
|
|
79
|
+
return { provider: contract.PROVIDERS.JWKS_SELF, dir: dir, assertion: assertion };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return { name: contract.PROVIDERS.JWKS_SELF, obtainSession: obtainSession };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = { createJwksSelfProvider: createJwksSelfProvider };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// A user-supplied provider (for example a client of a workload identity API),
|
|
4
|
+
// named by identity.provider_module as an absolute path. The module exports an
|
|
5
|
+
// object, or a function returning one, with:
|
|
6
|
+
//
|
|
7
|
+
// name recorded on the session; plain name
|
|
8
|
+
// obtainSession(definition, origin, rt, ctx)
|
|
9
|
+
// returns { dir, assertion? } or a typed unavailability
|
|
10
|
+
// (ctx.unavailable(code, reason, { quiet? })). `dir` is an absolute
|
|
11
|
+
// directory laid out as the contract's section 6 says, either one the
|
|
12
|
+
// module made or one it got from ctx.allocateDir(); `assertion`, when
|
|
13
|
+
// given, is written into it as identity.jwt.
|
|
14
|
+
// release(info) optional, called at most once when the
|
|
15
|
+
// session ends; the console does not wait for it. A directory from
|
|
16
|
+
// ctx.allocateDir() is removed by the console; a directory the module
|
|
17
|
+
// made is the module's, and the console removes nothing in it (end it in
|
|
18
|
+
// release()).
|
|
19
|
+
//
|
|
20
|
+
// ctx: { allocateDir(): string, owner: { uid, gid } | null,
|
|
21
|
+
// signal: AbortSignal, unavailable(code, reason, options): object }
|
|
22
|
+
//
|
|
23
|
+
// The module runs with the console's authority: it is code the person running the
|
|
24
|
+
// console chose, in the same way as the rest of the console's configuration.
|
|
25
|
+
|
|
26
|
+
var path = require("path");
|
|
27
|
+
var url = require("url");
|
|
28
|
+
var contract = require("../contract");
|
|
29
|
+
var unavailableModule = require("../unavailable");
|
|
30
|
+
|
|
31
|
+
var unavailable = unavailableModule.unavailable;
|
|
32
|
+
|
|
33
|
+
var RESERVED_NAMES = Object.keys(contract.PROVIDERS).map(function (k) { return contract.PROVIDERS[k]; });
|
|
34
|
+
var DEFAULT_NAME = "module";
|
|
35
|
+
|
|
36
|
+
async function loadModule(modulePath) {
|
|
37
|
+
var loaded = await import(url.pathToFileURL(path.normalize(modulePath)).href);
|
|
38
|
+
var exported = loaded.default !== undefined ? loaded.default : loaded;
|
|
39
|
+
if (typeof exported === "function") exported = await exported();
|
|
40
|
+
if (!exported || typeof exported.obtainSession !== "function") {
|
|
41
|
+
throw new Error("the module does not export obtainSession");
|
|
42
|
+
}
|
|
43
|
+
return exported;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function createModuleProvider(cfg, deps) {
|
|
47
|
+
var warn = (deps && deps.warn) || console.warn;
|
|
48
|
+
var loading = null;
|
|
49
|
+
|
|
50
|
+
function load() {
|
|
51
|
+
if (!loading) {
|
|
52
|
+
loading = loadModule(cfg.modulePath).catch(function (err) {
|
|
53
|
+
loading = null;
|
|
54
|
+
warn("[identity] provider module could not be loaded: " + (err && err.message));
|
|
55
|
+
return null;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return loading;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// A reserved name would let a module pass its own sessions off as ones a
|
|
62
|
+
// built-in provider vouched for.
|
|
63
|
+
function nameOf(mod) {
|
|
64
|
+
var name = mod.name;
|
|
65
|
+
if (!contract.matches(contract.NAME_PATTERN, name) || RESERVED_NAMES.indexOf(name) !== -1) {
|
|
66
|
+
return DEFAULT_NAME;
|
|
67
|
+
}
|
|
68
|
+
return name;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function obtainSession(definition, origin, rt, ctx) {
|
|
72
|
+
var mod = await load();
|
|
73
|
+
if (!mod) return unavailable("module_load_failed", "the identity provider module could not be loaded");
|
|
74
|
+
var result;
|
|
75
|
+
try {
|
|
76
|
+
result = await mod.obtainSession(definition, origin, rt, ctx);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
warn("[identity] provider module failed: " + (err && err.message));
|
|
79
|
+
return unavailable("provider_error", "the identity provider module failed");
|
|
80
|
+
}
|
|
81
|
+
if (unavailableModule.isUnavailable(result)) return unavailable(result.code, result.reason, { quiet: result.quiet });
|
|
82
|
+
if (!result || typeof result.dir !== "string") {
|
|
83
|
+
return unavailable("provider_result_invalid", "the identity provider module returned no directory");
|
|
84
|
+
}
|
|
85
|
+
return { provider: nameOf(mod), dir: result.dir, assertion: result.assertion };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function release(info) {
|
|
89
|
+
return load().then(function (mod) {
|
|
90
|
+
if (mod && typeof mod.release === "function") return mod.release(info);
|
|
91
|
+
return undefined;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { name: DEFAULT_NAME, obtainSession: obtainSession, release: release };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = { createModuleProvider: createModuleProvider };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The console's own signing key and the key set it publishes, for the jwks-self
|
|
4
|
+
// provider. The key is an Ed25519 key in a PKCS#8 PEM file; the public half is
|
|
5
|
+
// published as a JWKS document (contract section 5.2: no private parameters).
|
|
6
|
+
|
|
7
|
+
var fs = require("fs");
|
|
8
|
+
var path = require("path");
|
|
9
|
+
var crypto = require("crypto");
|
|
10
|
+
var joseLoader = require("../jose");
|
|
11
|
+
|
|
12
|
+
var ALG = "EdDSA";
|
|
13
|
+
|
|
14
|
+
function keyError(code, message) {
|
|
15
|
+
var err = new Error(message);
|
|
16
|
+
err.identityCode = code;
|
|
17
|
+
return err;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function readPrivateKey(keyPath) {
|
|
21
|
+
var fd;
|
|
22
|
+
try {
|
|
23
|
+
fd = fs.openSync(keyPath, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
if (e.code === "ENOENT") return null;
|
|
26
|
+
throw keyError("key_unreadable", "the identity signing key could not be opened");
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
var st = fs.fstatSync(fd);
|
|
30
|
+
if (!st.isFile()) throw keyError("key_unsafe", "the identity signing key is not a regular file");
|
|
31
|
+
if (st.uid !== process.getuid() || (st.mode & 0o077) !== 0) {
|
|
32
|
+
throw keyError("key_unsafe", "the identity signing key must be owned by the console user and private to it");
|
|
33
|
+
}
|
|
34
|
+
return crypto.createPrivateKey(fs.readFileSync(fd, "utf8"));
|
|
35
|
+
} catch (e) {
|
|
36
|
+
if (e.identityCode) throw e;
|
|
37
|
+
throw keyError("key_unreadable", "the identity signing key could not be read as a PEM private key");
|
|
38
|
+
} finally {
|
|
39
|
+
fs.closeSync(fd);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
var PEER_READ_ATTEMPTS = 10;
|
|
44
|
+
var PEER_READ_WAIT_MS = 20;
|
|
45
|
+
|
|
46
|
+
function waitSync(ms) {
|
|
47
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// A peer that won the exclusive create may still be writing: its file is read
|
|
51
|
+
// again a few times before it is called unreadable.
|
|
52
|
+
function readPeerKey(keyPath) {
|
|
53
|
+
for (var attempt = 1; ; attempt++) {
|
|
54
|
+
try {
|
|
55
|
+
var key = readPrivateKey(keyPath);
|
|
56
|
+
if (key) return key;
|
|
57
|
+
} catch (e) {
|
|
58
|
+
if (e.identityCode !== "key_unreadable" || attempt >= PEER_READ_ATTEMPTS) throw e;
|
|
59
|
+
}
|
|
60
|
+
if (attempt >= PEER_READ_ATTEMPTS) throw keyError("key_unreadable", "the identity signing key could not be read");
|
|
61
|
+
waitSync(PEER_READ_WAIT_MS);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Creates the key when no file is there and returns the key that is in the file
|
|
66
|
+
// afterwards: when another process created it first, that process's key.
|
|
67
|
+
function createKeyIfAbsent(keyPath) {
|
|
68
|
+
var pair = crypto.generateKeyPairSync("ed25519");
|
|
69
|
+
fs.mkdirSync(path.dirname(keyPath), { recursive: true, mode: 0o700 });
|
|
70
|
+
try {
|
|
71
|
+
// The file is created private (mode at creation, exclusive) so the key is
|
|
72
|
+
// never readable by anyone else, even for an instant.
|
|
73
|
+
fs.writeFileSync(keyPath, pair.privateKey.export({ type: "pkcs8", format: "pem" }), { flag: "wx", mode: 0o600 });
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if (e.code !== "EEXIST") throw e;
|
|
76
|
+
return readPeerKey(keyPath);
|
|
77
|
+
}
|
|
78
|
+
return pair.privateKey;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function requireEd25519(key) {
|
|
82
|
+
if (key.asymmetricKeyType !== "ed25519") {
|
|
83
|
+
throw keyError("key_unsupported", "the identity signing key must be an Ed25519 key");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Writes the JWKS only when its content changed, atomically, readable by others
|
|
88
|
+
// (a verifier under another user reads it) and writable by the console only.
|
|
89
|
+
function publishJwks(jwksPath, jwks) {
|
|
90
|
+
var text = JSON.stringify(jwks, null, 2) + "\n";
|
|
91
|
+
try {
|
|
92
|
+
if (fs.readFileSync(jwksPath, "utf8") === text) return;
|
|
93
|
+
} catch (e) {
|
|
94
|
+
// Not published yet, or unreadable: written below.
|
|
95
|
+
}
|
|
96
|
+
fs.mkdirSync(path.dirname(jwksPath), { recursive: true, mode: 0o755 });
|
|
97
|
+
var staging = jwksPath + ".tmp-" + process.pid;
|
|
98
|
+
fs.writeFileSync(staging, text, { flag: "w", mode: 0o644 });
|
|
99
|
+
fs.renameSync(staging, jwksPath);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Loads (and, for the default location, creates) the key, publishes its JWKS and
|
|
103
|
+
// returns what signing needs.
|
|
104
|
+
async function loadSigner(cfg) {
|
|
105
|
+
var privateKey = readPrivateKey(cfg.signingKey);
|
|
106
|
+
if (!privateKey) {
|
|
107
|
+
if (!cfg.generateKey) throw keyError("key_missing", "the identity signing key does not exist");
|
|
108
|
+
privateKey = createKeyIfAbsent(cfg.signingKey);
|
|
109
|
+
}
|
|
110
|
+
requireEd25519(privateKey);
|
|
111
|
+
var jose = await joseLoader.loadJose();
|
|
112
|
+
var jwk = crypto.createPublicKey(privateKey).export({ format: "jwk" });
|
|
113
|
+
var kid = await jose.calculateJwkThumbprint(jwk);
|
|
114
|
+
publishJwks(cfg.jwksPath, { keys: [Object.assign({}, jwk, { kid: kid, alg: ALG, use: "sig" })] });
|
|
115
|
+
return { privateKey: privateKey, kid: kid, alg: ALG, jose: jose };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = { loadSigner: loadSigner, createKeyIfAbsent: createKeyIfAbsent, ALG: ALG };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The identity record a session carries: which provider vouched for it and at
|
|
4
|
+
// what grade. Read back from a session file, so it is rebuilt from known values
|
|
5
|
+
// only, whatever the file holds.
|
|
6
|
+
|
|
7
|
+
var contract = require("./contract");
|
|
8
|
+
var CODE_PATTERN = require("./unavailable").CODE_PATTERN;
|
|
9
|
+
|
|
10
|
+
function sanitizeRecord(value) {
|
|
11
|
+
if (!value || typeof value !== "object") return null;
|
|
12
|
+
var provider = value.provider;
|
|
13
|
+
if (!contract.matches(contract.NAME_PATTERN, provider)) return null;
|
|
14
|
+
var record = {
|
|
15
|
+
provider: provider,
|
|
16
|
+
grade: contract.GRADES.indexOf(value.grade) === -1 ? null : value.grade,
|
|
17
|
+
origin: contract.ORIGINS.indexOf(value.origin) === -1 ? null : value.origin,
|
|
18
|
+
};
|
|
19
|
+
if (contract.matches(CODE_PATTERN, value.unavailable)) record.unavailable = value.unavailable;
|
|
20
|
+
return record;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = { sanitizeRecord: sanitizeRecord };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// The typed result of a provider that cannot supply an identity. A session that
|
|
4
|
+
// receives it starts without one: nothing is fabricated in its place.
|
|
5
|
+
//
|
|
6
|
+
// code a short stable identifier (lower-case letters, digits, underscore)
|
|
7
|
+
// reason one sentence for the person running the console, no secrets and no
|
|
8
|
+
// host paths
|
|
9
|
+
// quiet true when the absence is expected rather than a fault (a runtime the
|
|
10
|
+
// surface does not cover), so no notice is shown for it
|
|
11
|
+
|
|
12
|
+
var contract = require("./contract");
|
|
13
|
+
|
|
14
|
+
var CODE_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
|
|
15
|
+
|
|
16
|
+
function unavailable(code, reason, options) {
|
|
17
|
+
return {
|
|
18
|
+
unavailable: true,
|
|
19
|
+
code: contract.matches(CODE_PATTERN, code) ? code : "provider_error",
|
|
20
|
+
reason: typeof reason === "string" && reason ? reason.slice(0, 200) : "the identity provider could not supply an identity",
|
|
21
|
+
quiet: !!(options && options.quiet),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isUnavailable(value) {
|
|
26
|
+
return !!value && typeof value === "object" && value.unavailable === true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { unavailable: unavailable, isUnavailable: isUnavailable, CODE_PATTERN: CODE_PATTERN };
|
|
@@ -75,10 +75,9 @@ var formatters = {
|
|
|
75
75
|
// So the banner offers the answers the card does (see prompt-banner.js).
|
|
76
76
|
suppressAlwaysAllowRule: data.suppressAlwaysAllowRule === true ? true : undefined,
|
|
77
77
|
defaultToNo: data.defaultToNo === true ? true : undefined,
|
|
78
|
-
// Who asked
|
|
79
|
-
//
|
|
78
|
+
// Who asked: a banner reaches every client whatever project it is
|
|
79
|
+
// viewing.
|
|
80
80
|
label: data.label || null,
|
|
81
|
-
grantScope: typeof data.grantScope === "string" ? data.grantScope : null,
|
|
82
81
|
},
|
|
83
82
|
};
|
|
84
83
|
},
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
// An ask without hints (Codex approvals, older CLIs) is unchanged.
|
|
16
16
|
|
|
17
17
|
var toolCall = require("./tool-call");
|
|
18
|
-
var grantKeys = require("../grant-keys");
|
|
19
18
|
var { hasOwnKey } = require("./codecs");
|
|
20
19
|
|
|
21
20
|
var DECISIONS = { allow: true, allow_always: true, deny: true };
|
|
@@ -55,17 +54,12 @@ module.exports = {
|
|
|
55
54
|
store: "pendingPermissions",
|
|
56
55
|
journal: true,
|
|
57
56
|
|
|
58
|
-
// grantScope is what Allow for Session would grant for this very call, as a
|
|
59
|
-
// sentence, or null when the call cannot be granted for the session. It is
|
|
60
|
-
// computed once, here, so the card, the banner and the check that settles
|
|
61
|
-
// the answer all read the same scope.
|
|
62
57
|
fields: function (req) {
|
|
63
58
|
return Object.assign({
|
|
64
59
|
toolName: req.toolName,
|
|
65
60
|
toolInput: req.toolInput,
|
|
66
61
|
decisionReason: req.decisionReason || "",
|
|
67
62
|
vendor: req.vendor,
|
|
68
|
-
grantScope: grantKeys.grantScopeText(req.toolName, req.toolInput),
|
|
69
63
|
}, hintsOf(req));
|
|
70
64
|
},
|
|
71
65
|
|
|
@@ -75,7 +69,6 @@ module.exports = {
|
|
|
75
69
|
toolInput: record.toolInput,
|
|
76
70
|
decisionReason: record.decisionReason || "",
|
|
77
71
|
vendor: record.vendor,
|
|
78
|
-
grantScope: record.grantScope === undefined ? null : record.grantScope,
|
|
79
72
|
}, hintsOf(record));
|
|
80
73
|
},
|
|
81
74
|
|
|
@@ -85,7 +78,6 @@ module.exports = {
|
|
|
85
78
|
return {
|
|
86
79
|
suppressAlwaysAllowRule: hints.suppressAlwaysAllowRule,
|
|
87
80
|
defaultToNo: hints.defaultToNo,
|
|
88
|
-
grantScope: record.grantScope === undefined ? null : record.grantScope,
|
|
89
81
|
};
|
|
90
82
|
},
|
|
91
83
|
|
|
@@ -99,16 +91,6 @@ module.exports = {
|
|
|
99
91
|
if (decision === "allow_always" && record && record.suppressAlwaysAllowRule === true) {
|
|
100
92
|
return { invalid: "always_allow_not_offered" };
|
|
101
93
|
}
|
|
102
|
-
// A file tool never produces a session grant. An old client may still send
|
|
103
|
-
// Allow for Session for one: it is answered as this call only, nothing is
|
|
104
|
-
// stored.
|
|
105
|
-
if (decision === "allow_always" && record && grantKeys.isFileTool(record.toolName)) {
|
|
106
|
-
return { decision: "allow" };
|
|
107
|
-
}
|
|
108
|
-
// A call with nothing narrow enough to grant is never granted wider.
|
|
109
|
-
if (decision === "allow_always" && record && record.grantScope === null) {
|
|
110
|
-
return { invalid: "grant_scope_unavailable" };
|
|
111
|
-
}
|
|
112
94
|
return { decision: decision };
|
|
113
95
|
},
|
|
114
96
|
|
package/lib/prompt-registry.js
CHANGED
|
@@ -617,23 +617,15 @@ function createPromptRegistry(deps) {
|
|
|
617
617
|
}
|
|
618
618
|
|
|
619
619
|
function isGranted(session, toolName, input) {
|
|
620
|
-
return
|
|
620
|
+
return ownValue(session.allowedTools, utils.permissionGrantKey(toolName, input)) === true;
|
|
621
621
|
}
|
|
622
622
|
|
|
623
|
-
//
|
|
624
|
-
//
|
|
625
|
-
//
|
|
626
|
-
// with no narrow key, or a grant map with no room left in the persisted
|
|
627
|
-
// record, is allowed this once and nothing wider.
|
|
623
|
+
// Flushed immediately so the grant survives a daemon restart or a resume
|
|
624
|
+
// that rebuilds the session from disk. Returns true: a grant is always
|
|
625
|
+
// stored (lib/grant-keys.js for the key).
|
|
628
626
|
function grant(session, toolName, input) {
|
|
629
|
-
var key = utils.permissionGrantKey(toolName, input);
|
|
630
|
-
if (key === null) return false;
|
|
631
627
|
if (!session.allowedTools) session.allowedTools = Object.create(null);
|
|
632
|
-
|
|
633
|
-
console.warn("[prompt-registry] session grant not stored, the record has no room: " + key.slice(0, 40));
|
|
634
|
-
return false;
|
|
635
|
-
}
|
|
636
|
-
putOwn(session.allowedTools, key, true);
|
|
628
|
+
putOwn(session.allowedTools, utils.permissionGrantKey(toolName, input), true);
|
|
637
629
|
saveSessionFile(session);
|
|
638
630
|
return true;
|
|
639
631
|
}
|
|
@@ -136,8 +136,8 @@
|
|
|
136
136
|
letter-spacing: 0.12em;
|
|
137
137
|
margin-bottom: 3px;
|
|
138
138
|
}
|
|
139
|
-
/* Whose prompt this is
|
|
140
|
-
|
|
139
|
+
/* Whose prompt this is: wrapped, never cut off, because a clipped label is
|
|
140
|
+
the failure this line exists to fix. */
|
|
141
141
|
.notif-banner-label {
|
|
142
142
|
font-family: var(--font-mono, monospace);
|
|
143
143
|
font-size: 10.5px;
|
|
@@ -145,12 +145,6 @@
|
|
|
145
145
|
margin-bottom: 3px;
|
|
146
146
|
overflow-wrap: anywhere;
|
|
147
147
|
}
|
|
148
|
-
.notif-banner-scope {
|
|
149
|
-
font-size: 12px;
|
|
150
|
-
color: var(--text-secondary);
|
|
151
|
-
margin-top: 3px;
|
|
152
|
-
overflow-wrap: anywhere;
|
|
153
|
-
}
|
|
154
148
|
.notif-banner-title {
|
|
155
149
|
font-weight: 500;
|
|
156
150
|
font-size: 13px;
|
|
@@ -618,7 +618,6 @@
|
|
|
618
618
|
|
|
619
619
|
/* The user's own ask rule that forced the prompt. */
|
|
620
620
|
.permission-rule { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
|
|
621
|
-
.permission-scope { font-size: 12px; color: var(--text-secondary); margin-top: 6px; overflow-wrap: anywhere; }
|
|
622
621
|
.prompt-label {
|
|
623
622
|
font-family: var(--font-mono, monospace);
|
|
624
623
|
font-size: 11px;
|
|
@@ -13,7 +13,7 @@ import { switchProject } from './app-projects.js';
|
|
|
13
13
|
import { userAvatarUrl } from './avatar.js';
|
|
14
14
|
import { openTerminal } from './terminal.js';
|
|
15
15
|
import { askWording } from './prompt-kinds/index.js';
|
|
16
|
-
import { wirePromptBanner, restoreUnconfirmedBanners, bannerActions
|
|
16
|
+
import { wirePromptBanner, restoreUnconfirmedBanners, bannerActions } from './prompt-banner.js';
|
|
17
17
|
import { promptLabelHtml } from './prompt-label.js';
|
|
18
18
|
|
|
19
19
|
// The server dismisses a prompt's banner once the prompt settles, however it
|
|
@@ -140,11 +140,9 @@ function showBanner(notif, autoDismissMs) {
|
|
|
140
140
|
'</div>';
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
// The server says whose prompt this is (project, session, agent)
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
var scopeText = isPermission ? bannerScope(promptKind, notif.meta) : "";
|
|
147
|
-
|
|
143
|
+
// The server says whose prompt this is (project, session, agent): a banner
|
|
144
|
+
// reaches every client whatever project it is viewing, and the tool request
|
|
145
|
+
// alone does not say.
|
|
148
146
|
banner.innerHTML =
|
|
149
147
|
'<div class="notif-banner-icon">' + iconHtmlStr + '</div>' +
|
|
150
148
|
'<div class="notif-banner-body">' +
|
|
@@ -152,7 +150,6 @@ function showBanner(notif, autoDismissMs) {
|
|
|
152
150
|
(isPermission ? promptLabelHtml(notif.meta.label) : '') +
|
|
153
151
|
'<div class="notif-banner-title">' + escapeHtml(notif.title) + '</div>' +
|
|
154
152
|
(notif.body ? '<div class="notif-banner-text">' + escapeHtml(notif.body) + '</div>' : '') +
|
|
155
|
-
(scopeText ? '<div class="notif-banner-scope">' + escapeHtml(scopeText) + '</div>' : '') +
|
|
156
153
|
actionsHtml +
|
|
157
154
|
'</div>' +
|
|
158
155
|
(!isEmpty ? '<button class="notif-banner-close">' + iconHtml("x") + '</button>' : '');
|