@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.
- package/lib/activity-clock.js +23 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +29 -0
- package/lib/cli-transcript-title.js +131 -0
- package/lib/daemon.js +5 -9
- package/lib/debug-log.js +17 -0
- package/lib/exit-flush.js +44 -0
- package/lib/grant-keys.js +66 -0
- 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/log-field.js +34 -0
- package/lib/project-http.js +2 -0
- package/lib/project-notifications.js +3 -0
- package/lib/project-prompt-responses.js +2 -1
- package/lib/project-session-grants.js +73 -0
- package/lib/project-sessions.js +12 -0
- package/lib/project-user-message.js +6 -5
- package/lib/project.js +2 -0
- package/lib/prompt-label.js +60 -0
- package/lib/prompt-registry.js +105 -10
- package/lib/prompt-source.js +65 -0
- package/lib/public/css/notifications-center.css +9 -0
- package/lib/public/css/overlays.css +18 -0
- package/lib/public/css/rewind.css +7 -0
- package/lib/public/modules/app-messages.js +3 -0
- package/lib/public/modules/app-notifications.js +5 -0
- package/lib/public/modules/build-notice-gate.js +73 -0
- package/lib/public/modules/diagnostics.js +43 -1
- package/lib/public/modules/prompt-label.js +44 -0
- package/lib/public/modules/prompts.js +9 -0
- package/lib/public/modules/session-grants.js +131 -0
- package/lib/public/modules/sidebar-sessions.js +11 -0
- package/lib/runtime-env.js +1 -1
- package/lib/sdk-bridge.js +135 -104
- package/lib/sdk-message-processor.js +14 -67
- package/lib/session-ai-title.js +80 -0
- package/lib/session-input.js +32 -2
- package/lib/sessions.js +21 -18
- package/lib/turn-initiator.js +29 -14
- package/lib/utils.js +5 -46
- package/lib/ws-schema.js +6 -3
- package/lib/yoke/adapters/claude-worker.js +5 -5
- package/lib/yoke/adapters/claude.js +5 -62
- package/lib/yoke/adapters/codex.js +4 -75
- package/lib/yoke/interface.js +3 -7
- package/package.json +3 -1
- package/scripts/vendor-identity-vectors.js +52 -0
|
@@ -4,6 +4,7 @@ var { promptsFor } = require("./prompt-registry");
|
|
|
4
4
|
var { putOwn } = require("./prompt-kinds/codecs");
|
|
5
5
|
var { isKnownVendor } = require("./yoke");
|
|
6
6
|
var { INITIATORS } = require("./turn-initiator");
|
|
7
|
+
var promptSource = require("./prompt-source");
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Attach user-message handler and remaining small handlers
|
|
@@ -49,7 +50,7 @@ function truncateCodePointSafe(str, maxLen) {
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
// lr-62157d: pure helper — derives the FIRST-message provisional title
|
|
52
|
-
// (before any turn has completed / before
|
|
53
|
+
// (before any turn has completed / before the CLI has written its own title).
|
|
53
54
|
// Prefers real message text; falls back to the first paste when text is
|
|
54
55
|
// empty (a >=500-char paste is diverted server-side into msg.pastes[] with
|
|
55
56
|
// msg.text empty by the client's paste-chip handling — see input.js — so
|
|
@@ -298,7 +299,7 @@ function attachUserMessage(ctx) {
|
|
|
298
299
|
// authenticated client's extension_result is ignored.
|
|
299
300
|
if (msg.type === "extension_result") {
|
|
300
301
|
if (!mayAnswerExtensionCommand(msg.requestId, ws)) return true;
|
|
301
|
-
promptsFor(sm).respond(msg.requestId, { result: msg.result }, { kinds: ["extension"] });
|
|
302
|
+
promptsFor(sm).respond(msg.requestId, { result: msg.result }, { kinds: ["extension"], source: promptSource.fromWs(ws) });
|
|
302
303
|
return true;
|
|
303
304
|
}
|
|
304
305
|
|
|
@@ -429,9 +430,9 @@ function attachUserMessage(ctx) {
|
|
|
429
430
|
|
|
430
431
|
if (!session.title) {
|
|
431
432
|
session.title = deriveProvisionalTitle(msg);
|
|
432
|
-
// This is only a provisional title —
|
|
433
|
-
//
|
|
434
|
-
//
|
|
433
|
+
// This is only a provisional title — session-ai-title.js replaces it
|
|
434
|
+
// once the CLI has written its own title, as long as the user hasn't
|
|
435
|
+
// manually renamed the session since.
|
|
435
436
|
session.titleProvisional = true;
|
|
436
437
|
sm.saveSessionFile(session);
|
|
437
438
|
sm.broadcastSessionList();
|
package/lib/project.js
CHANGED
|
@@ -442,6 +442,8 @@ function createProjectContext(opts) {
|
|
|
442
442
|
historyInMemMax: historyInMemMax,
|
|
443
443
|
getNotificationsModule: function () { return _notifications; },
|
|
444
444
|
onProcessingChanged: onProcessingChanged,
|
|
445
|
+
getProjectName: function () { return title || project; },
|
|
446
|
+
getProjectSlug: function () { return slug; },
|
|
445
447
|
});
|
|
446
448
|
sm.availableVendors = Object.keys(adapters);
|
|
447
449
|
sm.defaultVendor = defaultVendor;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Who a prompt is from: the project, the session and, when a background agent
|
|
4
|
+
// raised it, that agent. Every surface that shows a prompt (card, banner, push
|
|
5
|
+
// notification) shows these, because a banner reaches every connected client
|
|
6
|
+
// whatever project it is viewing, and a tool request alone does not say whose
|
|
7
|
+
// it is.
|
|
8
|
+
|
|
9
|
+
var FIELD_MAX = 80;
|
|
10
|
+
var UNTITLED = "(untitled session)";
|
|
11
|
+
|
|
12
|
+
// Titles and agent descriptions are authored outside the console (a session
|
|
13
|
+
// title is typed or model-generated, a Task description comes from the model),
|
|
14
|
+
// so each is reduced to one bounded line.
|
|
15
|
+
function oneLine(raw) {
|
|
16
|
+
if (typeof raw !== "string") return "";
|
|
17
|
+
var one = raw.replace(/\s+/g, " ").trim();
|
|
18
|
+
return one.length > FIELD_MAX ? one.slice(0, FIELD_MAX - 3) + "..." : one;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {{project: ?string, sessionTitle: ?string, agent: ?string}} parts
|
|
23
|
+
* @returns {{project: string, session: string, agent: string}} agent is ""
|
|
24
|
+
* when the prompt belongs to the session itself.
|
|
25
|
+
*/
|
|
26
|
+
function promptLabel(parts) {
|
|
27
|
+
var p = parts || {};
|
|
28
|
+
return {
|
|
29
|
+
project: oneLine(p.project),
|
|
30
|
+
session: oneLine(p.sessionTitle) || UNTITLED,
|
|
31
|
+
agent: oneLine(p.agent),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The label as one line for a push notification.
|
|
37
|
+
* @param {?{project: string, session: string, agent: string}} label
|
|
38
|
+
* @returns {string} "" for no label.
|
|
39
|
+
*/
|
|
40
|
+
function formatPromptLabel(label) {
|
|
41
|
+
if (!label) return "";
|
|
42
|
+
var out = [];
|
|
43
|
+
if (label.project) out.push("Project: " + label.project);
|
|
44
|
+
if (label.session) out.push("Session: " + label.session);
|
|
45
|
+
if (label.agent) out.push("Agent: " + label.agent);
|
|
46
|
+
return out.join(" | ");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A push body that says whose prompt it is on its first line.
|
|
51
|
+
* @param {?object} label
|
|
52
|
+
* @param {string} body
|
|
53
|
+
*/
|
|
54
|
+
function withPromptLabel(label, body) {
|
|
55
|
+
var line = formatPromptLabel(label);
|
|
56
|
+
if (!line) return body || "";
|
|
57
|
+
return body ? line + "\n" + body : line;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = { promptLabel: promptLabel, formatPromptLabel: formatPromptLabel, withPromptLabel: withPromptLabel };
|
package/lib/prompt-registry.js
CHANGED
|
@@ -45,6 +45,11 @@ var crypto = require("crypto");
|
|
|
45
45
|
var utils = require("./utils");
|
|
46
46
|
var promptKinds = require("./prompt-kinds");
|
|
47
47
|
var codecs = require("./prompt-kinds/codecs");
|
|
48
|
+
var grantKeys = require("./grant-keys");
|
|
49
|
+
var sessionReclaim = require("./session-reclaim");
|
|
50
|
+
var { promptLabel } = require("./prompt-label");
|
|
51
|
+
var promptSource = require("./prompt-source");
|
|
52
|
+
var { logField } = require("./log-field");
|
|
48
53
|
var { ownValue, putOwn, hasOwnKey } = codecs;
|
|
49
54
|
|
|
50
55
|
var KINDS = promptKinds.KINDS;
|
|
@@ -117,6 +122,11 @@ function openedBy(item) {
|
|
|
117
122
|
* @param {function(object)} deps.saveSessionFile - durable session meta write.
|
|
118
123
|
* @param {function(): ?object} [deps.getNotificationsModule]
|
|
119
124
|
* @param {function()} [deps.onProcessingChanged] - cross-project badge refresh.
|
|
125
|
+
* @param {function(): string} [deps.getProjectName] - the project's display
|
|
126
|
+
* name, read at each prompt so a rename shows on the next one.
|
|
127
|
+
* @param {function(): string} [deps.getProjectSlug] - the project's slug, which
|
|
128
|
+
* the lifecycle log lines carry because console session ids repeat across
|
|
129
|
+
* projects.
|
|
120
130
|
*/
|
|
121
131
|
function createPromptRegistry(deps) {
|
|
122
132
|
var index = deps.index;
|
|
@@ -125,6 +135,8 @@ function createPromptRegistry(deps) {
|
|
|
125
135
|
var saveSessionFile = deps.saveSessionFile;
|
|
126
136
|
var getNotificationsModule = deps.getNotificationsModule || function () { return null; };
|
|
127
137
|
var onProcessingChanged = deps.onProcessingChanged || function () {};
|
|
138
|
+
var getProjectName = deps.getProjectName || function () { return ""; };
|
|
139
|
+
var getProjectSlug = deps.getProjectSlug || function () { return ""; };
|
|
128
140
|
|
|
129
141
|
// Project-scope prompts (no session): requestId -> record.
|
|
130
142
|
var projectPrompts = Object.create(null);
|
|
@@ -222,7 +234,36 @@ function createPromptRegistry(deps) {
|
|
|
222
234
|
pruneToolOwners(session);
|
|
223
235
|
}
|
|
224
236
|
|
|
225
|
-
|
|
237
|
+
// One line each when an operator prompt opens and when it settles, so the
|
|
238
|
+
// journal shows that a prompt was pending, for whom, and how it ended. Only
|
|
239
|
+
// identifiers and the outcome: never the tool input, the question, the
|
|
240
|
+
// answer or any prompt text.
|
|
241
|
+
function lifecycleFields(session, requestId, record, kind) {
|
|
242
|
+
var taskId = session ? ownerTaskOf(session, record) : null;
|
|
243
|
+
return "project=" + logField(getProjectSlug())
|
|
244
|
+
+ " session=" + logField(session && session.localId)
|
|
245
|
+
+ " request=" + logField(requestId, 80)
|
|
246
|
+
+ " kind=" + logField(kind.name)
|
|
247
|
+
+ " tool=" + logField(record.toolName)
|
|
248
|
+
+ " agent=" + (taskId ? "task:" + logField(taskId, 80) : "none");
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function logOpened(session, requestId, record, kind) {
|
|
252
|
+
if (!kind.journal) return;
|
|
253
|
+
console.log("[prompt-registry] prompt opened: " + lifecycleFields(session, requestId, record, kind));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// info: { status: "resolved"|"cancelled", source, reason?, decision?, granted? }
|
|
257
|
+
function logSettled(session, requestId, entry, info) {
|
|
258
|
+
if (!entry.kind.journal) return;
|
|
259
|
+
var line = "[prompt-registry] prompt " + info.status + ": " + lifecycleFields(session, requestId, entry.record, entry.kind);
|
|
260
|
+
if (info.decision) line += " decision=" + logField(info.decision);
|
|
261
|
+
if (info.status === "resolved") line += " grant=" + (info.granted ? "stored" : "none");
|
|
262
|
+
if (info.reason) line += " reason=" + logField(info.reason);
|
|
263
|
+
console.log(line + " " + promptSource.describe(info.source));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function settle(session, requestId, entry, value, event, info) {
|
|
226
267
|
var map = session ? session[entry.store] : projectPrompts;
|
|
227
268
|
if (!map || ownValue(map, requestId) !== entry.record) return false;
|
|
228
269
|
delete map[requestId];
|
|
@@ -233,6 +274,7 @@ function createPromptRegistry(deps) {
|
|
|
233
274
|
dismissNotification(requestId);
|
|
234
275
|
if (event) sendAndRecord(session, event);
|
|
235
276
|
onProcessingChanged();
|
|
277
|
+
if (info) logSettled(session, requestId, entry, info);
|
|
236
278
|
}
|
|
237
279
|
entry.record.resolve(value);
|
|
238
280
|
if (session) {
|
|
@@ -248,7 +290,11 @@ function createPromptRegistry(deps) {
|
|
|
248
290
|
var event = (entry.kind.journal && !(opts && opts.record === false))
|
|
249
291
|
? { type: "prompt_cancel", requestId: requestId, kind: entry.kind.name, reason: reason }
|
|
250
292
|
: null;
|
|
251
|
-
return settle(session, requestId, entry, entry.kind.cancelled(reason), event
|
|
293
|
+
return settle(session, requestId, entry, entry.kind.cancelled(reason), event, {
|
|
294
|
+
status: "cancelled",
|
|
295
|
+
reason: reason,
|
|
296
|
+
source: (opts && opts.source) || promptSource.fromCancel(reason),
|
|
297
|
+
});
|
|
252
298
|
}
|
|
253
299
|
|
|
254
300
|
function cancelWhere(session, reason, predicate, opts) {
|
|
@@ -311,6 +357,7 @@ function createPromptRegistry(deps) {
|
|
|
311
357
|
var owner = scoped ? session : null;
|
|
312
358
|
|
|
313
359
|
if (scoped) {
|
|
360
|
+
record.label = labelFor(session, record.toolUseId);
|
|
314
361
|
record.query = session.queryInstance || null;
|
|
315
362
|
putOwn(sessionMap(session, kind.store), requestId, record);
|
|
316
363
|
putOwn(index, requestId, session.localId);
|
|
@@ -323,8 +370,9 @@ function createPromptRegistry(deps) {
|
|
|
323
370
|
requestId: requestId,
|
|
324
371
|
kind: kind.name,
|
|
325
372
|
toolUseId: record.toolUseId,
|
|
326
|
-
}, kind.requestFields(record)));
|
|
373
|
+
}, labelFields(record), kind.requestFields(record)));
|
|
327
374
|
onProcessingChanged();
|
|
375
|
+
logOpened(owner, requestId, record, kind);
|
|
328
376
|
}
|
|
329
377
|
|
|
330
378
|
var cleanups = [];
|
|
@@ -337,7 +385,9 @@ function createPromptRegistry(deps) {
|
|
|
337
385
|
}
|
|
338
386
|
var timeoutMs = opts.timeoutMs != null ? opts.timeoutMs : kind.defaultTimeoutMs;
|
|
339
387
|
if (timeoutMs) {
|
|
340
|
-
var timer = setTimeout(function () {
|
|
388
|
+
var timer = setTimeout(function () {
|
|
389
|
+
cancelEntry(owner, requestId, entry, "expired", { source: promptSource.fromTimeout() });
|
|
390
|
+
}, timeoutMs);
|
|
341
391
|
cleanups.push(function () { clearTimeout(timer); });
|
|
342
392
|
}
|
|
343
393
|
if (cleanups.length) {
|
|
@@ -348,10 +398,10 @@ function createPromptRegistry(deps) {
|
|
|
348
398
|
var nm = getNotificationsModule();
|
|
349
399
|
if (nm && typeof nm.notify === "function") {
|
|
350
400
|
var kindFields = typeof kind.notificationFields === "function" ? kind.notificationFields(record) : {};
|
|
351
|
-
|
|
401
|
+
nm.notify("permission_request", Object.assign({}, opts.notification, kindFields, labelFields(record), { requestId: requestId, kind: kind.name }));
|
|
352
402
|
}
|
|
353
403
|
}
|
|
354
|
-
return { requestId: requestId, answer: answer, pending: true };
|
|
404
|
+
return { requestId: requestId, answer: answer, pending: true, label: record.label || null };
|
|
355
405
|
}
|
|
356
406
|
|
|
357
407
|
// The pending entry for requestId (its live record and kind adapter), or
|
|
@@ -413,6 +463,9 @@ function createPromptRegistry(deps) {
|
|
|
413
463
|
* @param {string} [opts.denyMessage] - override for a plain deny.
|
|
414
464
|
* @param {?object} [opts.responder] - the connection that answered, if
|
|
415
465
|
* any; handed to the resolution effects.
|
|
466
|
+
* @param {?object} [opts.source] - who answered (lib/prompt-source.js); it is
|
|
467
|
+
* logged and recorded on the prompt_resolved event. A caller that names none
|
|
468
|
+
* is logged as unspecified and its event carries no source.
|
|
416
469
|
*/
|
|
417
470
|
function respond(requestId, msg, opts) {
|
|
418
471
|
opts = opts || {};
|
|
@@ -427,12 +480,20 @@ function createPromptRegistry(deps) {
|
|
|
427
480
|
if (response.invalid) {
|
|
428
481
|
return { status: "invalid", reason: response.invalid, pending: kind.journal ? pendingMessage(requestId, found) : null };
|
|
429
482
|
}
|
|
430
|
-
|
|
483
|
+
var granted = kind.grantsSession(response) ? grant(found.session, found.record.toolName, found.record.toolInput) : false;
|
|
431
484
|
var event = kind.journal
|
|
432
485
|
? Object.assign({ type: "prompt_resolved", requestId: requestId, kind: kind.name }, kind.resolvedFields(response, found.record))
|
|
433
486
|
: null;
|
|
487
|
+
if (event && opts.source) event.source = opts.source;
|
|
434
488
|
var prompt = publicView(requestId, found);
|
|
435
|
-
|
|
489
|
+
// The decision word or action only; an answer's content stays out of the log.
|
|
490
|
+
var decision = event && (typeof event.decision === "string" ? event.decision : (typeof event.action === "string" ? event.action : null));
|
|
491
|
+
settle(found.session, requestId, found, kind.outcome(found.record, response, opts), event, {
|
|
492
|
+
status: "resolved",
|
|
493
|
+
decision: decision,
|
|
494
|
+
granted: granted,
|
|
495
|
+
source: opts.source || null,
|
|
496
|
+
});
|
|
436
497
|
var outcome = { status: "resolved", session: found.session, prompt: prompt, kind: kind.name, response: response };
|
|
437
498
|
if (resolutionEffects) resolutionEffects(outcome, opts.responder || null);
|
|
438
499
|
return outcome;
|
|
@@ -544,16 +605,47 @@ function createPromptRegistry(deps) {
|
|
|
544
605
|
return out;
|
|
545
606
|
}
|
|
546
607
|
|
|
608
|
+
// Who the prompt is from; null for a prompt with no session.
|
|
609
|
+
function labelFor(session, toolUseId) {
|
|
610
|
+
if (!session) return null;
|
|
611
|
+
var agent = sessionReclaim.ownerLabelOfTool(session, { ownerTaskOfTool: ownerTaskOfTool }, toolUseId);
|
|
612
|
+
return promptLabel({ project: getProjectName(), sessionTitle: session.title, agent: agent });
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function labelFields(record) {
|
|
616
|
+
return record && record.label ? { label: record.label } : {};
|
|
617
|
+
}
|
|
618
|
+
|
|
547
619
|
function isGranted(session, toolName, input) {
|
|
548
620
|
return ownValue(session.allowedTools, utils.permissionGrantKey(toolName, input)) === true;
|
|
549
621
|
}
|
|
550
622
|
|
|
551
623
|
// Flushed immediately so the grant survives a daemon restart or a resume
|
|
552
|
-
// that rebuilds the session from disk.
|
|
624
|
+
// that rebuilds the session from disk. Returns true: a grant is always
|
|
625
|
+
// stored (lib/grant-keys.js for the key).
|
|
553
626
|
function grant(session, toolName, input) {
|
|
554
627
|
if (!session.allowedTools) session.allowedTools = Object.create(null);
|
|
555
628
|
putOwn(session.allowedTools, utils.permissionGrantKey(toolName, input), true);
|
|
556
629
|
saveSessionFile(session);
|
|
630
|
+
return true;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** The session's grants, each described for the operator. */
|
|
634
|
+
function listGrants(session) {
|
|
635
|
+
var map = session && session.allowedTools;
|
|
636
|
+
if (!map) return [];
|
|
637
|
+
return Object.keys(map).filter(function (k) { return grantKeys.isGrantValue(k, map[k]); }).sort().map(grantKeys.describeGrantKey);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Take one grant away; the next call it covered prompts. Persisted at once.
|
|
642
|
+
* @returns {boolean} whether the session held it.
|
|
643
|
+
*/
|
|
644
|
+
function revokeGrant(session, key) {
|
|
645
|
+
if (!session || typeof key !== "string" || !grantKeys.isGrantValue(key, ownValue(session.allowedTools, key))) return false;
|
|
646
|
+
delete session.allowedTools[key];
|
|
647
|
+
saveSessionFile(session);
|
|
648
|
+
return true;
|
|
557
649
|
}
|
|
558
650
|
|
|
559
651
|
// The wire message re-presenting one pending prompt.
|
|
@@ -563,7 +655,7 @@ function createPromptRegistry(deps) {
|
|
|
563
655
|
requestId: requestId,
|
|
564
656
|
kind: entry.kind.name,
|
|
565
657
|
toolUseId: entry.record.toolUseId,
|
|
566
|
-
}, entry.kind.requestFields(entry.record));
|
|
658
|
+
}, labelFields(entry.record), entry.kind.requestFields(entry.record));
|
|
567
659
|
}
|
|
568
660
|
|
|
569
661
|
/** Wire messages re-presenting every pending prompt of a session. */
|
|
@@ -637,8 +729,11 @@ function createPromptRegistry(deps) {
|
|
|
637
729
|
isTaskTracked: isTaskTracked,
|
|
638
730
|
taskOwnsPending: taskOwnsPending,
|
|
639
731
|
trackedTaskIds: trackedTaskIds,
|
|
732
|
+
labelFor: labelFor,
|
|
640
733
|
isGranted: isGranted,
|
|
641
734
|
grant: grant,
|
|
735
|
+
listGrants: listGrants,
|
|
736
|
+
revokeGrant: revokeGrant,
|
|
642
737
|
pendingMessages: pendingMessages,
|
|
643
738
|
pendingCount: pendingCount,
|
|
644
739
|
replayAnnotator: replayAnnotator,
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Who or what settled a prompt. The prompt registry (lib/prompt-registry.js)
|
|
4
|
+
// logs a source for every prompt it settles and records the one for an answer
|
|
5
|
+
// in the session history (the prompt_resolved event), so "who allowed this"
|
|
6
|
+
// can be answered after the fact.
|
|
7
|
+
//
|
|
8
|
+
// { kind: "ws", clientId, user } an answer from a browser connection
|
|
9
|
+
// { kind: "push", action, user } an answer from a push notification
|
|
10
|
+
// { kind: "timeout" } the prompt's own timer ran out
|
|
11
|
+
// { kind: "cancel", reason } the scope that owned the prompt ended
|
|
12
|
+
//
|
|
13
|
+
// clientId is a per-connection label made here, not a credential; user is the
|
|
14
|
+
// authenticated user's id, or null in single-user mode. Prompt content never
|
|
15
|
+
// appears in a source.
|
|
16
|
+
|
|
17
|
+
var crypto = require("crypto");
|
|
18
|
+
var { logField } = require("./log-field");
|
|
19
|
+
|
|
20
|
+
function clientIdOf(ws) {
|
|
21
|
+
if (!ws) return null;
|
|
22
|
+
if (!ws._clagenticClientId) ws._clagenticClientId = "c-" + crypto.randomBytes(4).toString("hex");
|
|
23
|
+
return ws._clagenticClientId;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function userIdOf(user) {
|
|
27
|
+
return user && user.id !== undefined && user.id !== null ? String(user.id) : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function fromWs(ws) {
|
|
31
|
+
return { kind: "ws", clientId: clientIdOf(ws), user: userIdOf(ws && ws._clagenticUser) };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// req is the HTTP request the answer arrived on.
|
|
35
|
+
function fromPush(req, action) {
|
|
36
|
+
return { kind: "push", action: action, user: userIdOf(req && req._clagenticUser) };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function fromTimeout() {
|
|
40
|
+
return { kind: "timeout" };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function fromCancel(reason) {
|
|
44
|
+
return { kind: "cancel", reason: reason };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The source as log fields, "source=ws client=c-1a2b user=u1". A cancel's
|
|
48
|
+
// reason is its own field on the settle line, not repeated here.
|
|
49
|
+
function describe(source) {
|
|
50
|
+
if (!source) return "source=unspecified";
|
|
51
|
+
var out = "source=" + logField(source.kind);
|
|
52
|
+
if (source.clientId) out += " client=" + logField(source.clientId);
|
|
53
|
+
if (source.action) out += " action=" + logField(source.action);
|
|
54
|
+
if (source.kind === "ws" || source.kind === "push") out += " user=" + logField(source.user);
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = {
|
|
59
|
+
fromWs: fromWs,
|
|
60
|
+
fromPush: fromPush,
|
|
61
|
+
fromTimeout: fromTimeout,
|
|
62
|
+
fromCancel: fromCancel,
|
|
63
|
+
describe: describe,
|
|
64
|
+
clientIdOf: clientIdOf,
|
|
65
|
+
};
|
|
@@ -136,6 +136,15 @@
|
|
|
136
136
|
letter-spacing: 0.12em;
|
|
137
137
|
margin-bottom: 3px;
|
|
138
138
|
}
|
|
139
|
+
/* Whose prompt this is: wrapped, never cut off, because a clipped label is
|
|
140
|
+
the failure this line exists to fix. */
|
|
141
|
+
.notif-banner-label {
|
|
142
|
+
font-family: var(--font-mono, monospace);
|
|
143
|
+
font-size: 10.5px;
|
|
144
|
+
color: var(--accent);
|
|
145
|
+
margin-bottom: 3px;
|
|
146
|
+
overflow-wrap: anywhere;
|
|
147
|
+
}
|
|
139
148
|
.notif-banner-title {
|
|
140
149
|
font-weight: 500;
|
|
141
150
|
font-size: 13px;
|
|
@@ -544,6 +544,24 @@ button.top-bar-pill.pill-accent:hover { background: color-mix(in srgb, var(--acc
|
|
|
544
544
|
|
|
545
545
|
#skill-install-modal.hidden { display: none; }
|
|
546
546
|
|
|
547
|
+
#session-grants-modal {
|
|
548
|
+
position: fixed;
|
|
549
|
+
inset: 0;
|
|
550
|
+
z-index: 300;
|
|
551
|
+
display: flex;
|
|
552
|
+
align-items: center;
|
|
553
|
+
justify-content: center;
|
|
554
|
+
}
|
|
555
|
+
.session-grants-dialog { max-width: 520px; }
|
|
556
|
+
.session-grants-title { font-weight: 600; font-size: 16px; margin-bottom: 12px; color: var(--text); }
|
|
557
|
+
.session-grants-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; max-height: 50vh; overflow-y: auto; }
|
|
558
|
+
.session-grants-row { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; background: rgba(var(--overlay-rgb), 0.05); border: 1px solid var(--border); }
|
|
559
|
+
.session-grants-whole { border-color: var(--warning, #f39c12); }
|
|
560
|
+
.session-grants-text { flex: 1; min-width: 0; font-size: 13px; color: var(--text); overflow-wrap: anywhere; }
|
|
561
|
+
.session-grants-revoke { flex-shrink: 0; background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--text); cursor: pointer; padding: 4px 10px; font-size: 12px; }
|
|
562
|
+
.session-grants-revoke:disabled { opacity: 0.5; cursor: default; }
|
|
563
|
+
.session-grants-empty { font-size: 13px; color: var(--text-muted); }
|
|
564
|
+
|
|
547
565
|
.skill-install-dialog { max-width: 460px; padding: 28px 32px; }
|
|
548
566
|
.skill-install-title { font-weight: 600; font-size: 17px; margin-bottom: 8px; color: var(--text); }
|
|
549
567
|
.skill-install-reason { color: var(--text-secondary); font-size: 14px; line-height: 1.5; margin-bottom: 18px; }
|
|
@@ -618,6 +618,13 @@
|
|
|
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
|
+
.prompt-label {
|
|
622
|
+
font-family: var(--font-mono, monospace);
|
|
623
|
+
font-size: 11px;
|
|
624
|
+
color: var(--accent);
|
|
625
|
+
margin-bottom: 4px;
|
|
626
|
+
overflow-wrap: anywhere;
|
|
627
|
+
}
|
|
621
628
|
|
|
622
629
|
/* An ask that must open on No: the approve choices lose their primary
|
|
623
630
|
styling and the decline choice leads. */
|
|
@@ -65,6 +65,7 @@ import { handleRateLimitEvent, updateRateLimitUsage, addScheduledMessageBubble,
|
|
|
65
65
|
import { handleRemoteCursorMove, handleRemoteCursorLeave, handleRemoteSelection, clearRemoteCursors } from './app-cursors.js';
|
|
66
66
|
import { showLoopBanner, updateLoopBanner, updateLoopInputVisibility, updateLoopPendingBanner, showRalphApprovalBar, updateRalphApprovalStatus, openRalphPreviewModal, showExecModal, updateExecModalStatus } from './app-loop-ui.js';
|
|
67
67
|
import { handleSkillInstallWs } from './app-skills-install.js';
|
|
68
|
+
import { handleSessionGrants } from './session-grants.js';
|
|
68
69
|
import { handleNotificationsState, handleNotificationCreated, handleNotificationDismissed, handleNotificationDismissedAll, showUpdateBanner } from './app-notifications.js';
|
|
69
70
|
import { handleMentionStart, handleMentionActivity, handleMentionStream, handleMentionDone, handleMentionError, renderMentionUser, renderMentionResponse, renderUserMention } from './mention.js';
|
|
70
71
|
import { handleTeamState, handleTeamMemberUpdate, handleTeamTaskUpdate, handleTeamMessage as handleTeamMsg, handleTeamGone } from './team-panel.js';
|
|
@@ -1477,6 +1478,8 @@ registerHandlers({
|
|
|
1477
1478
|
addSystemMessage("Error: " + msg.text, true);
|
|
1478
1479
|
},
|
|
1479
1480
|
|
|
1481
|
+
session_grants: handleSessionGrants,
|
|
1482
|
+
|
|
1480
1483
|
// --- Notifications ---
|
|
1481
1484
|
notifications_state: handleNotificationsState,
|
|
1482
1485
|
notification_created: handleNotificationCreated,
|
|
@@ -14,6 +14,7 @@ import { userAvatarUrl } from './avatar.js';
|
|
|
14
14
|
import { openTerminal } from './terminal.js';
|
|
15
15
|
import { askWording } from './prompt-kinds/index.js';
|
|
16
16
|
import { wirePromptBanner, restoreUnconfirmedBanners, bannerActions } from './prompt-banner.js';
|
|
17
|
+
import { promptLabelHtml } from './prompt-label.js';
|
|
17
18
|
|
|
18
19
|
// The server dismisses a prompt's banner once the prompt settles, however it
|
|
19
20
|
// was answered.
|
|
@@ -139,10 +140,14 @@ function showBanner(notif, autoDismissMs) {
|
|
|
139
140
|
'</div>';
|
|
140
141
|
}
|
|
141
142
|
|
|
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.
|
|
142
146
|
banner.innerHTML =
|
|
143
147
|
'<div class="notif-banner-icon">' + iconHtmlStr + '</div>' +
|
|
144
148
|
'<div class="notif-banner-body">' +
|
|
145
149
|
(projectName ? '<div class="notif-banner-project">' + escapeHtml(projectName) + '</div>' : '') +
|
|
150
|
+
(isPermission ? promptLabelHtml(notif.meta.label) : '') +
|
|
146
151
|
'<div class="notif-banner-title">' + escapeHtml(notif.title) + '</div>' +
|
|
147
152
|
(notif.body ? '<div class="notif-banner-text">' + escapeHtml(notif.body) + '</div>' : '') +
|
|
148
153
|
actionsHtml +
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// build-notice-gate.js — decides what the diagnostics list does with the
|
|
2
|
+
// "newer build installed" notice, which the daemon replays to every client that
|
|
3
|
+
// connects (once per project connection) and refreshes while the build is stale.
|
|
4
|
+
//
|
|
5
|
+
// Pure state and rules, no DOM: lib/public/modules/diagnostics.js asks it what
|
|
6
|
+
// to do and does it. The rules:
|
|
7
|
+
// - one notice per running/installed build pair; an identical one never stacks;
|
|
8
|
+
// - a different pair replaces the held one, or retracts it when the incoming
|
|
9
|
+
// pair is itself quiet (nothing new is shown until the cooldown passes);
|
|
10
|
+
// - once the operator has closed the notice (the toast, or the panel entry),
|
|
11
|
+
// the same pair stays quiet until the cooldown has passed.
|
|
12
|
+
|
|
13
|
+
export var BUILD_NOTICE_SOURCE = 'build-update';
|
|
14
|
+
export var BUILD_NOTICE_ACTION = 'restart_for_build_update';
|
|
15
|
+
export var DEFAULT_COOLDOWN_MS = 60 * 60 * 1000;
|
|
16
|
+
|
|
17
|
+
/** The pair a standing notice is about, or null when `msg` is not that notice. */
|
|
18
|
+
export function noticeKeyOf(msg) {
|
|
19
|
+
if (!msg || msg.source !== BUILD_NOTICE_SOURCE) return null;
|
|
20
|
+
if (!msg.actionable || msg.actionable.action !== BUILD_NOTICE_ACTION) return null;
|
|
21
|
+
var b = msg.buildUpdate;
|
|
22
|
+
if (!b || !b.loadedBuildSha || !b.installedBuildSha) return null;
|
|
23
|
+
return b.loadedBuildSha + ':' + b.installedBuildSha;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The daemon-configured cooldown carried on the notice, else the default. */
|
|
27
|
+
export function cooldownOf(msg) {
|
|
28
|
+
var ms = msg && msg.noticeCooldownMs;
|
|
29
|
+
return typeof ms === 'number' && isFinite(ms) && ms >= 0 ? ms : DEFAULT_COOLDOWN_MS;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function createNoticeGate() {
|
|
33
|
+
// key -> {at, entryGone}. entryGone: the operator removed the panel entry too,
|
|
34
|
+
// so the notice must not come back at all, not just without a toast.
|
|
35
|
+
var closed = Object.create(null);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
/**
|
|
39
|
+
* @param {object} s
|
|
40
|
+
* @param {string} s.key — noticeKeyOf(msg)
|
|
41
|
+
* @param {?string} s.heldKey — key of the notice already in the list, or null
|
|
42
|
+
* @param {boolean} s.toastOnScreen — a toast for the held notice is showing
|
|
43
|
+
* @param {number} s.now
|
|
44
|
+
* @param {number} s.cooldownMs
|
|
45
|
+
* @returns {{action: 'add'|'replace'|'retract'|'skip'|'retoast', toast: boolean}}
|
|
46
|
+
*/
|
|
47
|
+
decide: function (s) {
|
|
48
|
+
var rec = closed[s.key];
|
|
49
|
+
var quiet = rec !== undefined && s.now - rec.at < s.cooldownMs;
|
|
50
|
+
if (rec !== undefined && !quiet) delete closed[s.key];
|
|
51
|
+
|
|
52
|
+
if (s.heldKey === s.key) {
|
|
53
|
+
// Identical notice: never a second entry. After the cooldown the toast
|
|
54
|
+
// may come back if the operator had closed it.
|
|
55
|
+
if (rec !== undefined && !quiet && !s.toastOnScreen) return { action: 'retoast', toast: true };
|
|
56
|
+
return { action: 'skip', toast: false };
|
|
57
|
+
}
|
|
58
|
+
// A quiet current pair shows nothing, so a different held pair is stale
|
|
59
|
+
// and must go too: one current notice, never an obsolete one left visible.
|
|
60
|
+
if (quiet && s.heldKey) return { action: 'retract', toast: false };
|
|
61
|
+
if (quiet && rec.entryGone) return { action: 'skip', toast: false };
|
|
62
|
+
return { action: s.heldKey ? 'replace' : 'add', toast: !quiet };
|
|
63
|
+
},
|
|
64
|
+
toastClosed: function (key, now) {
|
|
65
|
+
if (!key) return;
|
|
66
|
+
var rec = closed[key];
|
|
67
|
+
closed[key] = { at: now, entryGone: rec ? rec.entryGone : false };
|
|
68
|
+
},
|
|
69
|
+
entryDismissed: function (key, now) {
|
|
70
|
+
if (key) closed[key] = { at: now, entryGone: true };
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|