@clagentic/console 1.12.0-beta.2 → 1.12.0
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
|
@@ -28,11 +28,14 @@ import { formatDiagnosticSource as _formatSource } from './diagnostic-format.js'
|
|
|
28
28
|
import { sendWs } from './ws-ref.js';
|
|
29
29
|
import { buildUpdateDetailEl } from './build-update-detail.js';
|
|
30
30
|
import { sessionLinesOf, messageWithoutSessions, buildSessionsEl } from './build-update-sessions.js';
|
|
31
|
-
import {
|
|
32
|
-
BUILD_NOTICE_SOURCE, BUILD_NOTICE_ACTION, noticeKeyOf, cooldownOf, createNoticeGate,
|
|
33
|
-
} from './build-notice-gate.js';
|
|
34
31
|
|
|
35
|
-
|
|
32
|
+
// The build-update offer's diagnostics entry: where its restart action lives.
|
|
33
|
+
// The offer itself is a core notification (build_update_offer); the page builds
|
|
34
|
+
// this entry from it, and its collapse and close come from the core.
|
|
35
|
+
var BUILD_NOTICE_SOURCE = 'build-update';
|
|
36
|
+
var BUILD_NOTICE_ACTION = 'restart_for_build_update';
|
|
37
|
+
// The notification the held offer entry was built from.
|
|
38
|
+
var _offerNotifId = null;
|
|
36
39
|
|
|
37
40
|
// Allowlist of actionable.action values this client will act on.
|
|
38
41
|
// A diagnostic's `actionable.action` string is never sent to the server
|
|
@@ -281,9 +284,6 @@ export function addDiagnostic(msg, opts) {
|
|
|
281
284
|
ts: now,
|
|
282
285
|
id: _nextDiagnosticId++,
|
|
283
286
|
};
|
|
284
|
-
var gate = _gateBuildNotice(msg, now);
|
|
285
|
-
if (gate.action === "skip") return;
|
|
286
|
-
entry.noticeKey = gate.key;
|
|
287
287
|
diagnostics.push(entry);
|
|
288
288
|
|
|
289
289
|
// Render the new entry in the panel list.
|
|
@@ -293,7 +293,7 @@ export function addDiagnostic(msg, opts) {
|
|
|
293
293
|
_updateBadge();
|
|
294
294
|
|
|
295
295
|
// Toast for warning and error severity only.
|
|
296
|
-
var toastAllowed = !(opts && opts.toast === false)
|
|
296
|
+
var toastAllowed = !(opts && opts.toast === false);
|
|
297
297
|
if (toastAllowed && (entry.severity === "warning" || entry.severity === "error")) {
|
|
298
298
|
_showDiagnosticToast(entry);
|
|
299
299
|
}
|
|
@@ -313,49 +313,48 @@ function _arrivalTime(msg) {
|
|
|
313
313
|
return Date.now();
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
-
// The standing build-update notice is replayed to every connection and refreshed
|
|
317
|
-
// while the build is stale; build-notice-gate.js decides whether this arrival
|
|
318
|
-
// adds, replaces, re-toasts or is dropped. Anything else passes through.
|
|
319
|
-
function _gateBuildNotice(msg, now) {
|
|
320
|
-
var key = noticeKeyOf(msg);
|
|
321
|
-
if (!key) return { action: "add", toast: true, key: null };
|
|
322
|
-
var held = diagnostics.filter(function (e) {
|
|
323
|
-
return e.source === BUILD_NOTICE_SOURCE && _actionOf(e) === BUILD_NOTICE_ACTION;
|
|
324
|
-
})[0] || null;
|
|
325
|
-
var decision = _noticeGate.decide({
|
|
326
|
-
key: key,
|
|
327
|
-
heldKey: held ? held.noticeKey || null : null,
|
|
328
|
-
toastOnScreen: held ? _toastsFor(BUILD_NOTICE_SOURCE, BUILD_NOTICE_ACTION).length > 0 : false,
|
|
329
|
-
now: now,
|
|
330
|
-
cooldownMs: cooldownOf(msg),
|
|
331
|
-
});
|
|
332
|
-
if (decision.action === "replace" || decision.action === "retract") {
|
|
333
|
-
retractDiagnostics(BUILD_NOTICE_SOURCE, BUILD_NOTICE_ACTION);
|
|
334
|
-
}
|
|
335
|
-
if (decision.action === "retract") return { action: "skip", toast: false, key: key };
|
|
336
|
-
if (decision.action === "retoast") {
|
|
337
|
-
_showDiagnosticToast(held);
|
|
338
|
-
return { action: "skip", toast: false, key: key };
|
|
339
|
-
}
|
|
340
|
-
return { action: decision.action, toast: decision.toast, key: key };
|
|
341
|
-
}
|
|
342
|
-
|
|
343
316
|
/**
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
317
|
+
* Shows the build-update offer a notification carries, as the diagnostics entry
|
|
318
|
+
* with the restart action. The core already collapsed repeats into the one
|
|
319
|
+
* notification, so this only replaces the entry it built from an earlier one;
|
|
320
|
+
* the same notification again (a reconnect's state) changes nothing. No toast:
|
|
321
|
+
* the notification's banner is the alert.
|
|
322
|
+
* @param {object} notif a build_update_offer notification.
|
|
348
323
|
*/
|
|
349
|
-
export function
|
|
350
|
-
var
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
324
|
+
export function applyBuildOffer(notif) {
|
|
325
|
+
var meta = notif && notif.meta;
|
|
326
|
+
if (!meta || !meta.buildUpdate) return;
|
|
327
|
+
var held = diagnostics.some(function (e) { return e.source === BUILD_NOTICE_SOURCE && _actionOf(e) === BUILD_NOTICE_ACTION; });
|
|
328
|
+
if (held && _offerNotifId === notif.id) return;
|
|
329
|
+
retractDiagnostics(BUILD_NOTICE_SOURCE, BUILD_NOTICE_ACTION);
|
|
330
|
+
_offerNotifId = notif.id;
|
|
331
|
+
addDiagnostic({
|
|
332
|
+
severity: 'warning',
|
|
333
|
+
source: BUILD_NOTICE_SOURCE,
|
|
334
|
+
message: meta.message || '',
|
|
335
|
+
buildUpdate: meta.buildUpdate,
|
|
336
|
+
actionable: meta.actionable || null,
|
|
337
|
+
}, { toast: false });
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** The offer was closed (installed, declined anywhere, or no longer stale). */
|
|
341
|
+
export function withdrawBuildOffer() {
|
|
342
|
+
_offerNotifId = null;
|
|
343
|
+
retractDiagnostics(BUILD_NOTICE_SOURCE, BUILD_NOTICE_ACTION);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Opens the panel the offer's restart action lives in. */
|
|
347
|
+
export function openDiagnosticsPanel() {
|
|
348
|
+
openPanel();
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// The operator closed the offer here: close its notification, which the core
|
|
352
|
+
// then closes on every other surface and device.
|
|
353
|
+
function _declineBuildOffer() {
|
|
354
|
+
if (!_offerNotifId) return;
|
|
355
|
+
var id = _offerNotifId;
|
|
356
|
+
_offerNotifId = null;
|
|
357
|
+
sendWs({ type: 'notification_dismiss', ids: [id] });
|
|
359
358
|
}
|
|
360
359
|
|
|
361
360
|
function _actionOf(entry) {
|
|
@@ -486,6 +485,7 @@ function _showDiagnosticToast(entry) {
|
|
|
486
485
|
var sessionsEl = buildSessionsEl(sessionLines);
|
|
487
486
|
if (sessionsEl) el.appendChild(sessionsEl);
|
|
488
487
|
var hasAction = _appendToastActions(el, entry, function () {
|
|
488
|
+
if (entry.source === BUILD_NOTICE_SOURCE) _declineBuildOffer();
|
|
489
489
|
clearTimeout(timer);
|
|
490
490
|
_removeDiagnosticToast(el);
|
|
491
491
|
});
|
|
@@ -505,7 +505,6 @@ function _showDiagnosticToast(entry) {
|
|
|
505
505
|
// Manual dismiss.
|
|
506
506
|
dismissBtn.addEventListener("click", function () {
|
|
507
507
|
clearTimeout(timer);
|
|
508
|
-
_noticeGate.toastClosed(entry.noticeKey, Date.now());
|
|
509
508
|
_removeDiagnosticToast(el);
|
|
510
509
|
});
|
|
511
510
|
|
|
@@ -515,8 +514,7 @@ function _showDiagnosticToast(entry) {
|
|
|
515
514
|
var fromButton = e.target && e.target.tagName === "BUTTON";
|
|
516
515
|
if (e.key === "Escape" || ((e.key === "Enter" || e.key === " ") && !fromButton)) {
|
|
517
516
|
clearTimeout(timer);
|
|
518
|
-
|
|
519
|
-
_removeDiagnosticToast(el);
|
|
517
|
+
_removeDiagnosticToast(el);
|
|
520
518
|
}
|
|
521
519
|
});
|
|
522
520
|
}
|
|
@@ -670,7 +668,7 @@ function dismissDiagnostic(id) {
|
|
|
670
668
|
if (diagnostics[i].id === id) { idx = i; break; }
|
|
671
669
|
}
|
|
672
670
|
if (idx === -1) return;
|
|
673
|
-
|
|
671
|
+
if (diagnostics[idx].source === BUILD_NOTICE_SOURCE) _declineBuildOffer();
|
|
674
672
|
diagnostics.splice(idx, 1);
|
|
675
673
|
|
|
676
674
|
if (panelListEl) {
|
|
@@ -689,8 +687,7 @@ function dismissDiagnostic(id) {
|
|
|
689
687
|
* no server-side dismiss contract (see module header note).
|
|
690
688
|
*/
|
|
691
689
|
function clearAllDiagnostics() {
|
|
692
|
-
|
|
693
|
-
diagnostics.forEach(function (entry) { _noticeGate.entryDismissed(entry.noticeKey, clearedAt); });
|
|
690
|
+
if (diagnostics.some(function (entry) { return entry.source === BUILD_NOTICE_SOURCE; })) _declineBuildOffer();
|
|
694
691
|
// Toasts for the cleared entries go too, so clear-all leaves nothing on screen.
|
|
695
692
|
Array.prototype.slice.call(_getToastContainer().querySelectorAll("[data-diag-source]")).forEach(_removeDiagnosticToast);
|
|
696
693
|
diagnostics = [];
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
// name and avatar helpers. A sender only gains identity here when it matches a
|
|
3
3
|
// known mate or agent; the match changes the display name and avatar and
|
|
4
4
|
// nothing else, so an injected entry never reads as the operator.
|
|
5
|
+
//
|
|
6
|
+
// The avatar of a sender that names an agent comes from the shared resolver
|
|
7
|
+
// (agent-avatar.js): the operator's choice for that agent when there is one,
|
|
8
|
+
// otherwise the avatar this module always gave it.
|
|
5
9
|
|
|
6
10
|
import { mateAvatarUrl } from "./avatar.js";
|
|
7
11
|
import { injectedSenderName } from "./injected-label.js";
|
|
12
|
+
import { resolveAgentAvatar, robotAvatarUrl, senderAgentKey } from "./agent-avatar.js";
|
|
8
13
|
|
|
9
14
|
// Fixed seeds keep the avatar of anonymous senders stable across renders.
|
|
10
15
|
var UNDECLARED_SEED = "undeclared-sender";
|
|
@@ -29,9 +34,17 @@ function findKnownIdentity(known, fromId, fromName) {
|
|
|
29
34
|
return null;
|
|
30
35
|
}
|
|
31
36
|
|
|
37
|
+
// agentKey is the roster key the sender is recorded under (null when it names no
|
|
38
|
+
// agent); defaultAvatarUrl is what it shows when the operator chose nothing.
|
|
39
|
+
function identityOf(injected, name, defaultAvatarUrl, matched, size) {
|
|
40
|
+
var agentKey = senderAgentKey(injected);
|
|
41
|
+
var avatarUrl = agentKey ? resolveAgentAvatar(agentKey, size, defaultAvatarUrl).url : defaultAvatarUrl;
|
|
42
|
+
return { name: name, avatarUrl: avatarUrl, defaultAvatarUrl: defaultAvatarUrl, agentKey: agentKey, matched: matched };
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
// injected: { senderKind, fromName, ... }; fromId: the recorded `from`;
|
|
33
46
|
// known: mates and agents as { id, name, agentName?, slug?, avatar fields }.
|
|
34
|
-
// Returns { name, avatarUrl, matched }.
|
|
47
|
+
// Returns { name, avatarUrl, defaultAvatarUrl, agentKey, matched }.
|
|
35
48
|
export function resolveInjectedIdentity(injected, fromId, known, size) {
|
|
36
49
|
var extracted = injected.senderKind === "extracted";
|
|
37
50
|
var declared = injected.senderKind === "declared" || extracted;
|
|
@@ -42,37 +55,27 @@ export function resolveInjectedIdentity(injected, fromId, known, size) {
|
|
|
42
55
|
? findKnownIdentity(known, undefined, injected.senderAgent)
|
|
43
56
|
: findKnownIdentity(known, fromId, injected.fromName);
|
|
44
57
|
if (hit) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
avatarUrl: mateAvatarUrl(hit, size),
|
|
48
|
-
matched: true,
|
|
49
|
-
};
|
|
58
|
+
var hitName = extracted ? injectedSenderName(injected) : (hit.name || hit.agentName || injectedSenderName(injected));
|
|
59
|
+
return identityOf(injected, hitName, mateAvatarUrl(hit, size), true, size);
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
62
|
// An extracted agent keeps its own avatar when the receiving project does not
|
|
53
63
|
// list it: same id the list would give it.
|
|
54
64
|
if (extracted && injected.senderAgentSlug) {
|
|
55
|
-
return {
|
|
56
|
-
name: injectedSenderName(injected),
|
|
57
|
-
avatarUrl: mateAvatarUrl({ id: injected.senderAgentSlug }, size),
|
|
58
|
-
matched: false,
|
|
59
|
-
};
|
|
65
|
+
return identityOf(injected, injectedSenderName(injected), mateAvatarUrl({ id: injected.senderAgentSlug }, size), false, size);
|
|
60
66
|
}
|
|
61
67
|
// The console's own automations keep one avatar each, whichever session or
|
|
62
68
|
// project they run in, and never match a mate or agent by name.
|
|
63
69
|
if (injected.senderKind === "automation") {
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
avatarUrl: mateAvatarUrl({ avatarStyle: "bottts", avatarSeed: AUTOMATION_SEED_PREFIX + (injected.fromName || "console") }, size),
|
|
67
|
-
matched: false,
|
|
68
|
-
};
|
|
70
|
+
return identityOf(injected, injectedSenderName(injected),
|
|
71
|
+
mateAvatarUrl({ avatarStyle: "bottts", avatarSeed: AUTOMATION_SEED_PREFIX + (injected.fromName || "console") }, size), false, size);
|
|
69
72
|
}
|
|
73
|
+
// A sender that names an agent shows that agent's seeded robot, the same one
|
|
74
|
+
// the roster and every other place that draws the agent start from.
|
|
75
|
+
var agentKey = senderAgentKey(injected);
|
|
76
|
+
if (agentKey) return identityOf(injected, injectedSenderName(injected), robotAvatarUrl(agentKey, size), false, size);
|
|
70
77
|
var seed = declared
|
|
71
78
|
? (injected.fromName || fromId || UNDECLARED_SEED)
|
|
72
79
|
: (injected.senderKind === "undeclared" ? UNDECLARED_SEED : UNRECORDED_SEED);
|
|
73
|
-
return {
|
|
74
|
-
name: injectedSenderName(injected),
|
|
75
|
-
avatarUrl: mateAvatarUrl({ avatarStyle: "bottts", avatarSeed: seed }, size),
|
|
76
|
-
matched: false,
|
|
77
|
-
};
|
|
80
|
+
return identityOf(injected, injectedSenderName(injected), mateAvatarUrl({ avatarStyle: "bottts", avatarSeed: seed }, size), false, size);
|
|
78
81
|
}
|
|
@@ -9,6 +9,9 @@ import { getScheduleDelayMs, getArmedSchedule, setArmedSchedule, canArmScheduled
|
|
|
9
9
|
import { createSchedulePanel } from './schedule-panel.js';
|
|
10
10
|
import { scheduleMessageFor, specLabel, specTitle } from './schedule-time.js';
|
|
11
11
|
import { sendScheduledNow, cancelScheduledInput } from './scheduled-input-actions.js';
|
|
12
|
+
import { currentSendNowState, isSendNowKey, isMacPlatform, initSendLongPress } from './send-now.js';
|
|
13
|
+
import { parseShellLine } from './shell-line.js';
|
|
14
|
+
import { isShellModeOn, isShellPending, hasQueuedChat, sendShellCommand, queueShellCommand, isTurnRunning, queueChatMessage, flushQueuedChat, restoreSetAsideDraft, registerComposer, registerChatSender, runQueuedShellNext, takeBackLastQueued, registerFrameSender, registerSocketProbe, registerDeliveredRenderer, chatQueuesWithAgent, trackSentChat, newMessageId } from './user-shell.js';
|
|
12
15
|
|
|
13
16
|
var ctx;
|
|
14
17
|
|
|
@@ -137,7 +140,31 @@ export var builtinCommands = [
|
|
|
137
140
|
];
|
|
138
141
|
|
|
139
142
|
// --- Send ---
|
|
140
|
-
|
|
143
|
+
// Whether the composer holds a ! command line that would be sent as a command.
|
|
144
|
+
function draftIsShellLine() {
|
|
145
|
+
var attached = pendingFiles.length > 0 || pendingPastes.length > 0 || pendingImages.length > 0;
|
|
146
|
+
return !attached && isShellModeOn() && parseShellLine(ctx.inputEl.value) !== null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Send-now (Ctrl/Cmd+Enter, or a long press of the send button on touch): the
|
|
150
|
+
// queued ! commands are set to run next (they still wait for a running turn),
|
|
151
|
+
// and the draft goes right away: into the running turn when the agent can take
|
|
152
|
+
// it, a normal send when no turn runs, and a stated refusal (the draft stays in
|
|
153
|
+
// the composer) when a turn runs on an agent that cannot take one. A ! draft
|
|
154
|
+
// is a command, which never goes into a turn: it queues like Enter.
|
|
155
|
+
export function sendNow() {
|
|
156
|
+
runQueuedShellNext();
|
|
157
|
+
if (!hasSendableContent()) return;
|
|
158
|
+
if (draftIsShellLine()) { sendMessage(); return; }
|
|
159
|
+
var st = currentSendNowState("chat");
|
|
160
|
+
if (st.mode === "disabled") {
|
|
161
|
+
ctx.addSystemMessage("Send now is unavailable: " + st.reason + " Use send to queue it for the next turn.", true);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
sendMessage({ sendNow: st.mode === "steer" });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function sendMessage(opts) {
|
|
141
168
|
// DM mode intercept: if in DM mode, route to DM handler instead
|
|
142
169
|
if (ctx.isDmMode && ctx.isDmMode() && ctx.handleDmSend) {
|
|
143
170
|
ctx.handleDmSend();
|
|
@@ -282,10 +309,93 @@ export function sendMessage() {
|
|
|
282
309
|
return;
|
|
283
310
|
}
|
|
284
311
|
|
|
285
|
-
|
|
286
|
-
|
|
312
|
+
// A line that starts with ! is a shell command, not a chat message: it goes as
|
|
313
|
+
// its own request, which the server checks and answers with a result card. The
|
|
314
|
+
// command is read from the composer as typed (parseShellLine drops only the !
|
|
315
|
+
// and the whitespace after it). Anything attached keeps it a chat message, and
|
|
316
|
+
// so does the mode being off: the line is then sent as ordinary text.
|
|
317
|
+
var hasAttachments = files.length > 0 || pendingPastes.length > 0 || images.length > 0;
|
|
318
|
+
var shellCommand = hasAttachments ? null : parseShellLine(ctx.inputEl.value);
|
|
319
|
+
if (shellCommand !== null && isShellModeOn()) {
|
|
320
|
+
// Held like native Claude Code does: a command typed during a turn, during
|
|
321
|
+
// another command, or behind earlier unsent entries waits in the queue and
|
|
322
|
+
// runs in order once the session is free.
|
|
323
|
+
if (isTurnRunning() || isShellPending() || hasQueuedChat()) {
|
|
324
|
+
queueShellCommand(shellCommand);
|
|
325
|
+
flushQueuedChat();
|
|
326
|
+
finishSend();
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (!sendShellCommand(shellCommand, transmitFrame)) {
|
|
330
|
+
ctx.addSystemMessage("Not connected — command not sent.", true);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
finishSend();
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
var steerNow = !!(opts && opts.sendNow);
|
|
338
|
+
// Chat waits on the page, shown as queued, while a command of this session
|
|
339
|
+
// runs, and behind any earlier message that is still unsent, so the order typed
|
|
340
|
+
// is the order sent. Otherwise it is sent now; if that cannot be done it stays
|
|
341
|
+
// in the composer.
|
|
342
|
+
// A message sent now into the running turn does not wait behind queued ! lines:
|
|
343
|
+
// they wait for the turn to end, and it goes into the turn at once.
|
|
344
|
+
if (steerNow && isTurnRunning() && !isShellPending()) {
|
|
345
|
+
if (!dispatchChat(text, images, pastes, steerNow)) {
|
|
346
|
+
ctx.addSystemMessage("Not connected — message not sent.", true);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
} else if (isShellPending() || hasQueuedChat()) {
|
|
350
|
+
queueChatMessage({ text: text, images: images, pastes: pastes, steerNow: steerNow });
|
|
351
|
+
flushQueuedChat();
|
|
352
|
+
} else if (!dispatchChat(text, images, pastes, steerNow)) {
|
|
353
|
+
ctx.addSystemMessage("Not connected — message not sent.", true);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
finishSend();
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Clears the composer after a send and brings back a draft an Edit set aside.
|
|
361
|
+
function finishSend() {
|
|
362
|
+
ctx.inputEl.value = "";
|
|
363
|
+
sendInputSync();
|
|
364
|
+
clearPendingImages();
|
|
365
|
+
autoResize();
|
|
366
|
+
ctx.inputEl.focus();
|
|
367
|
+
restoreSetAsideDraft();
|
|
368
|
+
// Input cleared — switch back to stop mode if still processing
|
|
369
|
+
if ((ctx.processing || isShellPending()) && ctx.setSendBtnMode) {
|
|
370
|
+
ctx.setSendBtnMode("stop");
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Sends one frame; true only when the socket was open and took it. A frame that
|
|
375
|
+
// was not sent is never treated as sent by the caller.
|
|
376
|
+
function transmitFrame(payload) {
|
|
377
|
+
var ws = ctx.ws;
|
|
378
|
+
if (!ws || ws.readyState !== 1) return false;
|
|
379
|
+
try {
|
|
380
|
+
ws.send(JSON.stringify(payload));
|
|
381
|
+
return true;
|
|
382
|
+
} catch (err) {
|
|
383
|
+
console.warn("[input] could not send:", (err && err.message) || err);
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
287
387
|
|
|
388
|
+
// Sends a chat message and, only once it was sent, records it in the
|
|
389
|
+
// conversation, so a send that fails shows nothing twice when it is tried again.
|
|
390
|
+
function dispatchChat(text, images, pastes, steerNow) {
|
|
288
391
|
var payload = { type: "message", text: text || "" };
|
|
392
|
+
if (steerNow) payload.sendNow = true;
|
|
393
|
+
// Sent into a running turn, a message waits at the agent until it takes it in;
|
|
394
|
+
// it is drawn as queued (with an id the server echoes back) until then. A
|
|
395
|
+
// message sent now into the turn, or to an agent that cannot withdraw one, is
|
|
396
|
+
// shown as sent, as it always was.
|
|
397
|
+
var messageId = !steerNow && chatQueuesWithAgent() ? newMessageId() : null;
|
|
398
|
+
if (messageId) payload.messageId = messageId;
|
|
289
399
|
if (images.length > 0) {
|
|
290
400
|
payload.images = images;
|
|
291
401
|
}
|
|
@@ -295,12 +405,28 @@ export function sendMessage() {
|
|
|
295
405
|
// Include selected vendor for session binding (server uses on first message)
|
|
296
406
|
var _selVendor = store.get("currentVendor") || null;
|
|
297
407
|
if (_selVendor) payload.vendor = _selVendor;
|
|
298
|
-
|
|
408
|
+
if (!transmitFrame(payload)) return false;
|
|
409
|
+
|
|
410
|
+
ctx.currentMsgTs = Date.now();
|
|
411
|
+
if (messageId) {
|
|
412
|
+
trackSentChat({ messageId: messageId, text: text, images: images, pastes: pastes });
|
|
413
|
+
} else {
|
|
414
|
+
showSentMessage(text, images, pastes);
|
|
415
|
+
}
|
|
299
416
|
|
|
300
417
|
// Hide vendor toggle after first message (vendor is locked to this session)
|
|
301
418
|
var _vtw2 = document.getElementById("vendor-toggle-wrap");
|
|
302
419
|
if (_vtw2) { _vtw2.classList.remove("hidden"); _vtw2.classList.add("locked"); }
|
|
303
420
|
store.set({ vendorSelectionLocked: false });
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Records a chat message in the conversation: when it was sent, or, for one that
|
|
425
|
+
// waited as queued, when the agent took it in.
|
|
426
|
+
function showSentMessage(text, images, pastes) {
|
|
427
|
+
// Not marked here: whether the message reached the running turn is only known
|
|
428
|
+
// to the server, which records the mark with the message.
|
|
429
|
+
ctx.addUserMessage(text, images.length > 0 ? images : null, pastes.length > 0 ? pastes : null);
|
|
304
430
|
|
|
305
431
|
// Show pre-thinking dots before server responds.
|
|
306
432
|
// Channel layout: rich pre-thinking bubble via showClaudePreThinking().
|
|
@@ -311,16 +437,6 @@ export function sendMessage() {
|
|
|
311
437
|
if (!document.body.classList.contains("wide-view") && ctx.setActivity) {
|
|
312
438
|
ctx.setActivity("thinking");
|
|
313
439
|
}
|
|
314
|
-
|
|
315
|
-
ctx.inputEl.value = "";
|
|
316
|
-
sendInputSync();
|
|
317
|
-
clearPendingImages();
|
|
318
|
-
autoResize();
|
|
319
|
-
ctx.inputEl.focus();
|
|
320
|
-
// Input cleared — switch back to stop mode if still processing
|
|
321
|
-
if (ctx.processing && ctx.setSendBtnMode) {
|
|
322
|
-
ctx.setSendBtnMode("stop");
|
|
323
|
-
}
|
|
324
440
|
}
|
|
325
441
|
|
|
326
442
|
var INPUT_MAX_HEIGHT = 120;
|
|
@@ -821,6 +937,15 @@ function createFileInput(accept, capture, multiple) {
|
|
|
821
937
|
input.click();
|
|
822
938
|
}
|
|
823
939
|
|
|
940
|
+
// Replaces the composer's text (a queued command taken back for editing).
|
|
941
|
+
function writeComposer(text) {
|
|
942
|
+
ctx.inputEl.value = text;
|
|
943
|
+
resetAutoResize();
|
|
944
|
+
autoResize();
|
|
945
|
+
ctx.inputEl.focus();
|
|
946
|
+
if (ctx.processing && ctx.setSendBtnMode) ctx.setSendBtnMode(hasSendableContent() ? "send" : "stop");
|
|
947
|
+
}
|
|
948
|
+
|
|
824
949
|
// --- Init ---
|
|
825
950
|
export function initInput(_ctx) {
|
|
826
951
|
ctx = _ctx;
|
|
@@ -828,6 +953,19 @@ export function initInput(_ctx) {
|
|
|
828
953
|
// Initialise the @ agent menu with the input context.
|
|
829
954
|
initAtAgents(ctx);
|
|
830
955
|
|
|
956
|
+
// The ! command line draws into the composer and sends queued chat through it.
|
|
957
|
+
registerComposer({
|
|
958
|
+
read: function () { return ctx.inputEl.value; },
|
|
959
|
+
write: writeComposer,
|
|
960
|
+
});
|
|
961
|
+
registerFrameSender(transmitFrame);
|
|
962
|
+
registerSocketProbe(function () { return ctx.ws; });
|
|
963
|
+
registerDeliveredRenderer(function (m) { showSentMessage(m.text, m.images, m.pastes); });
|
|
964
|
+
registerChatSender(function (entry) {
|
|
965
|
+
if (entry.kind === "shell") return sendShellCommand(entry.command, transmitFrame);
|
|
966
|
+
return dispatchChat(entry.text, entry.images, entry.pastes, entry.steerNow);
|
|
967
|
+
});
|
|
968
|
+
|
|
831
969
|
if (!slashMenuBound && ctx.slashMenu) {
|
|
832
970
|
slashMenuBound = true;
|
|
833
971
|
ctx.slashMenu.addEventListener("click", function (e) {
|
|
@@ -1113,6 +1251,25 @@ export function initInput(_ctx) {
|
|
|
1113
1251
|
return;
|
|
1114
1252
|
}
|
|
1115
1253
|
|
|
1254
|
+
if (isSendNowKey(e, isMacPlatform()) && !isComposing) {
|
|
1255
|
+
e.preventDefault();
|
|
1256
|
+
sendNow();
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
// Up on an empty composer takes back ONE queued entry for editing, as native
|
|
1261
|
+
// does: the last queued ! command when nothing but ! commands is held on the
|
|
1262
|
+
// page, otherwise the last chat message still waiting to be delivered (it is
|
|
1263
|
+
// withdrawn at the agent first, then put in the composer). Anything else
|
|
1264
|
+
// leaves Up alone.
|
|
1265
|
+
if (e.key === "ArrowUp" && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey && !isComposing &&
|
|
1266
|
+
ctx.inputEl.value === "" && !hasSendableContent()) {
|
|
1267
|
+
if (takeBackLastQueued(writeComposer)) {
|
|
1268
|
+
e.preventDefault();
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1116
1273
|
if (e.key === "Enter" && !e.shiftKey && !isComposing) {
|
|
1117
1274
|
// Mobile: Enter inserts newline, send via button only — except when
|
|
1118
1275
|
// input is empty and a ghost suggestion is showing, in which case
|
|
@@ -1160,6 +1317,10 @@ export function initInput(_ctx) {
|
|
|
1160
1317
|
ctx.inputEl.setAttribute("enterkeyhint", "enter");
|
|
1161
1318
|
}
|
|
1162
1319
|
|
|
1320
|
+
// Touch has no Ctrl key: a long press of the send button, with a message ready
|
|
1321
|
+
// during a turn, is send-now. Registered first so it can swallow its own click.
|
|
1322
|
+
initSendLongPress(ctx.sendBtn, function () { return !!ctx.processing && hasSendableContent(); }, sendNow);
|
|
1323
|
+
|
|
1163
1324
|
// Send/Stop button — gate on live state, not the button's CSS class.
|
|
1164
1325
|
// If Claude is processing and the user has nothing queued, the click
|
|
1165
1326
|
// is a Stop, never a send (no ghost-suggestion adoption from a Stop
|
|
@@ -1167,7 +1328,7 @@ export function initInput(_ctx) {
|
|
|
1167
1328
|
// and can drift on mobile after backgrounding/reconnect; predicating
|
|
1168
1329
|
// user-facing behavior on it wedges the input on mobile. (lr-e6b5 follow-up)
|
|
1169
1330
|
ctx.sendBtn.addEventListener("click", function () {
|
|
1170
|
-
if (ctx.processing && !hasSendableContent()) {
|
|
1331
|
+
if ((ctx.processing || isShellPending()) && !hasSendableContent()) {
|
|
1171
1332
|
if (ctx.connected) {
|
|
1172
1333
|
ctx.ws.send(JSON.stringify({ type: "stop" }));
|
|
1173
1334
|
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// The sign-in panel shown above a login terminal. The terminal stays the
|
|
2
|
+
// engine: the panel only offers the link the login printed, the code the login
|
|
3
|
+
// displayed, and a field that types the user's code back into that terminal.
|
|
4
|
+
//
|
|
5
|
+
// The URL and the code live only in this closure, and only while the panel is
|
|
6
|
+
// open. They are never logged, stored, or written to the page's persisted
|
|
7
|
+
// state, and remove() drops them.
|
|
8
|
+
|
|
9
|
+
import { displayHost } from './login-parser.js';
|
|
10
|
+
|
|
11
|
+
export var IDENTITY_NOTES = {
|
|
12
|
+
"os-users": "This sign-in applies to your own account on this host.",
|
|
13
|
+
"shared": "This sign-in applies to every user of this host.",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function el(tag, className, text) {
|
|
17
|
+
var node = document.createElement(tag);
|
|
18
|
+
if (className) node.className = className;
|
|
19
|
+
if (text !== undefined) node.textContent = text;
|
|
20
|
+
return node;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {object} opts
|
|
25
|
+
* @param {string} opts.vendorName agent display name, for the heading
|
|
26
|
+
* @param {string} [opts.identity] "os-users", "shared" or "" (no note)
|
|
27
|
+
* @param {function(string):void} opts.sendCode types text into the login terminal
|
|
28
|
+
* @param {function(string):void} opts.copy copies text to the clipboard
|
|
29
|
+
* @param {function(string):void} opts.openLink opens a URL in a new tab, noopener
|
|
30
|
+
* @param {function():void} opts.onDismiss user closed the panel
|
|
31
|
+
* @returns {{element: object, update: function, remove: function, setHidden: function, isOpen: function}}
|
|
32
|
+
*/
|
|
33
|
+
export function createLoginPanel(opts) {
|
|
34
|
+
var url = "";
|
|
35
|
+
var userCode = "";
|
|
36
|
+
var open = true;
|
|
37
|
+
|
|
38
|
+
var root = el("div", "login-panel");
|
|
39
|
+
root.setAttribute("role", "region");
|
|
40
|
+
root.setAttribute("aria-label", "Sign in to " + opts.vendorName);
|
|
41
|
+
|
|
42
|
+
var head = el("div", "login-panel-head");
|
|
43
|
+
head.appendChild(el("span", "login-panel-title", "Sign in to " + opts.vendorName));
|
|
44
|
+
var dismissBtn = el("button", "login-panel-dismiss", "Dismiss");
|
|
45
|
+
dismissBtn.setAttribute("type", "button");
|
|
46
|
+
head.appendChild(dismissBtn);
|
|
47
|
+
root.appendChild(head);
|
|
48
|
+
|
|
49
|
+
var hostEl = el("div", "login-panel-host");
|
|
50
|
+
root.appendChild(hostEl);
|
|
51
|
+
|
|
52
|
+
var linkRow = el("div", "login-panel-row login-panel-links");
|
|
53
|
+
var openBtn = el("button", "login-panel-btn login-panel-open", "Open link");
|
|
54
|
+
openBtn.setAttribute("type", "button");
|
|
55
|
+
var copyBtn = el("button", "login-panel-btn login-panel-copy-link", "Copy link");
|
|
56
|
+
copyBtn.setAttribute("type", "button");
|
|
57
|
+
linkRow.appendChild(openBtn);
|
|
58
|
+
linkRow.appendChild(copyBtn);
|
|
59
|
+
root.appendChild(linkRow);
|
|
60
|
+
|
|
61
|
+
var shownRow = el("div", "login-panel-row login-panel-shown-code");
|
|
62
|
+
shownRow.style.display = "none";
|
|
63
|
+
shownRow.appendChild(el("span", "login-panel-label", "Your sign-in code"));
|
|
64
|
+
var shownValue = el("code", "login-panel-code-value");
|
|
65
|
+
shownRow.appendChild(shownValue);
|
|
66
|
+
var copyCodeBtn = el("button", "login-panel-btn login-panel-copy-code", "Copy code");
|
|
67
|
+
copyCodeBtn.setAttribute("type", "button");
|
|
68
|
+
shownRow.appendChild(copyCodeBtn);
|
|
69
|
+
root.appendChild(shownRow);
|
|
70
|
+
|
|
71
|
+
var entryRow = el("div", "login-panel-row login-panel-code-entry");
|
|
72
|
+
entryRow.style.display = "none";
|
|
73
|
+
var input = el("input", "login-panel-code-input");
|
|
74
|
+
input.setAttribute("type", "text");
|
|
75
|
+
input.setAttribute("autocomplete", "off");
|
|
76
|
+
input.setAttribute("autocapitalize", "off");
|
|
77
|
+
input.setAttribute("autocorrect", "off");
|
|
78
|
+
input.setAttribute("spellcheck", "false");
|
|
79
|
+
input.setAttribute("placeholder", "Code from the sign-in page");
|
|
80
|
+
input.setAttribute("aria-label", "Code from the sign-in page");
|
|
81
|
+
var submitBtn = el("button", "login-panel-btn login-panel-submit", "Submit code");
|
|
82
|
+
submitBtn.setAttribute("type", "button");
|
|
83
|
+
entryRow.appendChild(input);
|
|
84
|
+
entryRow.appendChild(submitBtn);
|
|
85
|
+
root.appendChild(entryRow);
|
|
86
|
+
|
|
87
|
+
if (opts.identity && IDENTITY_NOTES[opts.identity]) {
|
|
88
|
+
root.appendChild(el("div", "login-panel-identity", IDENTITY_NOTES[opts.identity]));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function submit() {
|
|
92
|
+
var code = String(input.value || "").trim();
|
|
93
|
+
if (!code || !open) return;
|
|
94
|
+
input.value = "";
|
|
95
|
+
opts.sendCode(code + "\n");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
openBtn.addEventListener("click", function () { if (url) opts.openLink(url); });
|
|
99
|
+
copyBtn.addEventListener("click", function () { if (url) opts.copy(url); });
|
|
100
|
+
copyCodeBtn.addEventListener("click", function () { if (userCode) opts.copy(userCode); });
|
|
101
|
+
submitBtn.addEventListener("click", submit);
|
|
102
|
+
input.addEventListener("keydown", function (e) {
|
|
103
|
+
if (e && e.key === "Enter") submit();
|
|
104
|
+
});
|
|
105
|
+
dismissBtn.addEventListener("click", function () {
|
|
106
|
+
remove();
|
|
107
|
+
if (opts.onDismiss) opts.onDismiss();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
function remove() {
|
|
111
|
+
open = false;
|
|
112
|
+
url = "";
|
|
113
|
+
userCode = "";
|
|
114
|
+
input.value = "";
|
|
115
|
+
shownValue.textContent = "";
|
|
116
|
+
hostEl.textContent = "";
|
|
117
|
+
root.remove();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
element: root,
|
|
122
|
+
isOpen: function () { return open; },
|
|
123
|
+
remove: remove,
|
|
124
|
+
/** @param {{url: string, codePrompt: boolean, userCode: string}} parsed */
|
|
125
|
+
update: function (parsed) {
|
|
126
|
+
if (!open || !parsed) return;
|
|
127
|
+
url = parsed.url;
|
|
128
|
+
userCode = parsed.userCode || "";
|
|
129
|
+
hostEl.textContent = displayHost(url);
|
|
130
|
+
shownValue.textContent = userCode;
|
|
131
|
+
shownRow.style.display = userCode ? "" : "none";
|
|
132
|
+
entryRow.style.display = parsed.codePrompt ? "" : "none";
|
|
133
|
+
},
|
|
134
|
+
setHidden: function (hidden) { root.style.display = hidden ? "none" : ""; },
|
|
135
|
+
};
|
|
136
|
+
}
|