@clagentic/console 1.11.0 → 1.12.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/bin/cli.js +14 -2
- package/lib/build-changes.js +8 -2
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +31 -7
- package/lib/claude-settings-env.js +142 -0
- package/lib/cli/arg-validation.js +1 -1
- package/lib/cli/duration.js +27 -0
- package/lib/cli/ipc-subcommands.js +26 -0
- package/lib/cli/schedule-input-subcommands.js +1 -22
- package/lib/cli/session-subcommands.js +38 -7
- package/lib/daemon.js +26 -0
- package/lib/notification-prefs.js +257 -0
- package/lib/notify/core.js +175 -0
- package/lib/notify/index.js +31 -0
- package/lib/notify/live-prompts.js +36 -0
- package/lib/notify/payload.js +63 -0
- package/lib/notify/target.js +5 -0
- package/lib/notify/type-registry.js +64 -0
- package/lib/notify/types.js +20 -0
- package/lib/open-sockets.js +27 -0
- package/lib/outbound-access.js +74 -0
- package/lib/outbound-entry.js +109 -0
- package/lib/outbound-ledger.js +306 -0
- package/lib/outbound-query.js +153 -0
- package/lib/pending-prompts.js +31 -16
- package/lib/project-connection.js +40 -1
- package/lib/project-filesystem.js +20 -5
- package/lib/project-http.js +9 -1
- package/lib/project-loop.js +25 -13
- package/lib/project-notifications.js +206 -42
- package/lib/project-prompt-responses.js +1 -1
- package/lib/project-sessions.js +30 -1
- package/lib/project.js +15 -1
- package/lib/prompt-registry.js +92 -24
- package/lib/prompt-reminders.js +282 -0
- package/lib/prompt-source.js +43 -8
- package/lib/public/app.js +1 -0
- package/lib/public/css/diagnostics.css +28 -0
- package/lib/public/css/home-hub.css +12 -0
- package/lib/public/css/icon-strip.css +9 -0
- package/lib/public/css/input.css +93 -0
- package/lib/public/css/menus.css +22 -0
- package/lib/public/css/mobile-nav.css +11 -0
- package/lib/public/css/server-settings.css +24 -0
- package/lib/public/css/sidebar.css +24 -0
- package/lib/public/index.html +6 -0
- package/lib/public/modules/activity-state.js +20 -4
- package/lib/public/modules/app-connection.js +22 -5
- package/lib/public/modules/app-header.js +2 -0
- package/lib/public/modules/app-messages.js +6 -2
- package/lib/public/modules/app-notifications.js +65 -40
- package/lib/public/modules/app-projects.js +3 -1
- package/lib/public/modules/app-rate-limit.js +12 -6
- package/lib/public/modules/app-rendering.js +26 -3
- package/lib/public/modules/build-update-sessions.js +81 -0
- package/lib/public/modules/collapsible-text.js +77 -0
- package/lib/public/modules/diagnostics.js +9 -2
- package/lib/public/modules/env-shadow-notice.js +34 -0
- package/lib/public/modules/keep-alive.js +66 -0
- package/lib/public/modules/notification-prefs.js +151 -0
- package/lib/public/modules/notify-client.js +153 -0
- package/lib/public/modules/project-settings.js +5 -0
- package/lib/public/modules/prompt-reminders-setting.js +13 -0
- package/lib/public/modules/prompt-state.js +3 -3
- package/lib/public/modules/prompts.js +1 -1
- package/lib/public/modules/server-settings.js +3 -0
- package/lib/public/modules/sidebar-mobile.js +8 -0
- package/lib/public/modules/sidebar-sessions.js +27 -0
- package/lib/public/modules/terminal-links.js +175 -0
- package/lib/public/modules/terminal.js +19 -103
- package/lib/public/notify-sw-logic.js +300 -0
- package/lib/public/notify-target.js +97 -0
- package/lib/public/sw.js +15 -62
- package/lib/push-audience.js +84 -0
- package/lib/push.js +87 -20
- package/lib/runtime-env.js +1 -0
- package/lib/sdk-bridge.js +83 -36
- package/lib/sdk-message-processor.js +148 -49
- package/lib/sender-ref.js +3 -0
- package/lib/server.js +80 -4
- package/lib/session-directory.js +6 -4
- package/lib/session-input-ipc.js +11 -1
- package/lib/session-input.js +95 -14
- package/lib/session-liveness.js +53 -0
- package/lib/session-reclaim.js +37 -2
- package/lib/sessions.js +58 -4
- package/lib/usage-store.js +403 -0
- package/lib/vendor-auth.js +33 -2
- package/lib/ws-schema.js +13 -2
- package/lib/yoke/adapters/claude-vendor.js +11 -1
- package/lib/yoke/adapters/claude.js +17 -0
- package/lib/yoke/adapters/codex.js +5 -1
- package/lib/yoke/auth-checks.js +17 -2
- package/lib/yoke/index.js +21 -3
- package/lib/yoke/provider-credentials.js +24 -0
- package/lib/yoke/registry.js +8 -1
- package/package.json +2 -2
- package/scripts/check-test-count.js +14 -0
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
var usersModule = require("./users");
|
|
2
|
+
var { pushForSession } = require("./push-audience");
|
|
3
|
+
var { notifyFor } = require("./notify");
|
|
2
4
|
var { discoverWorkflows } = require("./sdk-workflow-discovery");
|
|
3
5
|
var { buildEnrichedSlashCommands } = require("./sdk-slash-enrichment");
|
|
4
6
|
var { promptsFor } = require("./prompt-registry");
|
|
5
7
|
var sessionActivity = require("./session-activity");
|
|
6
8
|
var yokeRegistry = require("./yoke").registry;
|
|
9
|
+
var usageStore = require("./usage-store");
|
|
10
|
+
|
|
7
11
|
var { authRequiredFacts } = require("./vendor-auth");
|
|
8
12
|
var sessionReclaim = require("./session-reclaim");
|
|
9
13
|
var { withPromptLabel } = require("./prompt-label");
|
|
10
14
|
var { isAgentDispatchTool } = require("./agent-dispatch-tool");
|
|
11
15
|
var { bumpLastActivity } = require("./activity-clock");
|
|
12
16
|
|
|
17
|
+
// Only the Claude CLI is known to report rate limits on change alone; for any
|
|
18
|
+
// other vendor the absence of an event says nothing about the value.
|
|
19
|
+
function confirmsUsageByResult(vendor) {
|
|
20
|
+
return vendor === "claude";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Only a successful result counts as confirmation: a failed or interrupted turn
|
|
24
|
+
// is weak evidence that the CLI saw a fresh rate-limit response.
|
|
25
|
+
function isSuccessfulResult(parsed) {
|
|
26
|
+
return !!parsed && parsed.subtype === "success";
|
|
27
|
+
}
|
|
28
|
+
|
|
13
29
|
// Source names of the activity tokens an agent with the activityTokens
|
|
14
30
|
// trait holds for its own tool and thinking blocks.
|
|
15
31
|
var TOOL_ACTIVITY_SOURCE = "agent-tool";
|
|
@@ -22,6 +38,20 @@ function sessionHasTrait(session, trait) {
|
|
|
22
38
|
return yokeRegistry.traitOf(session.vendor, trait);
|
|
23
39
|
}
|
|
24
40
|
|
|
41
|
+
function formatTokens(n) {
|
|
42
|
+
return n >= 1000 ? Math.round(n / 1000) + "k" : String(n);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function compactionNoticeText(ev) {
|
|
46
|
+
var text = "Context compacted (" + (ev.trigger === "manual" ? "manual" : "automatic") + ")";
|
|
47
|
+
if (typeof ev.preTokens === "number" && typeof ev.postTokens === "number") {
|
|
48
|
+
text += ": " + formatTokens(ev.preTokens) + " to " + formatTokens(ev.postTokens) + " tokens";
|
|
49
|
+
} else if (typeof ev.preTokens === "number") {
|
|
50
|
+
text += ": was " + formatTokens(ev.preTokens) + " tokens";
|
|
51
|
+
}
|
|
52
|
+
return text + ".";
|
|
53
|
+
}
|
|
54
|
+
|
|
25
55
|
function attachMessageProcessor(ctx) {
|
|
26
56
|
var sm = ctx.sm;
|
|
27
57
|
var send = ctx.send;
|
|
@@ -66,6 +96,48 @@ function attachMessageProcessor(ctx) {
|
|
|
66
96
|
session.taskIdMap = next;
|
|
67
97
|
}
|
|
68
98
|
|
|
99
|
+
// Whether a tool_result block is the launch acknowledgement of a tracked
|
|
100
|
+
// background Task. The discriminator is the SDK's structured tool output
|
|
101
|
+
// (parsed.asyncLaunch, from tool_use_result.status "async_launched"), never
|
|
102
|
+
// the result text. When both sides name the agent id they must agree, so a
|
|
103
|
+
// launch of one agent cannot be mistaken for the ack of another.
|
|
104
|
+
function isBackgroundLaunchAck(session, parsed, toolUseId) {
|
|
105
|
+
if (!parsed.asyncLaunch) return false;
|
|
106
|
+
if (!promptsFor(sm).isTaskTracked(session, toolUseId)) return false;
|
|
107
|
+
var knownAgentId = session.taskIdMap ? session.taskIdMap[toolUseId] : null;
|
|
108
|
+
return !(parsed.asyncLaunch.agentId && knownAgentId && parsed.asyncLaunch.agentId !== knownAgentId);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function buildToolResultMsg(block) {
|
|
112
|
+
var resultText = "";
|
|
113
|
+
var resultImages = [];
|
|
114
|
+
if (typeof block.content === "string") {
|
|
115
|
+
resultText = block.content;
|
|
116
|
+
} else if (Array.isArray(block.content)) {
|
|
117
|
+
resultText = block.content
|
|
118
|
+
.filter(function(c) { return c.type === "text"; })
|
|
119
|
+
.map(function(c) { return c.text; })
|
|
120
|
+
.join("\n");
|
|
121
|
+
for (var ri = 0; ri < block.content.length; ri++) {
|
|
122
|
+
var rc = block.content[ri];
|
|
123
|
+
if (rc.type === "image" && rc.source) {
|
|
124
|
+
resultImages.push({
|
|
125
|
+
mediaType: rc.source.media_type,
|
|
126
|
+
data: rc.source.data,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
var msg = {
|
|
132
|
+
type: "tool_result",
|
|
133
|
+
id: block.tool_use_id,
|
|
134
|
+
content: resultText,
|
|
135
|
+
is_error: block.is_error || false,
|
|
136
|
+
};
|
|
137
|
+
if (resultImages.length > 0) msg.images = resultImages;
|
|
138
|
+
return msg;
|
|
139
|
+
}
|
|
140
|
+
|
|
69
141
|
function sendToSession(session, obj) {
|
|
70
142
|
sm.sendToSession(session, obj);
|
|
71
143
|
}
|
|
@@ -138,6 +210,20 @@ function attachMessageProcessor(ctx) {
|
|
|
138
210
|
// rather than either fully retiring session.isProcessing (too large a diff
|
|
139
211
|
// for this pass) or leaving this specific site unconditionally wrong (the
|
|
140
212
|
// one residual this task exists to fix).
|
|
213
|
+
// A turn's 'result' is the boundary after which no tool call of that turn can
|
|
214
|
+
// still be running; only a tracked background agent outlives it. A tool call
|
|
215
|
+
// that never got its tool_result (denied, or cut off in a query that stays
|
|
216
|
+
// open across turns) left a current-generation token that nothing else
|
|
217
|
+
// releases before the next query, and the re-derivation below then reported
|
|
218
|
+
// an idle session as running a turn on every surface that reads the flag.
|
|
219
|
+
function releaseTurnActivity(session) {
|
|
220
|
+
var live = session.activeTaskToolIds || {};
|
|
221
|
+
var sources = sessionActivity.listActiveSources(session);
|
|
222
|
+
for (var i = 0; i < sources.length; i++) {
|
|
223
|
+
if (!live[sources[i].token]) releaseActivity(session, sources[i].token);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
141
227
|
function setIsProcessingFromRegistry(session) {
|
|
142
228
|
session.isProcessing = sessionActivity.isSessionActive(session);
|
|
143
229
|
}
|
|
@@ -315,7 +401,7 @@ function attachMessageProcessor(ctx) {
|
|
|
315
401
|
}
|
|
316
402
|
if (parsed.model) {
|
|
317
403
|
sm.currentModel = sm.currentModel || sm._savedDefaultModel || parsed.model;
|
|
318
|
-
var initVendor =
|
|
404
|
+
var initVendor = usageStore.usageVendorFor(session, adapter);
|
|
319
405
|
send({
|
|
320
406
|
type: "model_info",
|
|
321
407
|
model: sm.currentModel,
|
|
@@ -504,19 +590,16 @@ function attachMessageProcessor(ctx) {
|
|
|
504
590
|
|
|
505
591
|
if (pushModule && block.name === "AskUserQuestion" && input.questions) {
|
|
506
592
|
var q = input.questions[0];
|
|
507
|
-
|
|
508
|
-
|
|
593
|
+
// Content carries prompt text: owner only, never a blind broadcast.
|
|
594
|
+
// The prompt's id is the tool call's id.
|
|
595
|
+
notifyFor(pushModule).notify("ask_user", {
|
|
509
596
|
slug: slug,
|
|
597
|
+
sessionId: session.localId,
|
|
598
|
+
requestId: block.id,
|
|
599
|
+
}, {
|
|
510
600
|
title: "Claude has a question",
|
|
511
601
|
body: withPromptLabel(promptsFor(sm).labelFor(session, block.id), q ? q.question : "Waiting for your response"),
|
|
512
|
-
|
|
513
|
-
};
|
|
514
|
-
// Route to session owner only — content carries prompt text.
|
|
515
|
-
if (session.ownerId && pushModule.sendPushToUser) {
|
|
516
|
-
pushModule.sendPushToUser(session.ownerId, _askPayload);
|
|
517
|
-
} else {
|
|
518
|
-
pushModule.sendPush(_askPayload);
|
|
519
|
-
}
|
|
602
|
+
}, { ownerId: session.ownerId });
|
|
520
603
|
}
|
|
521
604
|
} else if (block && block.type === "thinking") {
|
|
522
605
|
var duration = block.startTime ? (Date.now() - block.startTime) / 1000 : 0;
|
|
@@ -569,6 +652,15 @@ function attachMessageProcessor(ctx) {
|
|
|
569
652
|
for (var i = 0; i < content.length; i++) {
|
|
570
653
|
var block = content[i];
|
|
571
654
|
if (block.type === "tool_result" && !session.sentToolResults[block.tool_use_id]) {
|
|
655
|
+
// The acknowledgement of a background Task is its launch: the agent
|
|
656
|
+
// runs on, and its own terminal task_notification (or the query
|
|
657
|
+
// ending) is what ends tracking and releases its activity token.
|
|
658
|
+
if (isBackgroundLaunchAck(session, parsed, block.tool_use_id)) {
|
|
659
|
+
sessionReclaim.noteBackgroundLaunch(session, block.tool_use_id);
|
|
660
|
+
session.sentToolResults[block.tool_use_id] = true;
|
|
661
|
+
sendAndRecord(session, buildToolResultMsg(block));
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
572
664
|
// A tracked Task's result means its sub-agent is done.
|
|
573
665
|
var resultPrompts = promptsFor(sm);
|
|
574
666
|
if (resultPrompts.isTaskTracked(session, block.tool_use_id)) {
|
|
@@ -594,34 +686,8 @@ function attachMessageProcessor(ctx) {
|
|
|
594
686
|
// released by task_notification), so calling it unconditionally
|
|
595
687
|
// for every tool_result is always safe.
|
|
596
688
|
releaseActivity(session, block.tool_use_id);
|
|
597
|
-
var resultText = "";
|
|
598
|
-
var resultImages = [];
|
|
599
|
-
if (typeof block.content === "string") {
|
|
600
|
-
resultText = block.content;
|
|
601
|
-
} else if (Array.isArray(block.content)) {
|
|
602
|
-
resultText = block.content
|
|
603
|
-
.filter(function(c) { return c.type === "text"; })
|
|
604
|
-
.map(function(c) { return c.text; })
|
|
605
|
-
.join("\n");
|
|
606
|
-
for (var ri = 0; ri < block.content.length; ri++) {
|
|
607
|
-
var rc = block.content[ri];
|
|
608
|
-
if (rc.type === "image" && rc.source) {
|
|
609
|
-
resultImages.push({
|
|
610
|
-
mediaType: rc.source.media_type,
|
|
611
|
-
data: rc.source.data,
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
689
|
session.sentToolResults[block.tool_use_id] = true;
|
|
617
|
-
|
|
618
|
-
type: "tool_result",
|
|
619
|
-
id: block.tool_use_id,
|
|
620
|
-
content: resultText,
|
|
621
|
-
is_error: block.is_error || false,
|
|
622
|
-
};
|
|
623
|
-
if (resultImages.length > 0) toolResultMsg.images = resultImages;
|
|
624
|
-
sendAndRecord(session, toolResultMsg);
|
|
690
|
+
sendAndRecord(session, buildToolResultMsg(block));
|
|
625
691
|
}
|
|
626
692
|
}
|
|
627
693
|
}
|
|
@@ -639,6 +705,7 @@ function attachMessageProcessor(ctx) {
|
|
|
639
705
|
// bump, which already covers the harder case of abort/interrupt ending
|
|
640
706
|
// the stream before 'result' is ever reached at all).
|
|
641
707
|
if (sessionHasTrait(session, "activityTokens")) releaseAllAgentActivity(session);
|
|
708
|
+
releaseTurnActivity(session);
|
|
642
709
|
// Turn boundary: the turn's own prompts, of every kind, end here; a
|
|
643
710
|
// tracked sub-agent keeps its own (the registry decides which).
|
|
644
711
|
promptsFor(sm).endTurn(session);
|
|
@@ -649,6 +716,12 @@ function attachMessageProcessor(ctx) {
|
|
|
649
716
|
if (parsed.cost && parsed.cost > 0) {
|
|
650
717
|
session.rateLimitResetsAt = null;
|
|
651
718
|
}
|
|
719
|
+
// The Claude CLI reports rate limits only when they change, so a turn that
|
|
720
|
+
// completes without a new event is the evidence the value still holds.
|
|
721
|
+
var resultVendor = usageStore.usageVendorFor(session, adapter);
|
|
722
|
+
if (confirmsUsageByResult(resultVendor) && isSuccessfulResult(parsed)) {
|
|
723
|
+
usageStore.confirm(resultVendor, { sessionLocalId: session.localId, processKey: session.queryInstance });
|
|
724
|
+
}
|
|
652
725
|
console.log("[sdk-bridge] result handler: project " + slug + " session " + session.localId + " cost=" + parsed.cost + " rateLimitResetsAt=" + session.rateLimitResetsAt);
|
|
653
726
|
|
|
654
727
|
// Handle SDK execution errors: show the error to the user instead of
|
|
@@ -700,12 +773,19 @@ function attachMessageProcessor(ctx) {
|
|
|
700
773
|
}
|
|
701
774
|
// Detect "Not logged in / Please run /login" from SDK.
|
|
702
775
|
// This is a short canned response with zero cost, not actual AI output.
|
|
703
|
-
|
|
776
|
+
var loginVendor = [session.vendor, adapter && adapter.vendor].filter(yokeRegistry.isKnown)[0] || yokeRegistry.ids()[0];
|
|
777
|
+
var loginPromptProviderFailure = isLoginPrompt && typeof ctx.providerFailureFor === "function"
|
|
778
|
+
? ctx.providerFailureFor(session, loginVendor)
|
|
779
|
+
: null;
|
|
780
|
+
if (loginPromptProviderFailure) {
|
|
781
|
+
// The canned "please log in" reply under a configured cloud provider is
|
|
782
|
+
// that provider's credentials failing; no sign-in is offered.
|
|
783
|
+
sendAndRecord(session, { type: "error", text: loginPromptProviderFailure.message });
|
|
784
|
+
} else if (isLoginPrompt) {
|
|
704
785
|
var authUser = session.ownerId ? usersModule.findUserById(session.ownerId) : null;
|
|
705
786
|
var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
|
|
706
787
|
var canAutoLogin = !!authLinuxUser
|
|
707
788
|
|| (authUser && authUser.role === "admin");
|
|
708
|
-
var loginVendor = [session.vendor, adapter && adapter.vendor].filter(yokeRegistry.isKnown)[0] || yokeRegistry.ids()[0];
|
|
709
789
|
var authFacts = authRequiredFacts(loginVendor);
|
|
710
790
|
var authTitle = authFacts.title;
|
|
711
791
|
var loginCommand = authFacts.loginCommand;
|
|
@@ -732,10 +812,16 @@ function attachMessageProcessor(ctx) {
|
|
|
732
812
|
canAutoLogin: canAutoLogin,
|
|
733
813
|
});
|
|
734
814
|
}
|
|
735
|
-
|
|
815
|
+
}
|
|
816
|
+
if (isLoginPrompt) {
|
|
817
|
+
// The CLI kept the canned reply as a turn of that session, so the next
|
|
818
|
+
// query starts fresh whether the fix is a sign-in or provider credentials.
|
|
736
819
|
session.cliSessionId = null;
|
|
737
820
|
}
|
|
738
|
-
|
|
821
|
+
// The canned reply is a failed turn, under a provider or a missing
|
|
822
|
+
// sign-in alike; code 1 is how every other failed turn ends, and what the
|
|
823
|
+
// loop engine reads to count an iteration as errored.
|
|
824
|
+
sendAndRecord(session, { type: "done", code: isLoginPrompt ? 1 : 0 });
|
|
739
825
|
var _donePreviewText = (session.responsePreview || "").replace(/\s+/g, " ").trim();
|
|
740
826
|
if (_donePreviewText.length > 140) _donePreviewText = _donePreviewText.substring(0, 140) + "...";
|
|
741
827
|
var _doneTitle = session.title || "Claude";
|
|
@@ -748,12 +834,8 @@ function attachMessageProcessor(ctx) {
|
|
|
748
834
|
body: _donePreviewText || "Response ready",
|
|
749
835
|
tag: "claude-done",
|
|
750
836
|
};
|
|
751
|
-
//
|
|
752
|
-
|
|
753
|
-
pushModule.sendPushToUser(session.ownerId, _donePayload);
|
|
754
|
-
} else {
|
|
755
|
-
pushModule.sendPush(_donePayload);
|
|
756
|
-
}
|
|
837
|
+
// Body carries response preview text: owner only, never a blind broadcast.
|
|
838
|
+
pushForSession(pushModule, session.ownerId, _donePayload);
|
|
757
839
|
}
|
|
758
840
|
|
|
759
841
|
var _nm = getNotificationsModule();
|
|
@@ -805,6 +887,13 @@ function attachMessageProcessor(ctx) {
|
|
|
805
887
|
}
|
|
806
888
|
session.compacting = parsed.status === "compacting";
|
|
807
889
|
|
|
890
|
+
} else if (parsed.yokeType === "compact_boundary") {
|
|
891
|
+
// The vendor finished compacting this session's context. Recorded as a
|
|
892
|
+
// system notice so the operator, and anyone replaying the session, can
|
|
893
|
+
// see when it happened. Deliberately not a lastActivityAt bump: a
|
|
894
|
+
// compaction is the vendor's housekeeping, not operator or agent work.
|
|
895
|
+
sendAndRecord(session, { type: "system_info", text: compactionNoticeText(parsed) });
|
|
896
|
+
|
|
808
897
|
} else if (parsed.yokeType === "task_started") {
|
|
809
898
|
var parentId = parsed.parentToolId;
|
|
810
899
|
if (parentId) {
|
|
@@ -911,7 +1000,16 @@ function attachMessageProcessor(ctx) {
|
|
|
911
1000
|
|
|
912
1001
|
} else if (parsed.yokeType === "rate_limit") {
|
|
913
1002
|
var info = parsed.rateLimitInfo;
|
|
914
|
-
console.log("[sdk-bridge] rate_limit_event for session " + session.localId + ": status=" + info.status + " resetsAt=" + info.resetsAt + " isUsingOverage=" + info.isUsingOverage + " isProcessing=" + session.isProcessing);
|
|
1003
|
+
console.log("[sdk-bridge] rate_limit_event for session " + session.localId + ": status=" + info.status + " rateLimitType=" + info.rateLimitType + " utilization=" + info.utilization + " resetsAt=" + info.resetsAt + " isUsingOverage=" + info.isUsingOverage + " isProcessing=" + session.isProcessing);
|
|
1004
|
+
|
|
1005
|
+
// Retain the last value per (vendor, bucket) for the --usage verb. Every
|
|
1006
|
+
// event is recorded, not only warning/rejected ones.
|
|
1007
|
+
var usageVendor = usageStore.usageVendorFor(session, adapter);
|
|
1008
|
+
usageStore.record(usageVendor, info, {
|
|
1009
|
+
source: parsed.rateLimitSource,
|
|
1010
|
+
sessionLocalId: session.localId,
|
|
1011
|
+
processKey: confirmsUsageByResult(usageVendor) ? session.queryInstance : null,
|
|
1012
|
+
});
|
|
915
1013
|
|
|
916
1014
|
// Broadcast reset time for top-bar usage link. This is a project-wide
|
|
917
1015
|
// broadcast (not sendAndRecord), but still stamp localId so a client
|
|
@@ -1034,6 +1132,7 @@ function attachMessageProcessor(ctx) {
|
|
|
1034
1132
|
processSubagentMessage: processSubagentMessage,
|
|
1035
1133
|
toolActivityTextForSubagent: toolActivityTextForSubagent,
|
|
1036
1134
|
retainTaskIdMap: retainTaskIdMap,
|
|
1135
|
+
releaseTurnActivity: releaseTurnActivity,
|
|
1037
1136
|
};
|
|
1038
1137
|
}
|
|
1039
1138
|
|
package/lib/sender-ref.js
CHANGED
|
@@ -94,6 +94,9 @@ function resolve(getProject, ref) {
|
|
|
94
94
|
// restart, so it can prove later that a console id still names this session.
|
|
95
95
|
cliSessionId: found.cliSessionId || null,
|
|
96
96
|
name: name,
|
|
97
|
+
// The console's own record of who owns the sending session; lets a session
|
|
98
|
+
// it opens inherit the owner.
|
|
99
|
+
ownerId: found.ownerId || null,
|
|
97
100
|
};
|
|
98
101
|
}
|
|
99
102
|
|
package/lib/server.js
CHANGED
|
@@ -372,11 +372,15 @@ function createServer(opts) {
|
|
|
372
372
|
projectAccess: projectAccess,
|
|
373
373
|
});
|
|
374
374
|
|
|
375
|
+
// --- Notification preferences (per user, on the server) ---
|
|
376
|
+
// Created before push so push can filter where it is sent.
|
|
377
|
+
var _prefsStore = require("./notification-prefs").createPrefsStore();
|
|
378
|
+
|
|
375
379
|
// --- Push module (global) ---
|
|
376
380
|
var pushModule = null;
|
|
377
381
|
try {
|
|
378
382
|
var { initPush } = require("./push");
|
|
379
|
-
pushModule = initPush();
|
|
383
|
+
pushModule = initPush({ prefs: _prefsStore });
|
|
380
384
|
} catch (e) {}
|
|
381
385
|
|
|
382
386
|
// --- Notifications module (global singleton, shared by all projects) ---
|
|
@@ -384,9 +388,37 @@ function createServer(opts) {
|
|
|
384
388
|
var _globalNotifications = _attachNotifications({
|
|
385
389
|
broadcastAll: function (msg) { broadcastAll(msg); },
|
|
386
390
|
sendToUser: function (userId, msg) { sendToUser(userId, msg); },
|
|
391
|
+
broadcastPerViewer: function (buildMsg) { broadcastPerViewer(buildMsg); },
|
|
387
392
|
pushModule: pushModule,
|
|
388
|
-
|
|
393
|
+
prefsStore: _prefsStore,
|
|
394
|
+
isMultiUser: users.isMultiUser,
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// Reminders for prompts nobody has answered (lib/prompt-reminders.js): a
|
|
398
|
+
// sweep over every project's sessions and their prompt registries.
|
|
399
|
+
var { promptsFor: _promptsFor } = require("./prompt-registry");
|
|
400
|
+
var _promptReminders = require("./prompt-reminders").createPromptReminders({
|
|
401
|
+
notifications: _globalNotifications,
|
|
402
|
+
push: pushModule,
|
|
403
|
+
isMultiUser: users.isMultiUser,
|
|
404
|
+
getConfig: function () {
|
|
405
|
+
var cfg = require("./config").loadConfig();
|
|
406
|
+
return cfg ? cfg.promptReminders : null;
|
|
407
|
+
},
|
|
408
|
+
listSessions: function () {
|
|
409
|
+
var held = [];
|
|
410
|
+
projects.forEach(function (ctx, slug) {
|
|
411
|
+
if (!ctx.sm || !ctx.sm.sessions) return;
|
|
412
|
+
var prompts = _promptsFor(ctx.sm);
|
|
413
|
+
var projectName = ctx.getTitle ? ctx.getTitle() : slug;
|
|
414
|
+
ctx.sm.sessions.forEach(function (session) {
|
|
415
|
+
held.push({ slug: slug, project: projectName, session: session, prompts: prompts });
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
return held;
|
|
419
|
+
},
|
|
389
420
|
});
|
|
421
|
+
_promptReminders.start();
|
|
390
422
|
|
|
391
423
|
// --- External trigger watcher (global singleton) ---
|
|
392
424
|
// Watches ~/.clagentic/external-triggers/ for JSON files dropped by external
|
|
@@ -395,10 +427,31 @@ function createServer(opts) {
|
|
|
395
427
|
// emitted — the trigger carries its own notification channel (e.g. ntfy).
|
|
396
428
|
var { attachExternalTrigger } = require("./project-external-trigger");
|
|
397
429
|
var { EXTERNAL_TRIGGERS_DIR } = require("./config");
|
|
430
|
+
// The sender-side record of what each session sent out (lib/outbound-ledger.js).
|
|
431
|
+
// Retention is read from daemon.json at use, so a change needs no restart.
|
|
432
|
+
var _outboundLedger = require("./outbound-ledger").createOutboundLedger({
|
|
433
|
+
getBaseDir: function () { return CONFIG_DIR; },
|
|
434
|
+
getRetentionDays: function () {
|
|
435
|
+
var cfg = require("./config").loadConfig();
|
|
436
|
+
return cfg ? cfg.outboundRetentionDays : undefined;
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
_outboundLedger.start();
|
|
440
|
+
// `list-outbound` arrives on the daemon-owner socket: no user record, and
|
|
441
|
+
// authenticated by the OS gate on the socket itself.
|
|
442
|
+
var _outboundQuery = require("./outbound-query").createOutboundQuery({
|
|
443
|
+
ledger: _outboundLedger,
|
|
444
|
+
access: require("./outbound-access").createOutboundAccess({
|
|
445
|
+
projectAccess: projectAccess,
|
|
446
|
+
getProject: function (slug) { return projects.get(slug) || null; },
|
|
447
|
+
}),
|
|
448
|
+
caller: { user: null, authenticated: true },
|
|
449
|
+
});
|
|
398
450
|
// One implementation for the file drop and the daemon IPC verbs (open-session,
|
|
399
451
|
// send-input).
|
|
400
452
|
var _sessionInput = require("./session-input").createSessionInput({
|
|
401
453
|
getProject: function (slug) { return projects.get(slug) || null; },
|
|
454
|
+
outboundLedger: _outboundLedger,
|
|
402
455
|
// Read when a session is opened, so a change needs no restart.
|
|
403
456
|
getPermissionSettings: function () {
|
|
404
457
|
return onGetPermissionSettings ? onGetPermissionSettings() : null;
|
|
@@ -548,7 +601,11 @@ function createServer(opts) {
|
|
|
548
601
|
var parsed = JSON.parse(body);
|
|
549
602
|
var sub = parsed.subscription || parsed;
|
|
550
603
|
var _httpPushUser = getMultiUserFromReq(req);
|
|
551
|
-
pushModule.addSubscription(sub, parsed.replaceEndpoint, _httpPushUser ? _httpPushUser.id : null)
|
|
604
|
+
if (pushModule.addSubscription(sub, parsed.replaceEndpoint, _httpPushUser ? _httpPushUser.id : null) === false && sub && sub.endpoint) {
|
|
605
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
606
|
+
res.end('{"error":"sign in to enable push notifications"}');
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
552
609
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
553
610
|
res.end('{"ok":true}');
|
|
554
611
|
} catch (e) {
|
|
@@ -1749,6 +1806,17 @@ function createServer(opts) {
|
|
|
1749
1806
|
});
|
|
1750
1807
|
}
|
|
1751
1808
|
|
|
1809
|
+
// One message per live ws, built from that connection's user id.
|
|
1810
|
+
function broadcastPerViewer(buildMsg) {
|
|
1811
|
+
projects.forEach(function (ctx) {
|
|
1812
|
+
if (typeof ctx.forEachClient !== "function") return;
|
|
1813
|
+
ctx.forEachClient(function (ws) {
|
|
1814
|
+
if (ws.readyState !== 1) return;
|
|
1815
|
+
ws.send(JSON.stringify(buildMsg(ws._clagenticUser ? ws._clagenticUser.id : null)));
|
|
1816
|
+
});
|
|
1817
|
+
});
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1752
1820
|
// True if the user has any live ws across any project.
|
|
1753
1821
|
function isUserOnline(userId) {
|
|
1754
1822
|
if (!userId) return false;
|
|
@@ -1773,6 +1841,8 @@ function createServer(opts) {
|
|
|
1773
1841
|
}
|
|
1774
1842
|
|
|
1775
1843
|
function destroyAll() {
|
|
1844
|
+
_promptReminders.stop();
|
|
1845
|
+
_outboundLedger.stop();
|
|
1776
1846
|
_externalTrigger.stopWatcher();
|
|
1777
1847
|
_scheduledInput.stop();
|
|
1778
1848
|
var shutdowns = [];
|
|
@@ -1789,7 +1859,12 @@ function createServer(opts) {
|
|
|
1789
1859
|
});
|
|
1790
1860
|
projects.clear();
|
|
1791
1861
|
sessionReclaim.logShutdownSummary(tally);
|
|
1792
|
-
|
|
1862
|
+
// The prompts settled above sent their close pushes; the process must not
|
|
1863
|
+
// exit before they leave.
|
|
1864
|
+
return Promise.all(shutdowns).then(function (results) {
|
|
1865
|
+
if (!pushModule || typeof pushModule.flush !== "function") return results;
|
|
1866
|
+
return pushModule.flush().then(function () { return results; });
|
|
1867
|
+
});
|
|
1793
1868
|
}
|
|
1794
1869
|
|
|
1795
1870
|
// --- Periodic cleanup of old chat images ---
|
|
@@ -1859,6 +1934,7 @@ function createServer(opts) {
|
|
|
1859
1934
|
broadcastAll: broadcastAll,
|
|
1860
1935
|
forEachProject: forEachProject,
|
|
1861
1936
|
sessionInput: _sessionInput,
|
|
1937
|
+
outboundQuery: _outboundQuery,
|
|
1862
1938
|
scheduledInput: _scheduledInput,
|
|
1863
1939
|
getProject: function (slug) { return projects.get(slug) || null; },
|
|
1864
1940
|
destroyProject: removeProject,
|
package/lib/session-directory.js
CHANGED
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
// console is not in the store and is not listed.
|
|
10
10
|
//
|
|
11
11
|
// States:
|
|
12
|
-
// live a turn is running
|
|
13
|
-
//
|
|
12
|
+
// live a turn is running, or the session is blocked on a pending prompt
|
|
13
|
+
// (pendingPrompts tells the two apart)
|
|
14
|
+
// idle a runtime is attached, nothing running, nothing pending
|
|
14
15
|
// reaped no runtime (idle reaper, daemon restart); input resumes it
|
|
16
|
+
// The three come from the shared derivation in lib/session-liveness.js.
|
|
15
17
|
//
|
|
16
18
|
// Addresses (the label format of lib/sender-ref.js):
|
|
17
19
|
// <agent>@<project> a session running that named agent
|
|
@@ -30,6 +32,7 @@ var senderRef = require("./sender-ref");
|
|
|
30
32
|
var { slugifyAgentName } = require("./agents");
|
|
31
33
|
var { isInjected } = require("./injected-sender");
|
|
32
34
|
var { pendingPrompts } = require("./pending-prompts");
|
|
35
|
+
var liveness = require("./session-liveness");
|
|
33
36
|
|
|
34
37
|
var STATE = Object.freeze({ LIVE: "live", IDLE: "idle", REAPED: "reaped" });
|
|
35
38
|
var ANY_STATE = "any";
|
|
@@ -56,8 +59,7 @@ function validateName(raw) {
|
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
function stateOf(session) {
|
|
59
|
-
|
|
60
|
-
return session.isProcessing ? STATE.LIVE : STATE.IDLE;
|
|
62
|
+
return liveness.liveStateOf(liveness.activityOf(session));
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
function isoOrNull(ms) {
|
package/lib/session-input-ipc.js
CHANGED
|
@@ -50,4 +50,14 @@ function handleSessionCommand(sessionInput, msg) {
|
|
|
50
50
|
return undefined;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
// The read side of the outbound ledger (lib/outbound-query.js).
|
|
54
|
+
function handleOutboundCommand(outboundQuery, msg) {
|
|
55
|
+
return outboundQuery.list({
|
|
56
|
+
sessionId: msg.sessionId,
|
|
57
|
+
projectSlug: msg.projectSlug,
|
|
58
|
+
sinceMs: msg.sinceMs,
|
|
59
|
+
kind: msg.kind,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = { handleSessionCommand: handleSessionCommand, handleOutboundCommand: handleOutboundCommand };
|