@clagentic/console 1.10.0-beta.2 → 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.
Files changed (59) hide show
  1. package/lib/activity-clock.js +23 -0
  2. package/lib/build-sha.json +2 -2
  3. package/lib/build-update-offer.js +29 -0
  4. package/lib/cli-transcript-title.js +131 -0
  5. package/lib/daemon.js +5 -9
  6. package/lib/debug-log.js +17 -0
  7. package/lib/exit-flush.js +44 -0
  8. package/lib/grant-keys.js +66 -0
  9. package/lib/identity/config.js +118 -0
  10. package/lib/identity/contract.js +61 -0
  11. package/lib/identity/delivery.js +224 -0
  12. package/lib/identity/holder.js +87 -0
  13. package/lib/identity/index.js +229 -0
  14. package/lib/identity/jose.js +13 -0
  15. package/lib/identity/origin.js +28 -0
  16. package/lib/identity/owner.js +30 -0
  17. package/lib/identity/providers/gatekeeper.js +91 -0
  18. package/lib/identity/providers/jwks-self.js +85 -0
  19. package/lib/identity/providers/module.js +98 -0
  20. package/lib/identity/providers/signing-key.js +118 -0
  21. package/lib/identity/record.js +23 -0
  22. package/lib/identity/unavailable.js +29 -0
  23. package/lib/log-field.js +34 -0
  24. package/lib/project-http.js +2 -0
  25. package/lib/project-notifications.js +3 -0
  26. package/lib/project-prompt-responses.js +2 -1
  27. package/lib/project-session-grants.js +73 -0
  28. package/lib/project-sessions.js +12 -0
  29. package/lib/project-user-message.js +6 -5
  30. package/lib/project.js +2 -0
  31. package/lib/prompt-label.js +60 -0
  32. package/lib/prompt-registry.js +105 -10
  33. package/lib/prompt-source.js +65 -0
  34. package/lib/public/css/notifications-center.css +9 -0
  35. package/lib/public/css/overlays.css +18 -0
  36. package/lib/public/css/rewind.css +7 -0
  37. package/lib/public/modules/app-messages.js +3 -0
  38. package/lib/public/modules/app-notifications.js +5 -0
  39. package/lib/public/modules/build-notice-gate.js +73 -0
  40. package/lib/public/modules/diagnostics.js +43 -1
  41. package/lib/public/modules/prompt-label.js +44 -0
  42. package/lib/public/modules/prompts.js +9 -0
  43. package/lib/public/modules/session-grants.js +131 -0
  44. package/lib/public/modules/sidebar-sessions.js +11 -0
  45. package/lib/runtime-env.js +1 -1
  46. package/lib/sdk-bridge.js +135 -104
  47. package/lib/sdk-message-processor.js +14 -67
  48. package/lib/session-ai-title.js +80 -0
  49. package/lib/session-input.js +32 -2
  50. package/lib/sessions.js +21 -18
  51. package/lib/turn-initiator.js +29 -14
  52. package/lib/utils.js +5 -46
  53. package/lib/ws-schema.js +6 -3
  54. package/lib/yoke/adapters/claude-worker.js +5 -5
  55. package/lib/yoke/adapters/claude.js +5 -62
  56. package/lib/yoke/adapters/codex.js +4 -75
  57. package/lib/yoke/interface.js +3 -7
  58. package/package.json +3 -1
  59. package/scripts/vendor-identity-vectors.js +52 -0
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ // The one writer of session.lastActivityAt, the clock the idle reaper compares
4
+ // against (startIdleReaper in lib/sdk-bridge.js). Every bump names its source
5
+ // and, with CLAGENTIC_CONSOLE_DEBUG set, logs it, so a session that is never
6
+ // reaped can be traced to the event that kept resetting its clock.
7
+
8
+ var { debugLog } = require("./debug-log");
9
+ var { logField } = require("./log-field");
10
+
11
+ /**
12
+ * @param {object} session
13
+ * @param {string} source - what moved the clock (a fixed vocabulary at the call
14
+ * sites, e.g. "turn-result", "subagent-stream", "task_progress").
15
+ * @param {string} slug - the owning project; console session ids repeat across
16
+ * projects.
17
+ */
18
+ function bumpLastActivity(session, source, slug) {
19
+ session.lastActivityAt = Date.now();
20
+ debugLog("[activity] lastActivityAt bump: project=" + logField(slug) + " session=" + logField(session.localId) + " source=" + logField(source));
21
+ }
22
+
23
+ module.exports = { bumpLastActivity: bumpLastActivity };
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "1e4c285f1bfb4f164e33781a01e713c038b29ac3",
3
- "writtenAt": "2026-10-14T16:34:23.977Z"
2
+ "sha": "38180f943464c9b8120a5a21e1cf03e350beb81d",
3
+ "writtenAt": "2026-10-16T13:17:15.032Z"
4
4
  }
@@ -131,7 +131,36 @@ function summarizeOffer(a) {
131
131
  : 'Running build ' + short(a.loadedBuildSha) + '; installed build ' + short(a.installedBuildSha) + '.';
132
132
  }
133
133
 
134
+ var DEFAULT_NOTICE_COOLDOWN_MS = 60 * 60 * 1000;
135
+
136
+ /**
137
+ * How long a client keeps a closed build-update notice quiet. `raw` is the
138
+ * CLAGENTIC_CONSOLE_BUILD_NOTICE_COOLDOWN_MS value; unset, empty or invalid
139
+ * (not a non-negative number) falls back to the default. 0 disables the quiet period.
140
+ */
141
+ function noticeCooldownFrom(raw) {
142
+ if (raw === undefined || raw === null || raw === '') return DEFAULT_NOTICE_COOLDOWN_MS;
143
+ var n = Number(raw);
144
+ return isFinite(n) && n >= 0 ? n : DEFAULT_NOTICE_COOLDOWN_MS;
145
+ }
146
+
147
+ /** The standing diagnostic every client is sent for a stale build. */
148
+ function composeNotice(assessment, changes, cooldownMs) {
149
+ return {
150
+ type: 'diagnostic',
151
+ severity: 'warning',
152
+ source: 'build-update',
153
+ message: summarizeOffer(assessment) + ' Restart to apply it when it suits you; nothing restarts on its own.',
154
+ buildUpdate: buildOffer({ assessment: assessment, changes: changes }),
155
+ actionable: { label: 'Restart to apply update', action: 'restart_for_build_update' },
156
+ noticeCooldownMs: cooldownMs,
157
+ };
158
+ }
159
+
134
160
  module.exports = {
161
+ DEFAULT_NOTICE_COOLDOWN_MS: DEFAULT_NOTICE_COOLDOWN_MS,
162
+ noticeCooldownFrom: noticeCooldownFrom,
163
+ composeNotice: composeNotice,
135
164
  collectInterruptions: collectInterruptions,
136
165
  coveredBy: coveredBy,
137
166
  describeInterruptions: describeInterruptions,
@@ -0,0 +1,131 @@
1
+ // cli-transcript-title.js - reads the title the Claude Code CLI wrote for a
2
+ // session into its own transcript.
3
+ //
4
+ // The CLI appends a record of this shape to <claudeDir>/projects/<cwd>/<id>.jsonl
5
+ // each time it titles the session, and the last one wins:
6
+ //
7
+ // {"type":"ai-title","aiTitle":"...","sessionId":"<id>"}
8
+ //
9
+ // The SDK message stream does not carry it (sdk.d.ts has no message for it), so
10
+ // the transcript is the only source. Nothing here writes to the transcript.
11
+
12
+ var fs = require("fs");
13
+ var path = require("path");
14
+ var utils = require("./utils");
15
+ var { isSafeSessionId, sessionPathWithin } = require("./session-id");
16
+
17
+ // A transcript can be large and the record is normally near its end, so the
18
+ // file is read backwards in chunks and the scan stops at the first match.
19
+ var CHUNK_BYTES = 64 * 1024;
20
+ var MAX_SCAN_BYTES = 16 * 1024 * 1024;
21
+ var MAX_TITLE_CHARS = 100;
22
+
23
+ var NEWLINE = 0x0a;
24
+
25
+ function normalize(title) {
26
+ if (typeof title !== "string") return null;
27
+ var t = title.replace(/\s+/g, " ").trim();
28
+ return t ? t.substring(0, MAX_TITLE_CHARS) : null;
29
+ }
30
+
31
+ function aiTitleOfLine(line, sessionId) {
32
+ if (line.indexOf('"ai-title"') === -1) return null;
33
+ var obj;
34
+ try { obj = JSON.parse(line); } catch (e) { return null; }
35
+ if (!obj || obj.type !== "ai-title") return null;
36
+ // A record naming another session is not this session's title.
37
+ if (obj.sessionId && obj.sessionId !== sessionId) return null;
38
+ return normalize(obj.aiTitle);
39
+ }
40
+
41
+ // Resolves the latest ai-title in the transcript at filePath for sessionId, or
42
+ // null when there is none or the file cannot be read.
43
+ function readLatestAiTitle(filePath, sessionId) {
44
+ return fs.promises.open(filePath, "r").then(function (fh) {
45
+ function scan() {
46
+ return fh.stat().then(function (st) {
47
+ var pos = st.size;
48
+ var scanned = 0;
49
+ var carry = Buffer.alloc(0);
50
+
51
+ function step() {
52
+ if (pos <= 0 || scanned >= MAX_SCAN_BYTES) {
53
+ // pos === 0: carry is the first line of the file.
54
+ return Promise.resolve(pos <= 0 && carry.length ? aiTitleOfLine(carry.toString("utf8"), sessionId) : null);
55
+ }
56
+ var len = Math.min(CHUNK_BYTES, pos);
57
+ pos -= len;
58
+ scanned += len;
59
+ var chunk = Buffer.alloc(len);
60
+ return fh.read(chunk, 0, len, pos).then(function () {
61
+ var buf = Buffer.concat([chunk, carry]);
62
+ // Lines are split on bytes so a multibyte character cut by the
63
+ // chunk edge is never decoded half-way.
64
+ var end = buf.length;
65
+ var found = null;
66
+ for (var i = buf.length - 1; i >= 0 && found === null; i--) {
67
+ if (buf[i] === NEWLINE) {
68
+ if (end > i + 1) found = aiTitleOfLine(buf.toString("utf8", i + 1, end), sessionId);
69
+ end = i;
70
+ }
71
+ }
72
+ if (found !== null) return found;
73
+ carry = buf.subarray(0, end);
74
+ return step();
75
+ });
76
+ }
77
+ return step();
78
+ });
79
+ }
80
+ return scan().then(
81
+ function (v) { return fh.close().then(function () { return v; }); },
82
+ function (e) { return fh.close().then(function () { throw e; }); }
83
+ );
84
+ }).catch(function () { return null; });
85
+ }
86
+
87
+ // Finds <claudeDir>/projects/*/<sessionId>.jsonl. The directory named for a
88
+ // cwd in cwds is tried first; any other project directory is searched after,
89
+ // because the CLI names the directory for the cwd the query ran in.
90
+ // Resolves the path or null.
91
+ function findTranscript(claudeDir, cwds, sessionId) {
92
+ if (!isSafeSessionId(sessionId)) return Promise.resolve(null);
93
+ var projectsDir = path.join(claudeDir, "projects");
94
+
95
+ function exists(p) {
96
+ return fs.promises.stat(p).then(function (st) { return st.isFile(); }, function () { return false; });
97
+ }
98
+
99
+ var tried = {};
100
+ var candidates = [];
101
+ (cwds || []).forEach(function (c) {
102
+ if (typeof c !== "string" || !c) return;
103
+ var dir = path.join(projectsDir, utils.encodeCwd(c));
104
+ if (!tried[dir]) { tried[dir] = true; candidates.push(dir); }
105
+ });
106
+
107
+ function tryDirs(i) {
108
+ if (i >= candidates.length) return Promise.resolve(null);
109
+ var p = sessionPathWithin(candidates[i], sessionId, ".jsonl");
110
+ return exists(p).then(function (ok) { return ok ? p : tryDirs(i + 1); });
111
+ }
112
+
113
+ return tryDirs(0).then(function (hit) {
114
+ if (hit) return hit;
115
+ return fs.promises.readdir(projectsDir).then(function (names) {
116
+ function next(i) {
117
+ if (i >= names.length) return Promise.resolve(null);
118
+ var dir = path.join(projectsDir, names[i]);
119
+ if (tried[dir]) return next(i + 1);
120
+ var p = sessionPathWithin(dir, sessionId, ".jsonl");
121
+ return exists(p).then(function (ok) { return ok ? p : next(i + 1); });
122
+ }
123
+ return next(0);
124
+ }, function () { return null; });
125
+ });
126
+ }
127
+
128
+ module.exports = {
129
+ readLatestAiTitle: readLatestAiTitle,
130
+ findTranscript: findTranscript,
131
+ };
package/lib/daemon.js CHANGED
@@ -47,7 +47,7 @@ var { dropSkillsCache } = require("./server-skills");
47
47
  var { waitForIdleThenAct } = require("./build-update-check");
48
48
  var { createBuildMonitor } = require("./build-monitor");
49
49
  var { createBuildUpdateRestart } = require("./build-update-restart");
50
- var { buildOffer, summarizeOffer } = require("./build-update-offer");
50
+ var { composeNotice, noticeCooldownFrom } = require("./build-update-offer");
51
51
  var { createStandingOffer } = require("./build-update-standing");
52
52
  var { listBuildChanges, resolveHistoryRepo } = require("./build-changes");
53
53
  var { RESTART_EXIT_CODE, isSupervised, unsupervisedEnv } = require("./supervisor");
@@ -1397,6 +1397,9 @@ function liveProjectsForOffer() {
1397
1397
  var BUILD_CHECK_MS = Number(readConsoleEnv("CLAGENTIC_CONSOLE_BUILD_CHECK_MS")) || 60 * 1000;
1398
1398
  // A failed change-list read is retried no more often than the journal reminder.
1399
1399
  var BUILD_REMINDER_EVERY = 30;
1400
+ // How long a closed build-update notice stays quiet in a client before the same
1401
+ // notice may show again; the client applies it (lib/public/modules/build-notice-gate.js).
1402
+ var BUILD_NOTICE_COOLDOWN_MS = noticeCooldownFrom(readConsoleEnv("CLAGENTIC_CONSOLE_BUILD_NOTICE_COOLDOWN_MS"));
1400
1403
 
1401
1404
  // The offer clients hold is reconciled against the monitor's confirmed stale
1402
1405
  // assessment after every poll (lib/build-update-standing.js): it is shown,
@@ -1408,14 +1411,7 @@ var buildStandingOffer = createStandingOffer({
1408
1411
  retryAfterMs: BUILD_CHECK_MS * BUILD_REMINDER_EVERY,
1409
1412
  broadcast: function (message) { relay.broadcastAll(message); },
1410
1413
  compose: function (a, changes) {
1411
- return {
1412
- type: "diagnostic",
1413
- severity: "warning",
1414
- source: "build-update",
1415
- message: summarizeOffer(a) + " Restart to apply it when it suits you; nothing restarts on its own.",
1416
- buildUpdate: buildOffer({ assessment: a, changes: changes }),
1417
- actionable: { label: "Restart to apply update", action: "restart_for_build_update" },
1418
- };
1414
+ return composeNotice(a, changes, BUILD_NOTICE_COOLDOWN_MS);
1419
1415
  },
1420
1416
  log: function (line) { console.log("[daemon] " + line); },
1421
1417
  });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ // Lines worth keeping off the journal by default: they fire per stream event.
4
+ // Set CLAGENTIC_CONSOLE_DEBUG to see them. The variable is read at each call so
5
+ // an operator can start the daemon with it and a test can set it for one case.
6
+
7
+ var { readConsoleEnv } = require("./env-compat");
8
+
9
+ function debugEnabled() {
10
+ return !!readConsoleEnv("CLAGENTIC_CONSOLE_DEBUG");
11
+ }
12
+
13
+ function debugLog(line) {
14
+ if (debugEnabled()) console.log(line);
15
+ }
16
+
17
+ module.exports = { debugLog: debugLog, debugEnabled: debugEnabled };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ // Everything that must be written before the process ends, behind ONE
4
+ // process "exit" listener however many callers register.
5
+ //
6
+ // Each project's session manager used to add its own listener, so a daemon with
7
+ // fifty projects added fifty to `process` at startup and tripped Node's
8
+ // MaxListenersExceededWarning (the default cap is 10; the daemon raises it, and
9
+ // raising it again would only move the line). The listener is installed when
10
+ // the first flusher registers and removed when the last one unregisters, so a
11
+ // daemon that opens and closes projects does not accumulate any.
12
+
13
+ var flushers = new Set();
14
+ var installed = false;
15
+
16
+ function flushAll() {
17
+ flushers.forEach(function (flush) {
18
+ // One flusher failing must not stop the others: this is the last chance
19
+ // any of them gets to write.
20
+ try { flush(); }
21
+ catch (e) { console.error("[exit-flush] flush failed:", e && e.message ? e.message : e); }
22
+ });
23
+ }
24
+
25
+ /**
26
+ * @param {function(): void} flush - runs synchronously when the process exits.
27
+ * @returns {function(): void} unregister; safe to call more than once.
28
+ */
29
+ function registerExitFlush(flush) {
30
+ flushers.add(flush);
31
+ if (!installed) {
32
+ process.on("exit", flushAll);
33
+ installed = true;
34
+ }
35
+ return function unregister() {
36
+ flushers.delete(flush);
37
+ if (installed && flushers.size === 0) {
38
+ process.removeListener("exit", flushAll);
39
+ installed = false;
40
+ }
41
+ };
42
+ }
43
+
44
+ module.exports = { registerExitFlush: registerExitFlush };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ // What an "Allow for Session" answer grants, and how a later tool call is
4
+ // matched against it. One function builds the key for a call; the same key is
5
+ // what is stored when the operator grants it and what a later call is looked
6
+ // up by.
7
+ //
8
+ // Key shapes (stored as keys of session.allowedTools, persisted in the session
9
+ // meta record, always with the value true):
10
+ // <Tool> the whole tool: every later call of it in the session skips
11
+ // the prompt. This holds for file tools and Bash alike.
12
+ // Skill:<name> one skill (the Skill tool is one name over many skills).
13
+ //
14
+ // Bash=<command> keys were written by builds that scoped a Bash grant to one
15
+ // command line. No call produces one now, so they are dropped on load rather
16
+ // than left as grants nothing can match.
17
+
18
+ var SCOPED_BASH_KEY = /^Bash=/;
19
+
20
+ /**
21
+ * Whether a persisted value is one a grant under this key can hold: true, and
22
+ * not the retired exact-command Bash key.
23
+ */
24
+ function isGrantValue(key, value) {
25
+ return value === true && !SCOPED_BASH_KEY.test(key);
26
+ }
27
+
28
+ /**
29
+ * The key a call is granted and matched by.
30
+ *
31
+ * Most tools are discriminated by bare tool name alone: MCP tools already fold
32
+ * server and tool into the name. The Claude `Skill` tool is the exception:
33
+ * every skill arrives as toolName "Skill" with a different `input.skill`, so a
34
+ * bare "Skill" key would authorize every skill. Falls back to the bare name
35
+ * when the call names no skill.
36
+ * @param {string} toolName
37
+ * @param {?object} input
38
+ * @returns {string}
39
+ */
40
+ function permissionGrantKey(toolName, input) {
41
+ if (toolName === "Skill" && input && typeof input.skill === "string" && input.skill) {
42
+ return "Skill:" + input.skill;
43
+ }
44
+ return toolName;
45
+ }
46
+
47
+ /**
48
+ * Describe a stored key for the operator.
49
+ * @param {string} key
50
+ * @returns {{key: string, tool: string, wholeTool: boolean, text: string}}
51
+ */
52
+ function describeGrantKey(key) {
53
+ if (key.indexOf("Skill:") === 0) {
54
+ return { key: key, tool: "Skill", wholeTool: false, text: "Skill " + key.slice(6) };
55
+ }
56
+ return {
57
+ key: key, tool: key, wholeTool: true,
58
+ text: "Every " + key + " call, whatever it does (whole-tool grant)",
59
+ };
60
+ }
61
+
62
+ module.exports = {
63
+ permissionGrantKey: permissionGrantKey,
64
+ describeGrantKey: describeGrantKey,
65
+ isGrantValue: isGrantValue,
66
+ };
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ // Reads the `identity` block of the console configuration (daemon.json).
4
+ //
5
+ // identity.provider "none" (default) | "gatekeeper" | "jwks-self" | "module"
6
+ // identity.spawn_root where session delivery directories are created
7
+ //
8
+ // gatekeeper: identity.gatekeeper.socket issuer socket (absolute path)
9
+ // identity.gatekeeper.binary client executable, default "gatekeeper"
10
+ // identity.gatekeeper.timeout_ms bound on one request
11
+ // jwks-self: identity.signing_key private key (PEM, PKCS#8 Ed25519)
12
+ // identity.jwks_path where the public key set is published
13
+ // identity.issuer `iss` of the assertions, default file URL of jwks_path
14
+ // identity.roles role ceiling the assertions carry, default none
15
+ // identity.ttl_seconds assertion lifetime, default 3600, at most 43200
16
+ // module: identity.provider_module absolute path of a user-supplied provider
17
+ //
18
+ // An absent block, or provider "none", is the default: the console does nothing
19
+ // identity-related. A block that cannot be understood is reported as provider
20
+ // "invalid" so every session says so instead of silently running unattested.
21
+
22
+ var path = require("path");
23
+ var url = require("url");
24
+ var contract = require("./contract");
25
+
26
+ var DEFAULT_TTL_SECONDS = 3600;
27
+ var DEFAULT_GATEKEEPER_BINARY = "gatekeeper";
28
+ var DEFAULT_TIMEOUT_MS = 8000;
29
+
30
+ function none() {
31
+ return { provider: "none" };
32
+ }
33
+
34
+ function invalid(reason) {
35
+ return { provider: "invalid", reason: reason };
36
+ }
37
+
38
+ function isAbsolutePath(value) {
39
+ return typeof value === "string" && value !== "" && path.isAbsolute(value);
40
+ }
41
+
42
+ function isObject(value) {
43
+ return !!value && typeof value === "object" && !Array.isArray(value);
44
+ }
45
+
46
+ function commonFields(raw, configDir) {
47
+ var spawnRoot = raw.spawn_root === undefined ? path.join(configDir, "identity", "spawn") : raw.spawn_root;
48
+ if (!isAbsolutePath(spawnRoot)) return { error: "identity.spawn_root must be an absolute path" };
49
+ return { spawnRoot: spawnRoot };
50
+ }
51
+
52
+ function gatekeeperConfig(raw, common) {
53
+ var gk = raw.gatekeeper;
54
+ if (!isObject(gk) || !isAbsolutePath(gk.socket)) {
55
+ return invalid("identity.gatekeeper.socket must be an absolute path");
56
+ }
57
+ var binary = gk.binary === undefined ? DEFAULT_GATEKEEPER_BINARY : gk.binary;
58
+ if (typeof binary !== "string" || binary === "") return invalid("identity.gatekeeper.binary must be a string");
59
+ var timeout = gk.timeout_ms === undefined ? DEFAULT_TIMEOUT_MS : gk.timeout_ms;
60
+ if (!Number.isInteger(timeout) || timeout <= 0) return invalid("identity.gatekeeper.timeout_ms must be a positive integer");
61
+ return { provider: "gatekeeper", spawnRoot: common.spawnRoot, socket: gk.socket, binary: binary, timeoutMs: timeout };
62
+ }
63
+
64
+ function jwksSelfConfig(raw, common, configDir) {
65
+ var signingKey = raw.signing_key === undefined ? path.join(configDir, "identity", "signing-key.pem") : raw.signing_key;
66
+ var jwksPath = raw.jwks_path === undefined ? path.join(configDir, "identity", "jwks.json") : raw.jwks_path;
67
+ if (!isAbsolutePath(signingKey)) return invalid("identity.signing_key must be an absolute path");
68
+ if (!isAbsolutePath(jwksPath)) return invalid("identity.jwks_path must be an absolute path");
69
+ var issuer = raw.issuer === undefined ? url.pathToFileURL(jwksPath).href : raw.issuer;
70
+ if (typeof issuer !== "string" || issuer === "") return invalid("identity.issuer must be a string");
71
+ var roles = raw.roles === undefined ? [] : raw.roles;
72
+ if (!Array.isArray(roles) || roles.some(function (r) { return !contract.matches(contract.ROLE_PATTERN, r); }) || new Set(roles).size !== roles.length) {
73
+ return invalid("identity.roles must be a list of distinct role names");
74
+ }
75
+ var ttl = raw.ttl_seconds === undefined ? DEFAULT_TTL_SECONDS : raw.ttl_seconds;
76
+ if (!Number.isInteger(ttl) || ttl <= 0 || ttl > contract.MAX_LIFETIME_SECONDS) {
77
+ return invalid("identity.ttl_seconds must be between 1 and " + contract.MAX_LIFETIME_SECONDS);
78
+ }
79
+ return {
80
+ provider: "jwks-self",
81
+ spawnRoot: common.spawnRoot,
82
+ signingKey: signingKey,
83
+ // Only the default key is created when it is missing: a key path someone
84
+ // named is never replaced by a freshly generated one.
85
+ generateKey: raw.signing_key === undefined,
86
+ jwksPath: jwksPath,
87
+ issuer: issuer,
88
+ roles: roles.slice(),
89
+ ttlSeconds: ttl,
90
+ };
91
+ }
92
+
93
+ function resolveConfig(raw, configDir) {
94
+ if (raw === undefined || raw === null) return none();
95
+ if (!isObject(raw)) return invalid("identity must be an object");
96
+ var name = raw.provider;
97
+ if (name === undefined) name = raw.provider_module === undefined ? "none" : "module";
98
+ if (name === "none") return none();
99
+ if (typeof name !== "string") return invalid("identity.provider must be a string");
100
+ if (raw.provider_module !== undefined && name !== "module") {
101
+ return invalid("identity.provider_module cannot be combined with identity.provider " + name);
102
+ }
103
+ var common = commonFields(raw, configDir);
104
+ if (common.error) return invalid(common.error);
105
+ switch (name) {
106
+ case contract.PROVIDERS.GATEKEEPER:
107
+ return gatekeeperConfig(raw, common);
108
+ case contract.PROVIDERS.JWKS_SELF:
109
+ return jwksSelfConfig(raw, common, configDir);
110
+ case "module":
111
+ if (!isAbsolutePath(raw.provider_module)) return invalid("identity.provider_module must be an absolute path");
112
+ return { provider: "module", spawnRoot: common.spawnRoot, modulePath: raw.provider_module };
113
+ default:
114
+ return invalid("identity.provider " + JSON.stringify(name.slice(0, 40)) + " is not one the console knows");
115
+ }
116
+ }
117
+
118
+ module.exports = { resolveConfig: resolveConfig };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ // Constants of the published Identity Assertion contract (version 1.0.0). The
4
+ // console implements the contract from its text, a JWS library and the vendored
5
+ // conformance vectors; it shares no code with any issuer.
6
+
7
+ var CONTRACT_VERSION = "1.0.0";
8
+ var CONTRACT_MAJOR = 1;
9
+
10
+ // What the console delivers a session's assertion through.
11
+ var IDENTITY_DIR_ENV = "CLAGENTIC_IDENTITY_DIR";
12
+ var IDENTITY_FILE = "identity.jwt";
13
+ var IDENTITY_TMP_DIR = "tmp";
14
+
15
+ var MAX_LIFETIME_SECONDS = 43200;
16
+ var MAX_FILE_BYTES = 16384;
17
+ var MAX_JWKS_BYTES = 65536;
18
+
19
+ var ALGORITHMS = Object.freeze(["EdDSA", "ES256"]);
20
+ var GRADES = Object.freeze(["workload", "harness"]);
21
+ var ORIGINS = Object.freeze(["human", "scheduled", "loop", "trigger", "agent"]);
22
+
23
+ var ACTOR_PATTERN = /^(agent|runtime):[A-Za-z0-9._-]{1,128}$/;
24
+ var SUBJECT_PATTERN = /^(human|agent|runtime):[A-Za-z0-9._-]{1,128}$/;
25
+ var ROLE_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;
26
+ var NAME_PATTERN = /^[A-Za-z0-9._-]{1,128}$/;
27
+
28
+ // RegExp.prototype.test coerces its argument to a string, so null, true or 5
29
+ // would pass for the names "null", "true" and "5". Every check of a name against
30
+ // one of the patterns above goes through here instead.
31
+ function matches(pattern, value) {
32
+ return typeof value === "string" && pattern.test(value);
33
+ }
34
+
35
+ // The names providers record on a session. "declared" is the record of a
36
+ // session that has no assertion: the console says what it did, nothing is signed.
37
+ var PROVIDERS = Object.freeze({
38
+ GATEKEEPER: "gatekeeper",
39
+ JWKS_SELF: "jwks-self",
40
+ DECLARED: "declared",
41
+ });
42
+
43
+ module.exports = {
44
+ CONTRACT_VERSION: CONTRACT_VERSION,
45
+ CONTRACT_MAJOR: CONTRACT_MAJOR,
46
+ IDENTITY_DIR_ENV: IDENTITY_DIR_ENV,
47
+ IDENTITY_FILE: IDENTITY_FILE,
48
+ IDENTITY_TMP_DIR: IDENTITY_TMP_DIR,
49
+ MAX_LIFETIME_SECONDS: MAX_LIFETIME_SECONDS,
50
+ MAX_FILE_BYTES: MAX_FILE_BYTES,
51
+ MAX_JWKS_BYTES: MAX_JWKS_BYTES,
52
+ ALGORITHMS: ALGORITHMS,
53
+ GRADES: GRADES,
54
+ ORIGINS: ORIGINS,
55
+ ACTOR_PATTERN: ACTOR_PATTERN,
56
+ SUBJECT_PATTERN: SUBJECT_PATTERN,
57
+ ROLE_PATTERN: ROLE_PATTERN,
58
+ NAME_PATTERN: NAME_PATTERN,
59
+ matches: matches,
60
+ PROVIDERS: PROVIDERS,
61
+ };