@clagentic/console 1.12.0-beta.2 → 1.12.0-beta.3
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/LICENSES/README.md +5 -0
- package/bin/cli.js +4 -2
- package/lib/agent-roster-ws.js +84 -0
- package/lib/agent-roster.js +312 -0
- package/lib/auth-required-notify.js +42 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-notify.js +45 -0
- package/lib/build-update-offer.js +3 -4
- package/lib/build-update-standing.js +34 -14
- package/lib/cli/session-subcommands.js +26 -8
- package/lib/client-address.js +44 -0
- package/lib/daemon.js +25 -10
- package/lib/idle-compaction-setting.js +203 -0
- package/lib/mcp-bridge-credential.js +41 -0
- package/lib/notification-prefs.js +16 -22
- package/lib/notify/core.js +53 -18
- package/lib/notify/payload.js +2 -3
- package/lib/notify/type-registry.js +17 -0
- package/lib/notify/types.js +38 -1
- package/lib/outbound-access.js +12 -1
- package/lib/outbound-entry.js +8 -1
- package/lib/project-connection.js +9 -8
- package/lib/project-filesystem.js +23 -0
- package/lib/project-loop.js +16 -19
- package/lib/project-notifications.js +68 -7
- package/lib/project-sessions.js +9 -0
- package/lib/project-user-mention.js +22 -34
- package/lib/project-user-message.js +208 -4
- package/lib/project-user-shell.js +298 -0
- package/lib/project.js +26 -4
- package/lib/prompt-answer.js +145 -0
- package/lib/prompt-expiry.js +50 -0
- package/lib/prompt-registry.js +24 -1
- package/lib/prompt-source.js +16 -0
- package/lib/public/app.js +31 -2
- package/lib/public/css/agent-messages.css +96 -0
- package/lib/public/css/agent-roster.css +93 -0
- package/lib/public/css/diagnostics.css +1 -1
- package/lib/public/css/input.css +20 -141
- package/lib/public/css/login-panel.css +73 -0
- package/lib/public/css/menus.css +2 -2
- package/lib/public/css/sidebar.css +11 -0
- package/lib/public/css/team-panel.css +1 -6
- package/lib/public/css/team-view.css +101 -0
- package/lib/public/css/title-bar.css +10 -0
- package/lib/public/css/user-shell.css +144 -0
- package/lib/public/index.html +41 -7
- package/lib/public/modules/agent-avatar-picker.js +162 -0
- package/lib/public/modules/agent-avatar.js +153 -0
- package/lib/public/modules/agent-messages.js +285 -0
- package/lib/public/modules/agent-roster.js +157 -0
- package/lib/public/modules/app-connection.js +12 -0
- package/lib/public/modules/app-messages.js +55 -16
- package/lib/public/modules/app-notifications.js +59 -29
- package/lib/public/modules/app-panels.js +26 -3
- package/lib/public/modules/app-rate-limit.js +8 -165
- package/lib/public/modules/app-rendering.js +22 -7
- package/lib/public/modules/collapsible-text.js +33 -18
- package/lib/public/modules/compaction-state.js +34 -0
- package/lib/public/modules/custom-icons.js +23 -5
- package/lib/public/modules/diagnostics.js +52 -55
- package/lib/public/modules/injected-identity.js +24 -21
- package/lib/public/modules/input.js +176 -15
- package/lib/public/modules/login-panel.js +136 -0
- package/lib/public/modules/login-parser.js +73 -0
- package/lib/public/modules/login-tab.js +66 -0
- package/lib/public/modules/notifications.js +9 -1
- package/lib/public/modules/notify-client.js +114 -21
- package/lib/public/modules/pending-term-request.js +30 -0
- package/lib/public/modules/project-icon.js +22 -2
- package/lib/public/modules/queued-button.js +11 -0
- package/lib/public/modules/scheduled-input-actions.js +12 -4
- package/lib/public/modules/scheduled-outbox.js +230 -0
- package/lib/public/modules/send-now.js +200 -0
- package/lib/public/modules/server-settings.js +47 -1
- package/lib/public/modules/shell-card.js +76 -0
- package/lib/public/modules/shell-line.js +49 -0
- package/lib/public/modules/shell-queue.js +253 -0
- package/lib/public/modules/shell-settings-controls.js +76 -0
- package/lib/public/modules/sidebar-mobile.js +3 -3
- package/lib/public/modules/sidebar-sessions.js +8 -0
- package/lib/public/modules/sidebar-users.js +5 -7
- package/lib/public/modules/team-panel.js +30 -88
- package/lib/public/modules/team-view.js +211 -0
- package/lib/public/modules/terminal-links.js +18 -0
- package/lib/public/modules/terminal.js +65 -4
- package/lib/public/modules/tools.js +19 -0
- package/lib/public/modules/user-shell.js +824 -0
- package/lib/public/notify-sw-logic.js +35 -83
- package/lib/public/notify-target.js +70 -10
- package/lib/public/style.css +5 -0
- package/lib/public/sw.js +7 -3
- package/lib/queued-chat.js +392 -0
- package/lib/scheduled-input/ws.js +67 -9
- package/lib/sdk-bridge.js +122 -43
- package/lib/sdk-message-processor.js +46 -39
- package/lib/server-auth.js +6 -4
- package/lib/server-dm.js +11 -20
- package/lib/server-settings.js +39 -1
- package/lib/server.js +83 -19
- package/lib/session-directory.js +33 -8
- package/lib/session-end.js +97 -0
- package/lib/session-input-ipc.js +26 -0
- package/lib/session-input.js +176 -9
- package/lib/session-resume.js +1 -0
- package/lib/session-settings-file.js +53 -0
- package/lib/sessions.js +49 -5
- package/lib/team-traffic-ws.js +68 -0
- package/lib/team-traffic.js +318 -0
- package/lib/usage-store.js +7 -0
- package/lib/user-shell-settings.js +105 -0
- package/lib/ws-schema.js +27 -4
- package/lib/yoke/adapters/claude-capabilities.js +2 -0
- package/lib/yoke/adapters/claude-vendor.js +6 -0
- package/lib/yoke/adapters/claude-worker.js +39 -11
- package/lib/yoke/adapters/claude.js +218 -6
- package/lib/yoke/adapters/codex-capabilities.js +6 -1
- package/lib/yoke/adapters/codex-user-shell.js +265 -0
- package/lib/yoke/adapters/codex-vendor.js +7 -0
- package/lib/yoke/adapters/codex.js +186 -52
- package/lib/yoke/codex-app-server.js +8 -2
- package/lib/yoke/interface.js +54 -1
- package/lib/yoke/mcp-bridge-server.js +12 -8
- package/lib/yoke/registry.js +32 -0
- package/lib/yoke/user-shell.js +224 -0
- package/package.json +1 -1
- package/lib/public/modules/build-notice-gate.js +0 -73
package/lib/session-input.js
CHANGED
|
@@ -20,12 +20,17 @@ var sessionResume = require("./session-resume");
|
|
|
20
20
|
var { logField, logText } = require("./log-field");
|
|
21
21
|
var { validateFrom, validateFromSession, senderFields, forClient, stampRecord, newMessageId, isInjected, consoleTurnEntry } = require("./injected-sender");
|
|
22
22
|
var senderRef = require("./sender-ref");
|
|
23
|
+
var { senderKey } = require("./agent-roster");
|
|
23
24
|
var { findNameHolder, releaseReapedHolders } = require("./session-name-holder");
|
|
24
25
|
var directory = require("./session-directory");
|
|
25
26
|
var permissionSettings = require("./permission-settings");
|
|
27
|
+
var { checkSettingsFile } = require("./session-settings-file");
|
|
26
28
|
var { checkPermissionMode } = require("./permission-mode-policy");
|
|
27
29
|
var { slugifyAgentName } = agentsModule;
|
|
28
30
|
var outboundEntry = require("./outbound-entry");
|
|
31
|
+
var sessionEnd = require("./session-end");
|
|
32
|
+
var promptSource = require("./prompt-source");
|
|
33
|
+
var promptAnswer = require("./prompt-answer");
|
|
29
34
|
|
|
30
35
|
// The result vocabulary reported to the caller. "error" is not a verdict on
|
|
31
36
|
// the request: delivery was attempted and failed, so a caller may retry.
|
|
@@ -43,6 +48,8 @@ var RESULT = Object.freeze({
|
|
|
43
48
|
REFUSED: "refused",
|
|
44
49
|
ERROR: "error",
|
|
45
50
|
BUSY: "busy",
|
|
51
|
+
ENDED: "ended",
|
|
52
|
+
ALREADY_ENDED: "already-ended",
|
|
46
53
|
});
|
|
47
54
|
|
|
48
55
|
// Initiators injected input may name. HUMAN is deliberately absent.
|
|
@@ -196,10 +203,17 @@ function present(value) {
|
|
|
196
203
|
// outboundLedger -> { record(entry) } the sender-side ledger
|
|
197
204
|
// (lib/outbound-ledger.js); default: none kept
|
|
198
205
|
// now() -> ms clock for ledger entries (default Date.now)
|
|
206
|
+
// onAutomationInjected -> called after a console-composed turn (a scheduled
|
|
207
|
+
// firing) is recorded on its target; such a turn has
|
|
208
|
+
// no ledger entry, so a live view hears of it here
|
|
209
|
+
// onAgentSeen(sighting) -> told of each injected sender that names an agent
|
|
210
|
+
// (the agent roster); read-only, its result is unused
|
|
199
211
|
function createSessionInput(deps) {
|
|
200
212
|
var getProject = deps.getProject;
|
|
201
213
|
var listProjects = deps.listProjects || function () { return []; };
|
|
202
214
|
var outboundLedger = deps.outboundLedger || null;
|
|
215
|
+
var onAutomationInjected = deps.onAutomationInjected || null;
|
|
216
|
+
var onAgentSeen = deps.onAgentSeen || null;
|
|
203
217
|
var clock = deps.now || Date.now;
|
|
204
218
|
|
|
205
219
|
function defaultAgentCatalog(project) {
|
|
@@ -238,8 +252,9 @@ function createSessionInput(deps) {
|
|
|
238
252
|
}
|
|
239
253
|
|
|
240
254
|
// Resolves --to to a console session. Returns { projectSlug, sessionId, via }
|
|
241
|
-
// or { refusal } (not-found, ambiguous or refused).
|
|
242
|
-
|
|
255
|
+
// or { refusal } (not-found, ambiguous or refused). holdsRequest, when given,
|
|
256
|
+
// names the one session by the prompt request it holds (answer-prompt).
|
|
257
|
+
function resolveAddressTarget(req, holdsRequest) {
|
|
243
258
|
var parsed = directory.parseAddress(req.to);
|
|
244
259
|
if (parsed.error) return { refusal: refused(parsed.error) };
|
|
245
260
|
if (req.projectSlug && req.projectSlug !== parsed.project) {
|
|
@@ -247,9 +262,12 @@ function createSessionInput(deps) {
|
|
|
247
262
|
}
|
|
248
263
|
var resolved = resolveProject(parsed.project);
|
|
249
264
|
if (resolved.refusal) return { refusal: resolved.refusal };
|
|
250
|
-
var found = directory.resolve(entriesOf(parsed.project, resolved.project), parsed);
|
|
265
|
+
var found = directory.resolve(entriesOf(parsed.project, resolved.project), parsed, holdsRequest);
|
|
251
266
|
if (found.none) {
|
|
252
|
-
|
|
267
|
+
var reason = holdsRequest === undefined
|
|
268
|
+
? "no session matches the address " + shown(req.to)
|
|
269
|
+
: "no session matching the address " + shown(req.to) + " holds the request " + shown(holdsRequest);
|
|
270
|
+
return { refusal: { ok: false, result: RESULT.NOT_FOUND, reason: reason, to: req.to } };
|
|
253
271
|
}
|
|
254
272
|
if (found.candidates) {
|
|
255
273
|
return {
|
|
@@ -340,10 +358,10 @@ function createSessionInput(deps) {
|
|
|
340
358
|
// Exactly one way of naming the target: sessionId (with projectSlug), to, or
|
|
341
359
|
// reply. Returns { projectSlug, sessionId, via } for to and reply, {} to leave
|
|
342
360
|
// the request as it is, or { refusal }.
|
|
343
|
-
function resolveSendTarget(req) {
|
|
361
|
+
function resolveSendTarget(req, holdsRequest) {
|
|
344
362
|
var named = ["sessionId", "to", "reply"].filter(function (k) { return present(req[k]); });
|
|
345
363
|
if (named.length > 1) return { refusal: refused("name the target one way only: sessionId, to or reply (given: " + named.join(", ") + ")") };
|
|
346
|
-
if (present(req.to)) return resolveAddressTarget(req);
|
|
364
|
+
if (present(req.to)) return resolveAddressTarget(req, holdsRequest);
|
|
347
365
|
if (present(req.reply)) return resolveReplyTarget(req);
|
|
348
366
|
return {};
|
|
349
367
|
}
|
|
@@ -366,7 +384,12 @@ function createSessionInput(deps) {
|
|
|
366
384
|
|
|
367
385
|
// The verb a result is logged under, as the ledger names it. Other verbs
|
|
368
386
|
// (listing, a scheduled firing) are not outbound calls of a sender.
|
|
369
|
-
var LEDGER_VERB = {
|
|
387
|
+
var LEDGER_VERB = {
|
|
388
|
+
open_session: outboundEntry.VERB.OPEN_SESSION,
|
|
389
|
+
send_session_input: outboundEntry.VERB.SEND_INPUT,
|
|
390
|
+
end_session: outboundEntry.VERB.END_SESSION,
|
|
391
|
+
answer_prompt: outboundEntry.VERB.ANSWER_PROMPT,
|
|
392
|
+
};
|
|
370
393
|
|
|
371
394
|
// A delivery, recorded where the history entry is, so both carry the same
|
|
372
395
|
// message id and sender.
|
|
@@ -394,7 +417,9 @@ function createSessionInput(deps) {
|
|
|
394
417
|
// A request that was not delivered (refused, not found, ambiguous, failed).
|
|
395
418
|
// A delivery already left its entry in recordInjected.
|
|
396
419
|
function ledgerOutcome(verb, req, out) {
|
|
397
|
-
if (!outboundLedger || !LEDGER_VERB[verb] || !out
|
|
420
|
+
if (!outboundLedger || !LEDGER_VERB[verb] || !out) return;
|
|
421
|
+
// A delivery already left its entry; an end and an answer leave theirs here.
|
|
422
|
+
if (out.ok === true && verb !== "end_session" && verb !== "answer_prompt") return;
|
|
398
423
|
req = req || {};
|
|
399
424
|
var init = resolveInitiator(req.initiator);
|
|
400
425
|
var initiator = init.initiator || null;
|
|
@@ -432,6 +457,10 @@ function createSessionInput(deps) {
|
|
|
432
457
|
var sender = senderOf(req, initiator);
|
|
433
458
|
for (var k in sender) entry[k] = sender[k];
|
|
434
459
|
ledgerDelivery(verb, project, session, req, initiator, messageId, sender);
|
|
460
|
+
var senderName = senderKey(sender);
|
|
461
|
+
if (onAgentSeen && senderName) {
|
|
462
|
+
onAgentSeen({ key: senderName, source: "sender", project: req.projectSlug, sessionId: String(session.localId) });
|
|
463
|
+
}
|
|
435
464
|
}
|
|
436
465
|
try {
|
|
437
466
|
project.sm.recordHistoryEntry(session, entry, true);
|
|
@@ -443,6 +472,10 @@ function createSessionInput(deps) {
|
|
|
443
472
|
} catch (e) {
|
|
444
473
|
console.error("[session-input] failed to record injected message:", e.message || e);
|
|
445
474
|
}
|
|
475
|
+
if (req.automation && onAutomationInjected) {
|
|
476
|
+
try { onAutomationInjected(); }
|
|
477
|
+
catch (e) { console.error("[session-input] automation hook failed:", messageOf(e)); }
|
|
478
|
+
}
|
|
446
479
|
}
|
|
447
480
|
|
|
448
481
|
// The OS user a turn starts as. A console automation also grants that user
|
|
@@ -612,6 +645,129 @@ function createSessionInput(deps) {
|
|
|
612
645
|
});
|
|
613
646
|
}
|
|
614
647
|
|
|
648
|
+
// The target of a verb that acts on one existing session (end-session,
|
|
649
|
+
// answer-prompt), named by id with its project or by --to, resolved as
|
|
650
|
+
// send-input resolves it. Fills req.projectSlug and req.sessionId in (req is
|
|
651
|
+
// the caller's own copy). holdsRequest (answer-prompt) makes --to pick the
|
|
652
|
+
// address match holding that request id instead of by tier. Returns
|
|
653
|
+
// { project } or { refusal }.
|
|
654
|
+
function resolveSessionTarget(req, holdsRequest) {
|
|
655
|
+
var named = ["sessionId", "to"].filter(function (k) { return present(req[k]); });
|
|
656
|
+
if (named.length > 1) return { refusal: refused("name the target one way only: sessionId or to (given: " + named.join(", ") + ")") };
|
|
657
|
+
var target = resolveSendTarget(Object.assign({}, req, { reply: undefined }), holdsRequest);
|
|
658
|
+
if (target.refusal) return { refusal: target.refusal };
|
|
659
|
+
if (target.via) {
|
|
660
|
+
req.projectSlug = target.projectSlug;
|
|
661
|
+
req.sessionId = target.sessionId;
|
|
662
|
+
}
|
|
663
|
+
if (typeof req.sessionId !== "string" || !req.sessionId) {
|
|
664
|
+
return { refusal: refused("sessionId must be a non-empty string") };
|
|
665
|
+
}
|
|
666
|
+
if (!sessionResume.isSafeSessionId(req.sessionId)) {
|
|
667
|
+
return { refusal: refused("unsafe session id " + shown(req.sessionId) + " refused") };
|
|
668
|
+
}
|
|
669
|
+
var resolved = resolveProject(req.projectSlug);
|
|
670
|
+
if (resolved.refusal) return { refusal: resolved.refusal };
|
|
671
|
+
return { project: resolved.project };
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// req: { projectSlug, sessionId | to, from?, fromSession?, reason? }
|
|
675
|
+
// Stands one live session down: its prompts settle as cancelled (reason
|
|
676
|
+
// ended), its turn is aborted and its query closed (lib/session-end.js).
|
|
677
|
+
// History is kept and the session resumes by id. Addressed as send-input
|
|
678
|
+
// addresses a session; a session that is not live, or only in the store, is
|
|
679
|
+
// already-ended, and nothing is resumed to be ended. Returns the result, or a
|
|
680
|
+
// Promise of it when the store must be asked.
|
|
681
|
+
function endSession(req) {
|
|
682
|
+
req = Object.assign({}, req);
|
|
683
|
+
var fromRefusal = checkFrom(req.from) || checkFromSession(req.fromSession);
|
|
684
|
+
if (fromRefusal) return fromRefusal;
|
|
685
|
+
var by = sessionEnd.sourceFor(validateFrom(req.from).from);
|
|
686
|
+
if (by.error) return refused(by.error);
|
|
687
|
+
var located = resolveSessionTarget(req);
|
|
688
|
+
if (located.refusal) return located.refusal;
|
|
689
|
+
var project = located.project;
|
|
690
|
+
|
|
691
|
+
function answer(result, session) {
|
|
692
|
+
var out = session ? describe(project, session) : {};
|
|
693
|
+
out.ok = result === RESULT.ENDED || result === RESULT.ALREADY_ENDED;
|
|
694
|
+
out.result = result;
|
|
695
|
+
out.endedBy = by.source;
|
|
696
|
+
return out;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
var live = findSession(project.sm, req.sessionId);
|
|
700
|
+
if (live) {
|
|
701
|
+
if (!senderRef.isLive(live)) return answer(RESULT.ALREADY_ENDED, live);
|
|
702
|
+
var ended = sessionEnd.endLiveSession({
|
|
703
|
+
session: live,
|
|
704
|
+
sm: project.sm,
|
|
705
|
+
send: project.send,
|
|
706
|
+
slug: req.projectSlug,
|
|
707
|
+
source: by.source,
|
|
708
|
+
reason: req.reason,
|
|
709
|
+
});
|
|
710
|
+
var out = answer(RESULT.ENDED, live);
|
|
711
|
+
out.agents = ended.agents;
|
|
712
|
+
out.failures = ended.failures;
|
|
713
|
+
if (ended.failures.length) out.ok = false;
|
|
714
|
+
return out;
|
|
715
|
+
}
|
|
716
|
+
// Only the console's own store is asked, and a stored session is never
|
|
717
|
+
// brought back just to be ended.
|
|
718
|
+
return sessionResume.sessionExistsInStore(project.sm, req.sessionId).then(function (exists) {
|
|
719
|
+
if (!exists) return { ok: false, result: RESULT.NOT_FOUND, reason: "no session " + shown(req.sessionId) + " in project " + shown(req.projectSlug) };
|
|
720
|
+
var stored = answer(RESULT.ALREADY_ENDED, null);
|
|
721
|
+
stored.sessionId = req.sessionId;
|
|
722
|
+
return stored;
|
|
723
|
+
}).catch(function (err) {
|
|
724
|
+
console.error("[session-input] end failed:", messageOf(err));
|
|
725
|
+
return { ok: false, result: RESULT.ERROR, retryable: !!(err && err.retryable), reason: "end failed: " + messageOf(err) };
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// req: { projectSlug, sessionId | to, requestId, decision, from?, fromSession? }
|
|
730
|
+
// Answers one pending prompt of a live session through the prompt registry
|
|
731
|
+
// (lib/prompt-answer.js), as a browser answer does. Addressed as end-session
|
|
732
|
+
// addresses a session, under the same trust (the daemon's OS user); the
|
|
733
|
+
// answer is recorded as caller:<from>, or user without --from. A session with
|
|
734
|
+
// no runtime holds no pending prompt, so a stored one is not-found and is
|
|
735
|
+
// never resumed. Returns the result, or a Promise of it when the store must
|
|
736
|
+
// be asked.
|
|
737
|
+
function answerPrompt(req) {
|
|
738
|
+
req = Object.assign({}, req);
|
|
739
|
+
var fromRefusal = checkFrom(req.from) || checkFromSession(req.fromSession);
|
|
740
|
+
if (fromRefusal) return fromRefusal;
|
|
741
|
+
var by = promptSource.callerSource(validateFrom(req.from).from, "an answer");
|
|
742
|
+
if (by.error) return refused(by.error);
|
|
743
|
+
if (typeof req.requestId !== "string" || !req.requestId) return refused("requestId must be a non-empty string");
|
|
744
|
+
if (typeof req.decision !== "string" || !req.decision) return refused("decision must be a non-empty string");
|
|
745
|
+
var located = resolveSessionTarget(req, req.requestId);
|
|
746
|
+
if (located.refusal) return located.refusal;
|
|
747
|
+
var project = located.project;
|
|
748
|
+
|
|
749
|
+
function answered(session) {
|
|
750
|
+
var out = describe(project, session);
|
|
751
|
+
return Object.assign(out, promptAnswer.answerPrompt({
|
|
752
|
+
sm: project.sm,
|
|
753
|
+
session: session,
|
|
754
|
+
requestId: req.requestId,
|
|
755
|
+
decision: req.decision,
|
|
756
|
+
source: by.source,
|
|
757
|
+
}));
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
var live = findSession(project.sm, req.sessionId);
|
|
761
|
+
if (live) return answered(live);
|
|
762
|
+
return sessionResume.sessionExistsInStore(project.sm, req.sessionId).then(function (exists) {
|
|
763
|
+
if (!exists) return { ok: false, result: RESULT.NOT_FOUND, reason: "no session " + shown(req.sessionId) + " in project " + shown(req.projectSlug), requestId: req.requestId, kind: null, source: by.source };
|
|
764
|
+
return { ok: false, result: RESULT.NOT_FOUND, reason: "session " + shown(req.sessionId) + " has no runtime, so no pending request", requestId: req.requestId, kind: null, source: by.source, sessionId: req.sessionId };
|
|
765
|
+
}).catch(function (err) {
|
|
766
|
+
console.error("[session-input] answer failed:", messageOf(err));
|
|
767
|
+
return { ok: false, result: RESULT.ERROR, retryable: !!(err && err.retryable), reason: "answer failed: " + messageOf(err) };
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
|
|
615
771
|
// The scheduled-input firing (lib/scheduled-input/service.js): one scheduled
|
|
616
772
|
// input delivered to the session its record names, through deliver(), the path
|
|
617
773
|
// send-input uses. Not an IPC verb and not reachable from a request body:
|
|
@@ -677,6 +833,15 @@ function createSessionInput(deps) {
|
|
|
677
833
|
}
|
|
678
834
|
options.sessionName = named.name;
|
|
679
835
|
}
|
|
836
|
+
if (present(req.settingsFile)) {
|
|
837
|
+
var checked = checkSettingsFile(req.settingsFile);
|
|
838
|
+
if (checked.error) return { refusal: refused(checked.error) };
|
|
839
|
+
// A bare test double without the vendor check is let through, as for the mode.
|
|
840
|
+
if (typeof project.supportsSettingsFileFor === "function" && !project.supportsSettingsFileFor({ vendor: options.vendor || null })) {
|
|
841
|
+
return { refusal: refused("this vendor does not take a settings file (--settings)") };
|
|
842
|
+
}
|
|
843
|
+
options.settingsFile = checked.path;
|
|
844
|
+
}
|
|
680
845
|
return { options: options };
|
|
681
846
|
}
|
|
682
847
|
|
|
@@ -729,7 +894,7 @@ function createSessionInput(deps) {
|
|
|
729
894
|
}
|
|
730
895
|
|
|
731
896
|
// req: { projectSlug, prompt, vendor?, agentName?, sessionVisibility?,
|
|
732
|
-
// permissionMode?, initiator?, contextNote?, cwd?, triggerId? }
|
|
897
|
+
// permissionMode?, settingsFile?, initiator?, contextNote?, cwd?, triggerId? }
|
|
733
898
|
// Returns the result, or a Promise of it when the first turn starts
|
|
734
899
|
// asynchronously (see settle()).
|
|
735
900
|
function openSession(req) {
|
|
@@ -841,6 +1006,8 @@ function createSessionInput(deps) {
|
|
|
841
1006
|
return {
|
|
842
1007
|
openSession: logged("open_session", neverThrows(openSession), ledgerOutcome),
|
|
843
1008
|
sendInput: logged("send_session_input", neverThrows(sendInput), ledgerOutcome),
|
|
1009
|
+
endSession: logged("end_session", neverThrows(endSession), ledgerOutcome),
|
|
1010
|
+
answerPrompt: logged("answer_prompt", neverThrows(answerPrompt), ledgerOutcome),
|
|
844
1011
|
listSessions: logged("list_sessions", neverThrows(listSessions)),
|
|
845
1012
|
fireScheduled: logged("fire_scheduled_input", neverThrows(fireScheduled)),
|
|
846
1013
|
};
|
package/lib/session-resume.js
CHANGED
|
@@ -129,6 +129,7 @@ function resumeStoredSession(deps, cliSessionId, opts) {
|
|
|
129
129
|
if (meta.sessionVisibility) resumeOpts.sessionVisibility = meta.sessionVisibility;
|
|
130
130
|
// The mode the session had; the session manager checks it before use.
|
|
131
131
|
if (typeof meta.permissionMode === "string" && meta.permissionMode) resumeOpts.permissionMode = meta.permissionMode;
|
|
132
|
+
if (typeof meta.settingsFile === "string" && meta.settingsFile) resumeOpts.settingsFile = meta.settingsFile;
|
|
132
133
|
// Sanitized so a crafted meta record cannot auto-approve a tool.
|
|
133
134
|
if (meta.allowedTools) resumeOpts.allowedTools = utils.sanitizeAllowedTools(meta.allowedTools);
|
|
134
135
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// A session's additive settings file: a user-supplied path handed to the
|
|
2
|
+
// vendor runtime as an extra settings source. The console checks the path and,
|
|
3
|
+
// when it must also pass a settings object of its own, combines the two; it
|
|
4
|
+
// does not interpret the file's content otherwise.
|
|
5
|
+
|
|
6
|
+
var fs = require("fs");
|
|
7
|
+
var path = require("path");
|
|
8
|
+
|
|
9
|
+
// Checks a path at open time and at every launch. Returns { path } or { error }.
|
|
10
|
+
// Readable is checked for the daemon's identity; a session run as another OS
|
|
11
|
+
// user is checked again by that user's runtime, which fails the turn if it
|
|
12
|
+
// cannot read the file.
|
|
13
|
+
function checkSettingsFile(file) {
|
|
14
|
+
if (typeof file !== "string" || !file) return { error: "settings file must be a path" };
|
|
15
|
+
var shown = JSON.stringify(file.slice(0, 200));
|
|
16
|
+
if (!path.isAbsolute(file)) return { error: "settings file " + shown + " is not an absolute path" };
|
|
17
|
+
var stat;
|
|
18
|
+
try {
|
|
19
|
+
stat = fs.statSync(file);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
return { error: "settings file " + shown + " does not exist or cannot be read" };
|
|
22
|
+
}
|
|
23
|
+
if (!stat.isFile()) return { error: "settings file " + shown + " is not a regular file" };
|
|
24
|
+
try {
|
|
25
|
+
fs.accessSync(file, fs.constants.R_OK);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return { error: "settings file " + shown + " is not readable" };
|
|
28
|
+
}
|
|
29
|
+
return { path: file };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The value for the runtime's single `settings` option. The option takes a
|
|
33
|
+
// path or one object, not both, so with no console-supplied object the path is
|
|
34
|
+
// passed as is; with one, the file is read and the two are shallow-merged,
|
|
35
|
+
// the console's keys winning (they are the console's own switches). Returns
|
|
36
|
+
// { settings } or { error } (an unreadable or non-object file fails closed).
|
|
37
|
+
function composeSettings(file, consoleSettings) {
|
|
38
|
+
var checked = checkSettingsFile(file);
|
|
39
|
+
if (checked.error) return checked;
|
|
40
|
+
if (!consoleSettings || Object.keys(consoleSettings).length === 0) return { settings: file };
|
|
41
|
+
var parsed;
|
|
42
|
+
try {
|
|
43
|
+
parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
return { error: "settings file " + JSON.stringify(file.slice(0, 200)) + " is not valid JSON" };
|
|
46
|
+
}
|
|
47
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
48
|
+
return { error: "settings file " + JSON.stringify(file.slice(0, 200)) + " is not a JSON object" };
|
|
49
|
+
}
|
|
50
|
+
return { settings: Object.assign({}, parsed, consoleSettings) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { checkSettingsFile: checkSettingsFile, composeSettings: composeSettings };
|
package/lib/sessions.js
CHANGED
|
@@ -16,6 +16,7 @@ var { findNameHolder } = require("./session-name-holder");
|
|
|
16
16
|
var { createSenderRecorder } = require("./message-sender-record");
|
|
17
17
|
var { checkPermissionMode, savedModeOrDefault } = require("./permission-mode-policy");
|
|
18
18
|
var { logField } = require("./log-field");
|
|
19
|
+
var queuedChat = require("./queued-chat");
|
|
19
20
|
|
|
20
21
|
// lr-2ea2a7: hard cap on how many history entries a session may hold in the
|
|
21
22
|
// heap array, regardless of isProcessing state. On-disk JSONL remains the
|
|
@@ -149,6 +150,7 @@ function createSessionManager(opts) {
|
|
|
149
150
|
getProjectName: opts.getProjectName,
|
|
150
151
|
getProjectSlug: opts.getProjectSlug,
|
|
151
152
|
getPushModule: opts.getPushModule,
|
|
153
|
+
getConfig: function () { return config.loadConfig(); },
|
|
152
154
|
});
|
|
153
155
|
var capabilitiesByVendor = null; // set by sdk-bridge after adapter init
|
|
154
156
|
var defaultVendor = null; // set by sdk-bridge
|
|
@@ -201,6 +203,8 @@ function createSessionManager(opts) {
|
|
|
201
203
|
// The session's own permission mode, so a resume or a restart keeps it
|
|
202
204
|
// instead of taking whatever the project default is by then.
|
|
203
205
|
if (session.permissionMode) metaObj.permissionMode = session.permissionMode;
|
|
206
|
+
// The session's additive settings file path, kept across resume and restart.
|
|
207
|
+
if (session.settingsFile) metaObj.settingsFile = session.settingsFile;
|
|
204
208
|
// Persist per-session "allow for session" tool grants (lr-8b2e) so they
|
|
205
209
|
// survive daemon restart / resume-by-cliSessionId rehydration instead of
|
|
206
210
|
// silently re-prompting. Only written when non-empty — grants that were
|
|
@@ -234,6 +238,10 @@ function createSessionManager(opts) {
|
|
|
234
238
|
// Which identity provider vouched for the session and at what grade. Only
|
|
235
239
|
// present when a provider is configured: a plain session has no such field.
|
|
236
240
|
if (session.identity) metaObj.identity = session.identity;
|
|
241
|
+
// Chat the agent has not taken in, and text handed back to no page yet: what a
|
|
242
|
+
// restart would otherwise lose (lib/queued-chat.js). Present only while any waits.
|
|
243
|
+
var queued = queuedChat.durable(session);
|
|
244
|
+
if (queued.length > 0) metaObj.queuedChat = queued;
|
|
237
245
|
return JSON.stringify(metaObj);
|
|
238
246
|
}
|
|
239
247
|
|
|
@@ -759,11 +767,21 @@ function createSessionManager(opts) {
|
|
|
759
767
|
var firstLine = "";
|
|
760
768
|
try {
|
|
761
769
|
fd = fs.openSync(path.join(sessionsDir, files[i]), "r");
|
|
770
|
+
// The meta line can be long (queued chat text rides on it), so read on
|
|
771
|
+
// until the line ends rather than stopping at a fixed size.
|
|
762
772
|
var buf = Buffer.alloc(4096);
|
|
763
|
-
var
|
|
764
|
-
var
|
|
765
|
-
var
|
|
766
|
-
|
|
773
|
+
var offset = 0;
|
|
774
|
+
var chunks = [];
|
|
775
|
+
var lineEnd = -1;
|
|
776
|
+
while (lineEnd === -1) {
|
|
777
|
+
var bytesRead = fs.readSync(fd, buf, 0, 4096, offset);
|
|
778
|
+
if (bytesRead === 0) break;
|
|
779
|
+
var piece = Buffer.from(buf.subarray(0, bytesRead));
|
|
780
|
+
lineEnd = piece.indexOf(10);
|
|
781
|
+
chunks.push(lineEnd === -1 ? piece : piece.subarray(0, lineEnd));
|
|
782
|
+
offset += bytesRead;
|
|
783
|
+
}
|
|
784
|
+
firstLine = Buffer.concat(chunks).toString("utf8");
|
|
767
785
|
} catch { continue; } finally {
|
|
768
786
|
if (fd !== undefined) try { fs.closeSync(fd); } catch (e) {}
|
|
769
787
|
}
|
|
@@ -835,6 +853,7 @@ function createSessionManager(opts) {
|
|
|
835
853
|
}
|
|
836
854
|
session.permissionMode = savedMode.mode;
|
|
837
855
|
}
|
|
856
|
+
if (typeof m.settingsFile === "string" && m.settingsFile) session.settingsFile = m.settingsFile;
|
|
838
857
|
if (m.ownerId) session.ownerId = m.ownerId;
|
|
839
858
|
session.sessionVisibility = m.sessionVisibility || "shared";
|
|
840
859
|
session.bookmarked = !!m.bookmarked;
|
|
@@ -860,6 +879,9 @@ function createSessionManager(opts) {
|
|
|
860
879
|
var identityRecord = require("./identity/record").sanitizeRecord(m.identity);
|
|
861
880
|
if (identityRecord) session.identity = identityRecord;
|
|
862
881
|
}
|
|
882
|
+
// Chat that was waiting when the daemon last stopped: no agent holds it now,
|
|
883
|
+
// so it is handed back the first time a page shows the session.
|
|
884
|
+
queuedChat.loadParked(session, m.queuedChat);
|
|
863
885
|
sessions.set(localId, session);
|
|
864
886
|
}
|
|
865
887
|
}
|
|
@@ -906,6 +928,7 @@ function createSessionManager(opts) {
|
|
|
906
928
|
title: s.title || "New Session",
|
|
907
929
|
active: isActive,
|
|
908
930
|
isProcessing: s.isProcessing,
|
|
931
|
+
compacting: !!s.compacting,
|
|
909
932
|
waiting: sessionLiveness.activityOf(s) === sessionLiveness.ACTIVITY.WAITING,
|
|
910
933
|
lastActivity: s.lastActivity || s.createdAt || 0,
|
|
911
934
|
loop: loop,
|
|
@@ -1005,6 +1028,7 @@ function createSessionManager(opts) {
|
|
|
1005
1028
|
vendor: (sessionOpts && sessionOpts.vendor) || null,
|
|
1006
1029
|
agentName: (sessionOpts && sessionOpts.agentName) || null,
|
|
1007
1030
|
sessionName: (sessionOpts && sessionOpts.sessionName) || null,
|
|
1031
|
+
settingsFile: (sessionOpts && sessionOpts.settingsFile) || null,
|
|
1008
1032
|
};
|
|
1009
1033
|
giveStartingMode(session, sessionOpts);
|
|
1010
1034
|
sessions.set(localId, session);
|
|
@@ -1253,7 +1277,7 @@ function createSessionManager(opts) {
|
|
|
1253
1277
|
// client hydrating from session_switched alone (no separate config_state
|
|
1254
1278
|
// round-trip needed) never has to fall back to guessing the shared
|
|
1255
1279
|
// project/global default — see effectiveSessionModel() above.
|
|
1256
|
-
_send({ type: "session_switched", id: localId, cliSessionId: session.cliSessionId || null, loop: session.loop || null, vendor: session.vendor || null, model: effectiveSessionModel(session, _instance), mode: effectiveSessionMode(session, _instance), hasHistory: (session._historyLoaded ? session.history.length > 0 : !!session.cliSessionId), capabilities: _vendorCaps, isProcessing: !!session.isProcessing, agentName: session.agentName || null });
|
|
1280
|
+
_send({ type: "session_switched", id: localId, cliSessionId: session.cliSessionId || null, loop: session.loop || null, vendor: session.vendor || null, model: effectiveSessionModel(session, _instance), mode: effectiveSessionMode(session, _instance), hasHistory: (session._historyLoaded ? session.history.length > 0 : !!session.cliSessionId), capabilities: _vendorCaps, isProcessing: !!session.isProcessing, agentName: session.agentName || null, compacting: !!session.compacting });
|
|
1257
1281
|
// Send vendor-specific slash commands
|
|
1258
1282
|
var _vendorCmds = slashCommandsByVendor[_sessionVendor] || slashCommands || [];
|
|
1259
1283
|
_send({ type: "slash_commands", commands: _vendorCmds, vendor: _sessionVendor });
|
|
@@ -1267,6 +1291,25 @@ function createSessionManager(opts) {
|
|
|
1267
1291
|
// Re-present every prompt still awaiting the operator.
|
|
1268
1292
|
prompts.pendingMessages(session).forEach(_send);
|
|
1269
1293
|
|
|
1294
|
+
// Chat the agent has not taken in. The page rebuilt its transcript and holds no
|
|
1295
|
+
// queued item of its own (a reload, a second tab), so it is told what is still
|
|
1296
|
+
// waiting and draws it again. Text that no page has been handed (the daemon
|
|
1297
|
+
// restarted, or the query closed with nobody viewing) goes back to the composer
|
|
1298
|
+
// of the first page that shows the session, once.
|
|
1299
|
+
queuedChat.pending(session).forEach(function (p) {
|
|
1300
|
+
var tracked = { type: "queued_message_tracked", messageId: p.messageId, text: p.text, pastes: p.pastes, imageCount: p.imageCount, unconfirmed: p.unconfirmed };
|
|
1301
|
+
// Send now was pressed: the page draws it as sending, never as queued again.
|
|
1302
|
+
if (p.sendNow) tracked.sendNow = true;
|
|
1303
|
+
_send(tracked);
|
|
1304
|
+
});
|
|
1305
|
+
var parkedChat = queuedChat.takeParked(session);
|
|
1306
|
+
if (parkedChat.length > 0) {
|
|
1307
|
+
parkedChat.forEach(function (p) {
|
|
1308
|
+
_send({ type: "queued_message_cancelled", messageId: p.messageId, result: "dropped", cause: p.cause, text: p.text, pastes: p.pastes, imageCount: p.imageCount });
|
|
1309
|
+
});
|
|
1310
|
+
saveSessionFile(session);
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1270
1313
|
// Re-send active mention indicator so returning clients restore the mate avatar state
|
|
1271
1314
|
if (session._mentionInProgress && session._mentionActiveMateId) {
|
|
1272
1315
|
_send({ type: "mention_processing", mateId: session._mentionActiveMateId, active: true });
|
|
@@ -1534,6 +1577,7 @@ function createSessionManager(opts) {
|
|
|
1534
1577
|
};
|
|
1535
1578
|
if (opts && opts.vendor) session.vendor = opts.vendor;
|
|
1536
1579
|
if (opts && opts.agentName) session.agentName = opts.agentName;
|
|
1580
|
+
if (opts && opts.settingsFile) session.settingsFile = opts.settingsFile;
|
|
1537
1581
|
// A session resumed from its stored record keeps the mode saved with it.
|
|
1538
1582
|
giveStartingMode(session, opts);
|
|
1539
1583
|
if (opts && opts.sessionName) {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// team-traffic-ws.js - the browser's side of the Team view's agent-messages
|
|
2
|
+
// section (lib/team-traffic.js).
|
|
3
|
+
//
|
|
4
|
+
// team_traffic_request c2s ask for the traffic this connection may see
|
|
5
|
+
// team_traffic s2c the answer: pairs, messages, pending, withheld
|
|
6
|
+
// team_traffic_changed s2c something landed; ask again. It carries no
|
|
7
|
+
// content, so what a connection may read is
|
|
8
|
+
// decided only when it asks, never by a broadcast.
|
|
9
|
+
|
|
10
|
+
var REQUEST = "team_traffic_request";
|
|
11
|
+
var CHANGED = "team_traffic_changed";
|
|
12
|
+
var DEFAULT_DELAY_MS = 200;
|
|
13
|
+
|
|
14
|
+
// deps: { service (createTeamTraffic() result, or null), sendTo(ws, obj) }
|
|
15
|
+
function createWsHandlers(deps) {
|
|
16
|
+
var service = deps.service;
|
|
17
|
+
|
|
18
|
+
// Answers true when the message was one of ours.
|
|
19
|
+
function handle(ws, msg) {
|
|
20
|
+
if (!msg || msg.type !== REQUEST) return false;
|
|
21
|
+
if (!service) {
|
|
22
|
+
deps.sendTo(ws, { type: "team_traffic", ok: false, result: "error", reason: "agent messages are not available here" });
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
var caller = { user: ws._clagenticUser || null, authenticated: ws._clagenticAuthenticated === true };
|
|
26
|
+
var answer;
|
|
27
|
+
try {
|
|
28
|
+
answer = service.snapshot(caller);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
console.error("[team-traffic] snapshot failed:", e && e.message ? e.message : e);
|
|
31
|
+
answer = { ok: false, result: "error", reason: "the agent messages could not be read" };
|
|
32
|
+
}
|
|
33
|
+
deps.sendTo(ws, Object.assign({ type: "team_traffic" }, answer));
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return { handle: handle };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// A burst of entries (a sender opening several sessions) makes one broadcast.
|
|
41
|
+
// deps: { broadcast(msg), delayMs?, build()? }. build() makes the message to
|
|
42
|
+
// send; the default is the content-free nudge. The agent roster reuses this
|
|
43
|
+
// burst-coalescing timer and sends its own content-free agent_roster_changed
|
|
44
|
+
// nudge, so each connection asks for the roster it may read.
|
|
45
|
+
function createNotifier(deps) {
|
|
46
|
+
var delay = typeof deps.delayMs === "number" ? deps.delayMs : DEFAULT_DELAY_MS;
|
|
47
|
+
var build = typeof deps.build === "function" ? deps.build : function () { return { type: CHANGED }; };
|
|
48
|
+
var timer = null;
|
|
49
|
+
|
|
50
|
+
function notify() {
|
|
51
|
+
if (timer) return;
|
|
52
|
+
timer = setTimeout(function () {
|
|
53
|
+
timer = null;
|
|
54
|
+
try { deps.broadcast(build()); }
|
|
55
|
+
catch (e) { console.error("[team-traffic] broadcast failed:", e && e.message ? e.message : e); }
|
|
56
|
+
}, delay);
|
|
57
|
+
if (typeof timer.unref === "function") timer.unref();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function stop() {
|
|
61
|
+
if (timer) clearTimeout(timer);
|
|
62
|
+
timer = null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { notify: notify, stop: stop };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = { createWsHandlers: createWsHandlers, createNotifier: createNotifier, REQUEST: REQUEST, CHANGED: CHANGED };
|