@clagentic/console 1.12.0-beta.1 → 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/README.md +1 -0
- package/bin/cli.js +5 -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-changes.js +8 -2
- package/lib/build-sha.json +2 -2
- package/lib/build-update-notify.js +45 -0
- package/lib/build-update-offer.js +34 -11
- package/lib/build-update-standing.js +34 -14
- package/lib/claude-settings-env.js +142 -0
- package/lib/cli/duration.js +27 -0
- package/lib/cli/schedule-input-subcommands.js +1 -22
- package/lib/cli/session-subcommands.js +60 -11
- package/lib/client-address.js +44 -0
- package/lib/daemon.js +31 -10
- package/lib/idle-compaction-setting.js +203 -0
- package/lib/mcp-bridge-credential.js +41 -0
- package/lib/notification-prefs.js +18 -22
- package/lib/notify/core.js +210 -0
- package/lib/notify/index.js +31 -0
- package/lib/notify/live-prompts.js +36 -0
- package/lib/notify/payload.js +62 -0
- package/lib/notify/target.js +5 -0
- package/lib/notify/type-registry.js +81 -0
- package/lib/notify/types.js +57 -0
- package/lib/open-sockets.js +27 -0
- package/lib/outbound-access.js +85 -0
- package/lib/outbound-entry.js +116 -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 +48 -8
- package/lib/project-filesystem.js +43 -5
- package/lib/project-http.js +9 -1
- package/lib/project-loop.js +38 -26
- package/lib/project-notifications.js +122 -39
- package/lib/project-prompt-responses.js +1 -1
- package/lib/project-sessions.js +11 -1
- 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 +41 -5
- package/lib/prompt-answer.js +145 -0
- package/lib/prompt-expiry.js +50 -0
- package/lib/prompt-registry.js +98 -25
- package/lib/prompt-reminders.js +38 -33
- package/lib/prompt-source.js +59 -8
- package/lib/public/app.js +32 -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 +29 -1
- package/lib/public/css/home-hub.css +12 -0
- package/lib/public/css/icon-strip.css +9 -0
- 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/mobile-nav.css +11 -0
- package/lib/public/css/sidebar.css +18 -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 +44 -7
- package/lib/public/modules/activity-state.js +20 -4
- 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 +34 -5
- package/lib/public/modules/app-messages.js +55 -16
- package/lib/public/modules/app-notifications.js +104 -75
- package/lib/public/modules/app-panels.js +26 -3
- package/lib/public/modules/app-projects.js +3 -1
- package/lib/public/modules/app-rate-limit.js +8 -165
- package/lib/public/modules/app-rendering.js +32 -7
- package/lib/public/modules/build-update-sessions.js +81 -0
- 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 +61 -57
- package/lib/public/modules/env-shadow-notice.js +34 -0
- 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 +246 -0
- package/lib/public/modules/pending-term-request.js +30 -0
- package/lib/public/modules/project-icon.js +22 -2
- package/lib/public/modules/project-settings.js +5 -0
- package/lib/public/modules/prompt-state.js +3 -3
- package/lib/public/modules/prompts.js +1 -1
- 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 +50 -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 +193 -0
- package/lib/public/modules/terminal.js +84 -107
- package/lib/public/modules/tools.js +19 -0
- package/lib/public/modules/user-shell.js +824 -0
- package/lib/public/notify-sw-logic.js +252 -0
- package/lib/public/notify-target.js +157 -0
- package/lib/public/style.css +5 -0
- package/lib/public/sw.js +20 -69
- package/lib/push.js +63 -19
- package/lib/queued-chat.js +392 -0
- package/lib/runtime-env.js +1 -0
- package/lib/scheduled-input/ws.js +67 -9
- package/lib/sdk-bridge.js +184 -73
- package/lib/sdk-message-processor.js +124 -76
- 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 +112 -16
- package/lib/session-directory.js +39 -12
- package/lib/session-end.js +97 -0
- package/lib/session-input-ipc.js +37 -1
- package/lib/session-input.js +263 -21
- package/lib/session-liveness.js +53 -0
- package/lib/session-reclaim.js +37 -2
- package/lib/session-resume.js +1 -0
- package/lib/session-settings-file.js +53 -0
- package/lib/sessions.js +80 -9
- package/lib/team-traffic-ws.js +68 -0
- package/lib/team-traffic.js +318 -0
- package/lib/usage-store.js +36 -7
- package/lib/user-shell-settings.js +105 -0
- package/lib/vendor-auth.js +33 -2
- package/lib/ws-schema.js +33 -5
- package/lib/yoke/adapters/claude-capabilities.js +2 -0
- package/lib/yoke/adapters/claude-vendor.js +17 -1
- package/lib/yoke/adapters/claude-worker.js +39 -11
- package/lib/yoke/adapters/claude.js +225 -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/auth-checks.js +17 -2
- package/lib/yoke/codex-app-server.js +8 -2
- package/lib/yoke/index.js +21 -3
- package/lib/yoke/interface.js +54 -1
- package/lib/yoke/mcp-bridge-server.js +12 -8
- package/lib/yoke/provider-credentials.js +24 -0
- package/lib/yoke/registry.js +40 -1
- package/lib/yoke/user-shell.js +224 -0
- package/package.json +2 -2
- package/scripts/check-test-count.js +14 -0
- package/lib/public/modules/build-notice-gate.js +0 -73
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
var usersModule = require("./users");
|
|
2
|
-
var {
|
|
2
|
+
var { notifyFor } = require("./notify");
|
|
3
|
+
var { notifyAuthRequired } = require("./auth-required-notify");
|
|
3
4
|
var { discoverWorkflows } = require("./sdk-workflow-discovery");
|
|
4
5
|
var { buildEnrichedSlashCommands } = require("./sdk-slash-enrichment");
|
|
5
6
|
var { promptsFor } = require("./prompt-registry");
|
|
6
7
|
var sessionActivity = require("./session-activity");
|
|
8
|
+
var queuedChat = require("./queued-chat");
|
|
7
9
|
var yokeRegistry = require("./yoke").registry;
|
|
8
10
|
var usageStore = require("./usage-store");
|
|
9
11
|
|
|
@@ -42,7 +44,10 @@ function formatTokens(n) {
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
function compactionNoticeText(ev) {
|
|
45
|
-
|
|
47
|
+
// Name only the trigger the vendor reported; any other value is left unnamed
|
|
48
|
+
// rather than guessed.
|
|
49
|
+
var triggerName = ev.trigger === "manual" ? "manual" : ev.trigger === "auto" ? "automatic" : null;
|
|
50
|
+
var text = "Context compacted" + (triggerName ? " (" + triggerName + ")" : "");
|
|
46
51
|
if (typeof ev.preTokens === "number" && typeof ev.postTokens === "number") {
|
|
47
52
|
text += ": " + formatTokens(ev.preTokens) + " to " + formatTokens(ev.postTokens) + " tokens";
|
|
48
53
|
} else if (typeof ev.preTokens === "number") {
|
|
@@ -65,6 +70,7 @@ function attachMessageProcessor(ctx) {
|
|
|
65
70
|
var refreshAiTitle = ctx.refreshAiTitle || null;
|
|
66
71
|
var onTeamCreate = ctx.onTeamCreate || null;
|
|
67
72
|
var onTeamDelete = ctx.onTeamDelete || null;
|
|
73
|
+
var onAgentSeen = ctx.onAgentSeen || null;
|
|
68
74
|
var opts = ctx.opts;
|
|
69
75
|
var discoverSkillDirs = ctx.discoverSkillDirs;
|
|
70
76
|
var mergeSkills = ctx.mergeSkills;
|
|
@@ -80,6 +86,14 @@ function attachMessageProcessor(ctx) {
|
|
|
80
86
|
sm.sendAndRecord(session, obj);
|
|
81
87
|
}
|
|
82
88
|
|
|
89
|
+
// A Task or Agent dispatch names the sub-agent it starts in subagent_type; the
|
|
90
|
+
// roster records that name exactly as the call gave it.
|
|
91
|
+
function observeSubagent(session, toolName, input) {
|
|
92
|
+
if (!onAgentSeen || !isAgentDispatchTool(toolName) || !input) return;
|
|
93
|
+
if (typeof input.subagent_type !== "string" || !input.subagent_type) return;
|
|
94
|
+
onAgentSeen({ key: input.subagent_type, source: "subagent", project: slug, sessionId: String(session.localId) });
|
|
95
|
+
}
|
|
96
|
+
|
|
83
97
|
// session.taskIdMap is keyed by the Task's tool-use id (the parentToolId
|
|
84
98
|
// task_started carries) and holds the SDK's task id; the registry tracks
|
|
85
99
|
// Tasks by that same tool-use id. At a turn boundary the mapping is kept
|
|
@@ -95,6 +109,48 @@ function attachMessageProcessor(ctx) {
|
|
|
95
109
|
session.taskIdMap = next;
|
|
96
110
|
}
|
|
97
111
|
|
|
112
|
+
// Whether a tool_result block is the launch acknowledgement of a tracked
|
|
113
|
+
// background Task. The discriminator is the SDK's structured tool output
|
|
114
|
+
// (parsed.asyncLaunch, from tool_use_result.status "async_launched"), never
|
|
115
|
+
// the result text. When both sides name the agent id they must agree, so a
|
|
116
|
+
// launch of one agent cannot be mistaken for the ack of another.
|
|
117
|
+
function isBackgroundLaunchAck(session, parsed, toolUseId) {
|
|
118
|
+
if (!parsed.asyncLaunch) return false;
|
|
119
|
+
if (!promptsFor(sm).isTaskTracked(session, toolUseId)) return false;
|
|
120
|
+
var knownAgentId = session.taskIdMap ? session.taskIdMap[toolUseId] : null;
|
|
121
|
+
return !(parsed.asyncLaunch.agentId && knownAgentId && parsed.asyncLaunch.agentId !== knownAgentId);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function buildToolResultMsg(block) {
|
|
125
|
+
var resultText = "";
|
|
126
|
+
var resultImages = [];
|
|
127
|
+
if (typeof block.content === "string") {
|
|
128
|
+
resultText = block.content;
|
|
129
|
+
} else if (Array.isArray(block.content)) {
|
|
130
|
+
resultText = block.content
|
|
131
|
+
.filter(function(c) { return c.type === "text"; })
|
|
132
|
+
.map(function(c) { return c.text; })
|
|
133
|
+
.join("\n");
|
|
134
|
+
for (var ri = 0; ri < block.content.length; ri++) {
|
|
135
|
+
var rc = block.content[ri];
|
|
136
|
+
if (rc.type === "image" && rc.source) {
|
|
137
|
+
resultImages.push({
|
|
138
|
+
mediaType: rc.source.media_type,
|
|
139
|
+
data: rc.source.data,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
var msg = {
|
|
145
|
+
type: "tool_result",
|
|
146
|
+
id: block.tool_use_id,
|
|
147
|
+
content: resultText,
|
|
148
|
+
is_error: block.is_error || false,
|
|
149
|
+
};
|
|
150
|
+
if (resultImages.length > 0) msg.images = resultImages;
|
|
151
|
+
return msg;
|
|
152
|
+
}
|
|
153
|
+
|
|
98
154
|
function sendToSession(session, obj) {
|
|
99
155
|
sm.sendToSession(session, obj);
|
|
100
156
|
}
|
|
@@ -278,6 +334,11 @@ function attachMessageProcessor(ctx) {
|
|
|
278
334
|
}
|
|
279
335
|
|
|
280
336
|
function processSDKMessage(session, parsed) {
|
|
337
|
+
// The agent names the messages it has taken into the turn on its frames:
|
|
338
|
+
// each chat message tracked as queued is delivered once, here.
|
|
339
|
+
if (parsed.userMessageUuids) queuedChat.consume(session, parsed.userMessageUuids);
|
|
340
|
+
if (parsed.yokeType === "result") queuedChat.markTurnEnd(session);
|
|
341
|
+
|
|
281
342
|
// Timing: log key SDK milestones relative to query start
|
|
282
343
|
if (session._queryStartTs) {
|
|
283
344
|
var _elapsed = Date.now() - session._queryStartTs;
|
|
@@ -433,6 +494,7 @@ function attachMessageProcessor(ctx) {
|
|
|
433
494
|
name: parsed.toolName,
|
|
434
495
|
input: parsed.input || {},
|
|
435
496
|
});
|
|
497
|
+
observeSubagent(session, parsed.toolName, parsed.input);
|
|
436
498
|
|
|
437
499
|
// TeamCreate: record pending so we can extract the teamId from tool_result
|
|
438
500
|
if (parsed.toolName === "TeamCreate" && onTeamCreate) {
|
|
@@ -523,6 +585,7 @@ function attachMessageProcessor(ctx) {
|
|
|
523
585
|
var input = {};
|
|
524
586
|
try { input = JSON.parse(block.inputJson); } catch (e) {}
|
|
525
587
|
sendAndRecord(session, { type: "tool_executing", id: block.id, name: block.name, input: input });
|
|
588
|
+
observeSubagent(session, block.name, input);
|
|
526
589
|
|
|
527
590
|
// lr-6e20f7: acquire an activity token for EVERY Claude tool_use
|
|
528
591
|
// block, not only Task. Claude has turn-wide isProcessing coverage
|
|
@@ -547,15 +610,16 @@ function attachMessageProcessor(ctx) {
|
|
|
547
610
|
|
|
548
611
|
if (pushModule && block.name === "AskUserQuestion" && input.questions) {
|
|
549
612
|
var q = input.questions[0];
|
|
550
|
-
|
|
551
|
-
|
|
613
|
+
// Content carries prompt text: owner only, never a blind broadcast.
|
|
614
|
+
// The prompt's id is the tool call's id.
|
|
615
|
+
notifyFor(pushModule).notify("ask_user", {
|
|
552
616
|
slug: slug,
|
|
617
|
+
sessionId: session.localId,
|
|
618
|
+
requestId: block.id,
|
|
619
|
+
}, {
|
|
553
620
|
title: "Claude has a question",
|
|
554
621
|
body: withPromptLabel(promptsFor(sm).labelFor(session, block.id), q ? q.question : "Waiting for your response"),
|
|
555
|
-
|
|
556
|
-
};
|
|
557
|
-
// Content carries prompt text: owner only, never a blind broadcast.
|
|
558
|
-
pushForSession(pushModule, session.ownerId, _askPayload);
|
|
622
|
+
}, { ownerId: session.ownerId });
|
|
559
623
|
}
|
|
560
624
|
} else if (block && block.type === "thinking") {
|
|
561
625
|
var duration = block.startTime ? (Date.now() - block.startTime) / 1000 : 0;
|
|
@@ -608,6 +672,15 @@ function attachMessageProcessor(ctx) {
|
|
|
608
672
|
for (var i = 0; i < content.length; i++) {
|
|
609
673
|
var block = content[i];
|
|
610
674
|
if (block.type === "tool_result" && !session.sentToolResults[block.tool_use_id]) {
|
|
675
|
+
// The acknowledgement of a background Task is its launch: the agent
|
|
676
|
+
// runs on, and its own terminal task_notification (or the query
|
|
677
|
+
// ending) is what ends tracking and releases its activity token.
|
|
678
|
+
if (isBackgroundLaunchAck(session, parsed, block.tool_use_id)) {
|
|
679
|
+
sessionReclaim.noteBackgroundLaunch(session, block.tool_use_id);
|
|
680
|
+
session.sentToolResults[block.tool_use_id] = true;
|
|
681
|
+
sendAndRecord(session, buildToolResultMsg(block));
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
611
684
|
// A tracked Task's result means its sub-agent is done.
|
|
612
685
|
var resultPrompts = promptsFor(sm);
|
|
613
686
|
if (resultPrompts.isTaskTracked(session, block.tool_use_id)) {
|
|
@@ -633,34 +706,8 @@ function attachMessageProcessor(ctx) {
|
|
|
633
706
|
// released by task_notification), so calling it unconditionally
|
|
634
707
|
// for every tool_result is always safe.
|
|
635
708
|
releaseActivity(session, block.tool_use_id);
|
|
636
|
-
var resultText = "";
|
|
637
|
-
var resultImages = [];
|
|
638
|
-
if (typeof block.content === "string") {
|
|
639
|
-
resultText = block.content;
|
|
640
|
-
} else if (Array.isArray(block.content)) {
|
|
641
|
-
resultText = block.content
|
|
642
|
-
.filter(function(c) { return c.type === "text"; })
|
|
643
|
-
.map(function(c) { return c.text; })
|
|
644
|
-
.join("\n");
|
|
645
|
-
for (var ri = 0; ri < block.content.length; ri++) {
|
|
646
|
-
var rc = block.content[ri];
|
|
647
|
-
if (rc.type === "image" && rc.source) {
|
|
648
|
-
resultImages.push({
|
|
649
|
-
mediaType: rc.source.media_type,
|
|
650
|
-
data: rc.source.data,
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
709
|
session.sentToolResults[block.tool_use_id] = true;
|
|
656
|
-
|
|
657
|
-
type: "tool_result",
|
|
658
|
-
id: block.tool_use_id,
|
|
659
|
-
content: resultText,
|
|
660
|
-
is_error: block.is_error || false,
|
|
661
|
-
};
|
|
662
|
-
if (resultImages.length > 0) toolResultMsg.images = resultImages;
|
|
663
|
-
sendAndRecord(session, toolResultMsg);
|
|
710
|
+
sendAndRecord(session, buildToolResultMsg(block));
|
|
664
711
|
}
|
|
665
712
|
}
|
|
666
713
|
}
|
|
@@ -746,16 +793,22 @@ function attachMessageProcessor(ctx) {
|
|
|
746
793
|
}
|
|
747
794
|
// Detect "Not logged in / Please run /login" from SDK.
|
|
748
795
|
// This is a short canned response with zero cost, not actual AI output.
|
|
749
|
-
|
|
796
|
+
var loginVendor = [session.vendor, adapter && adapter.vendor].filter(yokeRegistry.isKnown)[0] || yokeRegistry.ids()[0];
|
|
797
|
+
var loginPromptProviderFailure = isLoginPrompt && typeof ctx.providerFailureFor === "function"
|
|
798
|
+
? ctx.providerFailureFor(session, loginVendor)
|
|
799
|
+
: null;
|
|
800
|
+
if (loginPromptProviderFailure) {
|
|
801
|
+
// The canned "please log in" reply under a configured cloud provider is
|
|
802
|
+
// that provider's credentials failing; no sign-in is offered.
|
|
803
|
+
sendAndRecord(session, { type: "error", text: loginPromptProviderFailure.message });
|
|
804
|
+
} else if (isLoginPrompt) {
|
|
750
805
|
var authUser = session.ownerId ? usersModule.findUserById(session.ownerId) : null;
|
|
751
806
|
var authLinuxUser = authUser && authUser.linuxUser ? authUser.linuxUser : null;
|
|
752
807
|
var canAutoLogin = !!authLinuxUser
|
|
753
808
|
|| (authUser && authUser.role === "admin");
|
|
754
|
-
var loginVendor = [session.vendor, adapter && adapter.vendor].filter(yokeRegistry.isKnown)[0] || yokeRegistry.ids()[0];
|
|
755
809
|
var authFacts = authRequiredFacts(loginVendor);
|
|
756
810
|
var authTitle = authFacts.title;
|
|
757
811
|
var loginCommand = authFacts.loginCommand;
|
|
758
|
-
var _nmLogin = getNotificationsModule();
|
|
759
812
|
var authMsg = {
|
|
760
813
|
type: "auth_required",
|
|
761
814
|
text: authTitle,
|
|
@@ -765,50 +818,41 @@ function attachMessageProcessor(ctx) {
|
|
|
765
818
|
canAutoLogin: canAutoLogin,
|
|
766
819
|
};
|
|
767
820
|
sendAndRecord(session, authMsg);
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
// Reset CLI session so next query starts fresh with new auth
|
|
821
|
+
notifyAuthRequired(pushModule, getNotificationsModule(), {
|
|
822
|
+
slug: slug,
|
|
823
|
+
session: session,
|
|
824
|
+
title: authTitle,
|
|
825
|
+
vendor: authFacts.vendor,
|
|
826
|
+
loginCommand: loginCommand,
|
|
827
|
+
linuxUser: authLinuxUser,
|
|
828
|
+
canAutoLogin: canAutoLogin,
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
if (isLoginPrompt) {
|
|
832
|
+
// The CLI kept the canned reply as a turn of that session, so the next
|
|
833
|
+
// query starts fresh whether the fix is a sign-in or provider credentials.
|
|
782
834
|
session.cliSessionId = null;
|
|
783
835
|
}
|
|
784
|
-
|
|
836
|
+
// The canned reply is a failed turn, under a provider or a missing
|
|
837
|
+
// sign-in alike; code 1 is how every other failed turn ends, and what the
|
|
838
|
+
// loop engine reads to count an iteration as errored.
|
|
839
|
+
sendAndRecord(session, { type: "done", code: isLoginPrompt ? 1 : 0 });
|
|
785
840
|
var _donePreviewText = (session.responsePreview || "").replace(/\s+/g, " ").trim();
|
|
786
841
|
if (_donePreviewText.length > 140) _donePreviewText = _donePreviewText.substring(0, 140) + "...";
|
|
787
842
|
var _doneTitle = session.title || "Claude";
|
|
788
843
|
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
var _nm = getNotificationsModule();
|
|
802
|
-
if (_nm && !session.loop) {
|
|
803
|
-
_nm.notify("response_done", {
|
|
804
|
-
title: _doneTitle,
|
|
805
|
-
preview: _donePreviewText,
|
|
806
|
-
slug: slug,
|
|
807
|
-
sessionId: session.localId,
|
|
808
|
-
mateId: null,
|
|
809
|
-
ownerId: session.ownerId || null,
|
|
810
|
-
});
|
|
811
|
-
}
|
|
844
|
+
// One notify() per finished turn. The push carries the response preview,
|
|
845
|
+
// so it and the banner go to the session's owner alone (the core's
|
|
846
|
+
// audience rule), and a turn after a turn in the same session replaces
|
|
847
|
+
// the earlier notification. A turn of a loop's own session raises no
|
|
848
|
+
// banner: the loop's end does.
|
|
849
|
+
notifyFor(pushModule, getNotificationsModule()).notify("response_done", {
|
|
850
|
+
slug: slug,
|
|
851
|
+
sessionId: session.localId,
|
|
852
|
+
}, {
|
|
853
|
+
push: { title: _doneTitle, body: _donePreviewText || "Response ready" },
|
|
854
|
+
banner: session.loop ? null : { title: _doneTitle, preview: _donePreviewText },
|
|
855
|
+
}, { ownerId: session.ownerId || null });
|
|
812
856
|
// Reset for next turn in the same query
|
|
813
857
|
bumpLastActivity(session, "turn-result", slug);
|
|
814
858
|
session.turnCount = (session.turnCount || 0) + 1;
|
|
@@ -845,7 +889,10 @@ function attachMessageProcessor(ctx) {
|
|
|
845
889
|
});
|
|
846
890
|
}
|
|
847
891
|
}
|
|
892
|
+
var wasCompacting = !!session.compacting;
|
|
848
893
|
session.compacting = parsed.status === "compacting";
|
|
894
|
+
// The session list entry carries the flag, so the sidebar follows it.
|
|
895
|
+
if (wasCompacting !== session.compacting) sm.broadcastSessionList();
|
|
849
896
|
|
|
850
897
|
} else if (parsed.yokeType === "compact_boundary") {
|
|
851
898
|
// The vendor finished compacting this session's context. Recorded as a
|
|
@@ -1092,6 +1139,7 @@ function attachMessageProcessor(ctx) {
|
|
|
1092
1139
|
processSubagentMessage: processSubagentMessage,
|
|
1093
1140
|
toolActivityTextForSubagent: toolActivityTextForSubagent,
|
|
1094
1141
|
retainTaskIdMap: retainTaskIdMap,
|
|
1142
|
+
releaseTurnActivity: releaseTurnActivity,
|
|
1095
1143
|
};
|
|
1096
1144
|
}
|
|
1097
1145
|
|
package/lib/server-auth.js
CHANGED
|
@@ -5,6 +5,7 @@ var { CONFIG_DIR } = require("./config");
|
|
|
5
5
|
var _isDevMode = require("./config").isDevMode;
|
|
6
6
|
var store = require("./store");
|
|
7
7
|
var audit = require("./audit");
|
|
8
|
+
var { resolveClientAddress } = require("./client-address");
|
|
8
9
|
var { readCappedBody } = require("./utils");
|
|
9
10
|
|
|
10
11
|
// Default token TTL: 30 days. Tokens issued before expiry support was added are
|
|
@@ -36,6 +37,7 @@ function attachAuth(ctx) {
|
|
|
36
37
|
var osUsers = ctx.osUsers;
|
|
37
38
|
var provisionLinuxUser = ctx.provisionLinuxUser;
|
|
38
39
|
var onUserProvisioned = ctx.onUserProvisioned;
|
|
40
|
+
var trustedProxy = !!ctx.trustedProxy;
|
|
39
41
|
|
|
40
42
|
// --- Multi-user auth tokens (persisted to disk) ---
|
|
41
43
|
var TOKENS_NAME = _isDevMode ? "auth-tokens-dev.json" : "auth-tokens.json";
|
|
@@ -372,7 +374,7 @@ function attachAuth(ctx) {
|
|
|
372
374
|
return true;
|
|
373
375
|
}
|
|
374
376
|
if (req.method === "POST") {
|
|
375
|
-
var ip = req.
|
|
377
|
+
var ip = resolveClientAddress(req, trustedProxy).address;
|
|
376
378
|
var remaining = checkPinRateLimit(ip);
|
|
377
379
|
if (remaining !== null) {
|
|
378
380
|
res.writeHead(429, { "Content-Type": "application/json" });
|
|
@@ -505,7 +507,7 @@ function attachAuth(ctx) {
|
|
|
505
507
|
|
|
506
508
|
// Multi-user login
|
|
507
509
|
if (req.method === "POST" && fullUrl === "/auth/login") {
|
|
508
|
-
var ip = req.
|
|
510
|
+
var ip = resolveClientAddress(req, trustedProxy).address;
|
|
509
511
|
// IP-only pre-check (username not yet known — body not read)
|
|
510
512
|
var remaining = checkPinRateLimit(ip);
|
|
511
513
|
if (remaining !== null) {
|
|
@@ -562,7 +564,7 @@ function attachAuth(ctx) {
|
|
|
562
564
|
res.end('{"error":"OTP login not available"}');
|
|
563
565
|
return true;
|
|
564
566
|
}
|
|
565
|
-
var ip = req.
|
|
567
|
+
var ip = resolveClientAddress(req, trustedProxy).address;
|
|
566
568
|
var remaining = checkPinRateLimit(ip);
|
|
567
569
|
if (remaining !== null) {
|
|
568
570
|
res.writeHead(429, { "Content-Type": "application/json" });
|
|
@@ -615,7 +617,7 @@ function attachAuth(ctx) {
|
|
|
615
617
|
res.end('{"error":"OTP login not available"}');
|
|
616
618
|
return true;
|
|
617
619
|
}
|
|
618
|
-
var ip = req.
|
|
620
|
+
var ip = resolveClientAddress(req, trustedProxy).address;
|
|
619
621
|
var remaining = checkPinRateLimit(ip);
|
|
620
622
|
if (remaining !== null) {
|
|
621
623
|
res.writeHead(429, { "Content-Type": "application/json" });
|
package/lib/server-dm.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var { notifyFor } = require("./notify");
|
|
2
|
+
|
|
1
3
|
// Strict allow-list for client-supplied dmKey values.
|
|
2
4
|
// Accepts exactly two segments separated by a single colon, each containing
|
|
3
5
|
// only alphanumeric characters, hyphens, and underscores. This prevents path
|
|
@@ -109,28 +111,17 @@ function attachDm(ctx) {
|
|
|
109
111
|
// Send push notification to target user
|
|
110
112
|
var senderName = ws._clagenticUser ? (ws._clagenticUser.displayName || ws._clagenticUser.username || "Someone") : "Someone";
|
|
111
113
|
var preview = (msg.text || "").substring(0, 140);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
type: "dm",
|
|
115
|
-
title: senderName,
|
|
116
|
-
body: preview,
|
|
117
|
-
tag: "dm-" + msg.dmKey,
|
|
118
|
-
dmKey: msg.dmKey,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
// Create in-app notification via any project's notifications module
|
|
114
|
+
// The in-app banner store is shared by every project; any project's
|
|
115
|
+
// context reaches it.
|
|
122
116
|
var _nmCtx = null;
|
|
123
117
|
projects.forEach(function (pCtx) { if (!_nmCtx && pCtx.getNotificationsModule) _nmCtx = pCtx; });
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
118
|
+
var _nm = _nmCtx ? _nmCtx.getNotificationsModule() : null;
|
|
119
|
+
// One notify() per message: the push and the banner go to the recipient
|
|
120
|
+
// alone, and a tap opens the conversation with the sender.
|
|
121
|
+
notifyFor(pushModule, _nm).notify("mate_dm", { peerId: userId }, {
|
|
122
|
+
push: { title: senderName, body: preview },
|
|
123
|
+
banner: { senderName: senderName, preview: preview },
|
|
124
|
+
}, { ownerId: targetId });
|
|
134
125
|
return true;
|
|
135
126
|
}
|
|
136
127
|
|
package/lib/server-settings.js
CHANGED
|
@@ -453,6 +453,7 @@ function attachSettings(ctx) {
|
|
|
453
453
|
// POST /api/custom-emoji/:slug — upload a new custom emoji image
|
|
454
454
|
if (req.method === "POST" && fullUrl.startsWith("/api/custom-emoji/")) {
|
|
455
455
|
var postSlug = fullUrl.slice("/api/custom-emoji/".length).split("?")[0];
|
|
456
|
+
var postQuery = new URLSearchParams(fullUrl.indexOf("?") === -1 ? "" : fullUrl.slice(fullUrl.indexOf("?") + 1));
|
|
456
457
|
|
|
457
458
|
// Auth gate
|
|
458
459
|
var muPost = getMultiUserFromReq(req);
|
|
@@ -527,6 +528,32 @@ function attachSettings(ctx) {
|
|
|
527
528
|
return;
|
|
528
529
|
}
|
|
529
530
|
|
|
531
|
+
// ?create=1 is create-only: an existing slug is refused, never replaced.
|
|
532
|
+
// Callers that attach the icon to something of their own (the agent
|
|
533
|
+
// avatar picker) use it so they cannot overwrite an icon another surface
|
|
534
|
+
// already uses. Without it an upload replaces, as before.
|
|
535
|
+
var createOnly = postQuery.get("create") === "1";
|
|
536
|
+
if (createOnly) {
|
|
537
|
+
var slugTaken = false;
|
|
538
|
+
try {
|
|
539
|
+
slugTaken = fs.readdirSync(customEmojiDir).some(function (f) {
|
|
540
|
+
var fExt = path.extname(f).slice(1);
|
|
541
|
+
return !!CUSTOM_EMOJI_CT[fExt] && path.basename(f, "." + fExt) === postSlug;
|
|
542
|
+
});
|
|
543
|
+
} catch (e) {
|
|
544
|
+
slugTaken = false;
|
|
545
|
+
}
|
|
546
|
+
if (slugTaken) {
|
|
547
|
+
audit.log(CUSTOM_EMOJI_UPLOAD_ACTION, Object.assign({}, postActor, {
|
|
548
|
+
target: postSlug,
|
|
549
|
+
metadata: { status: 409, size: postSize, reason: "slug exists (create-only)" },
|
|
550
|
+
}));
|
|
551
|
+
res.writeHead(409, { "Content-Type": "application/json" });
|
|
552
|
+
res.end('{"error":"An icon with that name already exists"}');
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
530
557
|
// Remove any existing file for this slug (different ext)
|
|
531
558
|
try {
|
|
532
559
|
var existingAll = fs.readdirSync(customEmojiDir);
|
|
@@ -541,9 +568,20 @@ function attachSettings(ctx) {
|
|
|
541
568
|
} catch (e) {}
|
|
542
569
|
|
|
543
570
|
try {
|
|
544
|
-
|
|
571
|
+
// "wx" makes create-only hold even if the same name was taken between the
|
|
572
|
+
// check above and this write.
|
|
573
|
+
fs.writeFileSync(candidatePath, raw, createOnly ? { flag: "wx" } : undefined);
|
|
545
574
|
try { fs.chmodSync(candidatePath, 0o644); } catch (e) {}
|
|
546
575
|
} catch (e) {
|
|
576
|
+
if (createOnly && e && e.code === "EEXIST") {
|
|
577
|
+
audit.log(CUSTOM_EMOJI_UPLOAD_ACTION, Object.assign({}, postActor, {
|
|
578
|
+
target: postSlug,
|
|
579
|
+
metadata: { status: 409, size: postSize, reason: "slug exists (create-only)" },
|
|
580
|
+
}));
|
|
581
|
+
res.writeHead(409, { "Content-Type": "application/json" });
|
|
582
|
+
res.end('{"error":"An icon with that name already exists"}');
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
547
585
|
audit.log(CUSTOM_EMOJI_UPLOAD_ACTION, Object.assign({}, postActor, {
|
|
548
586
|
target: postSlug,
|
|
549
587
|
metadata: { status: 500, size: postSize, reason: "write failed: " + e.message },
|