@clagentic/console 1.10.0 → 1.11.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 +14 -1
- package/bin/cli.js +38 -16
- package/lib/agents.js +1 -55
- package/lib/bash-auto-approve.js +133 -0
- package/lib/build-identity.js +23 -5
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +0 -62
- package/lib/build-update-offer.js +23 -13
- package/lib/build-update-restart.js +59 -43
- package/lib/cli/arg-validation.js +50 -0
- package/lib/cli/daemon-launch.js +5 -4
- package/lib/cli/menus.js +2 -2
- package/lib/cli/schedule-input-subcommands.js +327 -0
- package/lib/cli/session-subcommands.js +101 -17
- package/lib/client-build-id.js +56 -0
- package/lib/daemon.js +38 -6
- package/lib/identity/index.js +9 -4
- package/lib/injected-sender.js +225 -0
- package/lib/message-sender-record.js +133 -0
- package/lib/pending-prompts.js +55 -0
- package/lib/permission-mode-policy.js +63 -0
- package/lib/permission-settings.js +96 -0
- package/lib/permission-summary.js +67 -0
- package/lib/project-connection.js +10 -11
- package/lib/project-external-trigger.js +9 -1
- package/lib/project-loop.js +50 -23
- package/lib/project-permission-settings.js +59 -0
- package/lib/project-prompt-responses.js +25 -15
- package/lib/project-sessions.js +164 -60
- package/lib/project-user-message.js +18 -47
- package/lib/project.js +46 -74
- package/lib/public/app.js +4 -7
- package/lib/public/css/channel-layout.css +20 -0
- package/lib/public/css/diagnostics.css +7 -0
- package/lib/public/css/input.css +78 -0
- package/lib/public/css/menus.css +17 -0
- package/lib/public/css/overlays.css +0 -3
- package/lib/public/css/scheduler-modal.css +5 -0
- package/lib/public/index.html +44 -8
- package/lib/public/modules/app-connection.js +18 -1
- package/lib/public/modules/app-loop-ui.js +11 -1
- package/lib/public/modules/app-messages.js +23 -30
- package/lib/public/modules/app-panels.js +10 -3
- package/lib/public/modules/app-rate-limit.js +64 -88
- package/lib/public/modules/app-rendering.js +37 -6
- package/lib/public/modules/approve-tools-toggle.js +33 -0
- package/lib/public/modules/at-agents.js +8 -0
- package/lib/public/modules/build-guard.js +61 -0
- package/lib/public/modules/build-update-detail.js +1 -4
- package/lib/public/modules/diagnostics.js +98 -9
- package/lib/public/modules/injected-identity.js +78 -0
- package/lib/public/modules/injected-label.js +62 -0
- package/lib/public/modules/input.js +64 -114
- package/lib/public/modules/loop-hooks-warning.js +20 -0
- package/lib/public/modules/mode-options.js +35 -16
- package/lib/public/modules/permission-settings.js +56 -0
- package/lib/public/modules/project-settings.js +3 -0
- package/lib/public/modules/rate-limit-state.js +47 -22
- package/lib/public/modules/schedule-panel.js +234 -0
- package/lib/public/modules/schedule-time.js +193 -0
- package/lib/public/modules/scheduled-input-actions.js +19 -0
- package/lib/public/modules/scheduler-config.js +12 -0
- package/lib/public/modules/scheduler.js +8 -0
- package/lib/public/modules/server-settings.js +5 -9
- package/lib/public/modules/settings-defaults.js +18 -4
- package/lib/runtime-env.js +4 -0
- package/lib/scheduled-input/ipc.js +92 -0
- package/lib/scheduled-input/rate-limit-resume.js +53 -0
- package/lib/scheduled-input/records.js +350 -0
- package/lib/scheduled-input/service.js +743 -0
- package/lib/scheduled-input/store.js +132 -0
- package/lib/scheduled-input/ws.js +194 -0
- package/lib/scheduler.js +4 -0
- package/lib/sdk-bridge.js +194 -175
- package/lib/sdk-message-processor.js +13 -5
- package/lib/sdk-skill-discovery.js +17 -0
- package/lib/sender-ref.js +109 -0
- package/lib/server.js +37 -11
- package/lib/session-directory.js +224 -0
- package/lib/session-file-scan.js +55 -0
- package/lib/session-input-ipc.js +21 -0
- package/lib/session-input.js +396 -23
- package/lib/session-name-holder.js +82 -0
- package/lib/session-resume.js +3 -0
- package/lib/sessions.js +111 -2
- package/lib/turn-initiator.js +6 -2
- package/lib/updater.js +8 -2
- package/lib/ws-schema.js +20 -9
- package/lib/yoke/adapters/claude-worker.js +3 -1
- package/lib/yoke/adapters/claude.js +13 -17
- package/lib/yoke/adapters/codex.js +18 -5
- package/lib/yoke/adapters/permission-relay.js +9 -0
- package/lib/yoke/interface.js +7 -1
- package/package.json +1 -1
- package/scripts/check-test-count.js +1 -1
- package/scripts/install-local-test.js +45 -1
- package/scripts/postinstall.js +1 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Detects that the daemon now serves a different build than the one this page
|
|
2
|
+
// booted with, and gets the page onto the new client.
|
|
3
|
+
//
|
|
4
|
+
// The id arrives with every connect (the WebSocket info message and /info), so a
|
|
5
|
+
// tab that stayed open across a daemon restart notices on its reconnect, even
|
|
6
|
+
// when both builds carry the same package version.
|
|
7
|
+
//
|
|
8
|
+
// Reload versus banner: a reload drops what has not been sent yet, so with
|
|
9
|
+
// unsent input the guard shows a banner the user acts on instead, and reloads
|
|
10
|
+
// at once when there is nothing to lose.
|
|
11
|
+
|
|
12
|
+
export function createBuildGuard(deps) {
|
|
13
|
+
var booted = null;
|
|
14
|
+
var acted = false;
|
|
15
|
+
|
|
16
|
+
// Returns what happened, so callers and tests can tell the paths apart.
|
|
17
|
+
function observe(buildId) {
|
|
18
|
+
if (!buildId) return "ignored";
|
|
19
|
+
if (booted === null) {
|
|
20
|
+
booted = buildId;
|
|
21
|
+
return "booted";
|
|
22
|
+
}
|
|
23
|
+
if (buildId === booted) return "same";
|
|
24
|
+
if (acted) return "pending";
|
|
25
|
+
acted = true;
|
|
26
|
+
if (deps.hasUnsent()) {
|
|
27
|
+
deps.showBanner();
|
|
28
|
+
return "banner";
|
|
29
|
+
}
|
|
30
|
+
deps.reload();
|
|
31
|
+
return "reload";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Both ways the id arrives carry it as `buildId`: the WebSocket "info" message
|
|
35
|
+
// and the /info response. One entry point for both keeps them from drifting.
|
|
36
|
+
function observeInfo(info) {
|
|
37
|
+
return observe(info && info.buildId);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return { observe: observe, observeInfo: observeInfo };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Not dismissable: the page is running code the server no longer matches.
|
|
44
|
+
export function showReloadBanner(doc, reload) {
|
|
45
|
+
if (doc.getElementById("sw-update-banner")) return;
|
|
46
|
+
var banner = doc.createElement("div");
|
|
47
|
+
banner.id = "sw-update-banner";
|
|
48
|
+
banner.className = "sw-update-banner";
|
|
49
|
+
var text = doc.createElement("span");
|
|
50
|
+
text.className = "sw-update-banner-text";
|
|
51
|
+
text.textContent = "Clagentic: Console was updated. Reload to continue.";
|
|
52
|
+
var button = doc.createElement("button");
|
|
53
|
+
button.className = "sw-update-banner-btn";
|
|
54
|
+
button.id = "sw-update-reload";
|
|
55
|
+
button.textContent = "Reload";
|
|
56
|
+
button.addEventListener("click", reload);
|
|
57
|
+
banner.appendChild(text);
|
|
58
|
+
banner.appendChild(button);
|
|
59
|
+
doc.body.appendChild(banner);
|
|
60
|
+
banner.classList.add("visible");
|
|
61
|
+
}
|
|
@@ -30,10 +30,7 @@ export function buildUpdateDetailEl(offer) {
|
|
|
30
30
|
'Running: ' + shortSha(offer.loadedBuildSha) + ' Installed: ' + shortSha(offer.installedBuildSha)));
|
|
31
31
|
|
|
32
32
|
var changes = offer.changes || {};
|
|
33
|
-
if (
|
|
34
|
-
root.appendChild(line('build-update-note',
|
|
35
|
-
'Both report the same build, but the installed files differ from the ones this process loaded.'));
|
|
36
|
-
} else if (changes.available && Array.isArray(changes.commits) && changes.commits.length > 0) {
|
|
33
|
+
if (changes.available && Array.isArray(changes.commits) && changes.commits.length > 0) {
|
|
37
34
|
root.appendChild(line('build-update-heading', 'Changes since the running build:'));
|
|
38
35
|
var list = document.createElement('ul');
|
|
39
36
|
list.className = 'build-update-commits';
|
|
@@ -44,13 +44,78 @@ var _noticeGate = createNoticeGate();
|
|
|
44
44
|
// another diagnostic carrying a one-use token, and only its "Restart now"
|
|
45
45
|
// sends that token back.
|
|
46
46
|
var CONFIRM_BUILD_UPDATE = 'confirm_build_update_restart';
|
|
47
|
+
// A handler returns true only when its frame was handed to an open socket; a
|
|
48
|
+
// click that sent nothing must leave the button usable.
|
|
49
|
+
// Each request carries a requestId the daemon echoes in its result, so a result
|
|
50
|
+
// releases only the button whose click produced it.
|
|
47
51
|
var ACTIONABLE_HANDLERS = {
|
|
48
|
-
restart_for_build_update: function () {
|
|
49
|
-
|
|
52
|
+
restart_for_build_update: function (entry, requestId) {
|
|
53
|
+
return sendWs({ type: 'restart_for_build_update', requestId: requestId });
|
|
54
|
+
},
|
|
55
|
+
confirm_build_update_restart: function (entry, requestId) {
|
|
50
56
|
var token = entry.buildUpdate && entry.buildUpdate.token;
|
|
51
|
-
if (typeof token
|
|
57
|
+
if (typeof token !== 'string' || !token) return false;
|
|
58
|
+
return sendWs({ type: 'restart_for_build_update', confirmToken: token, requestId: requestId });
|
|
52
59
|
},
|
|
53
60
|
};
|
|
61
|
+
var _nextRequestId = 1;
|
|
62
|
+
|
|
63
|
+
// A click disables its button until the daemon answers. The answer is a
|
|
64
|
+
// restart_for_build_update_result frame, but a refused request (admin gate) or
|
|
65
|
+
// a reply lost with the socket is never followed by one, so the wait is bounded:
|
|
66
|
+
// a button that stayed dimmed for ever looked like a restart under way.
|
|
67
|
+
var REPLY_TIMEOUT_MS = 15000;
|
|
68
|
+
var SEND_FAILED_TEXT = "Not connected to Clagentic: Console right now. Wait for it to reconnect, then try again.";
|
|
69
|
+
var _awaitingReply = []; // [{btn, timer, requestId}]
|
|
70
|
+
|
|
71
|
+
function _setSendFailedNote(btn, text) {
|
|
72
|
+
var host = btn.parentNode;
|
|
73
|
+
if (!host) return;
|
|
74
|
+
var note = host.querySelectorAll(".build-update-send-failed")[0];
|
|
75
|
+
if (!text) {
|
|
76
|
+
if (note && note.parentNode) note.parentNode.removeChild(note);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (!note) {
|
|
80
|
+
note = document.createElement("div");
|
|
81
|
+
note.className = "build-update-send-failed";
|
|
82
|
+
host.appendChild(note);
|
|
83
|
+
}
|
|
84
|
+
note.textContent = text;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var NO_ANSWER_TEXT = "Clagentic: Console did not answer, so the restart may not have been requested. Try again.";
|
|
88
|
+
|
|
89
|
+
function _awaitReply(btn, requestId) {
|
|
90
|
+
var slot = { btn: btn, timer: null, requestId: requestId };
|
|
91
|
+
slot.timer = setTimeout(function () { _releaseSlot(slot, true, NO_ANSWER_TEXT); }, REPLY_TIMEOUT_MS);
|
|
92
|
+
_awaitingReply.push(slot);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function _releaseSlot(slot, reenable, note) {
|
|
96
|
+
clearTimeout(slot.timer);
|
|
97
|
+
_awaitingReply = _awaitingReply.filter(function (s) { return s !== slot; });
|
|
98
|
+
if (reenable) slot.btn.disabled = false;
|
|
99
|
+
if (note) _setSendFailedNote(slot.btn, note);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The daemon's answer to a restart request. `ok: true` means the restart is
|
|
104
|
+
* scheduled: the buttons stay disabled. Anything else (a fresh offer to
|
|
105
|
+
* confirm, a refusal, nothing to apply) gives the buttons back so the
|
|
106
|
+
* operator can act on what is now on screen.
|
|
107
|
+
*
|
|
108
|
+
* Only the slot whose requestId the result echoes is released; a result that
|
|
109
|
+
* names no pending request releases nothing (the slot's own timeout covers it).
|
|
110
|
+
*/
|
|
111
|
+
export function settleBuildUpdateRequest(result) {
|
|
112
|
+
var requestId = result && typeof result.requestId === "string" ? result.requestId : null;
|
|
113
|
+
if (!requestId) return;
|
|
114
|
+
var restarting = result.ok === true;
|
|
115
|
+
var refusal = !restarting && typeof result.error === "string" ? result.error : null;
|
|
116
|
+
_awaitingReply.filter(function (s) { return s.requestId === requestId; })
|
|
117
|
+
.forEach(function (slot) { _releaseSlot(slot, !restarting, refusal); });
|
|
118
|
+
}
|
|
54
119
|
|
|
55
120
|
// Shared by both render sites below (panel entry + toast). Returns
|
|
56
121
|
// a clickable button when entry.actionable.action is a known action, or null
|
|
@@ -65,8 +130,14 @@ function _buildActionableEl(entry, btnClass) {
|
|
|
65
130
|
btn.className = btnClass;
|
|
66
131
|
btn.textContent = entry.actionable.label;
|
|
67
132
|
btn.addEventListener("click", function () {
|
|
133
|
+
var requestId = "bu-" + (_nextRequestId++);
|
|
134
|
+
if (handler(entry, requestId) !== true) {
|
|
135
|
+
_setSendFailedNote(btn, SEND_FAILED_TEXT);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
_setSendFailedNote(btn, null);
|
|
68
139
|
btn.disabled = true;
|
|
69
|
-
|
|
140
|
+
_awaitReply(btn, requestId);
|
|
70
141
|
});
|
|
71
142
|
return btn;
|
|
72
143
|
}
|
|
@@ -192,7 +263,7 @@ export function initDiagnostics() {
|
|
|
192
263
|
// ============================================================
|
|
193
264
|
|
|
194
265
|
export function addDiagnostic(msg, opts) {
|
|
195
|
-
var now =
|
|
266
|
+
var now = _arrivalTime(msg);
|
|
196
267
|
|
|
197
268
|
// lr-e901: same condition can arrive via two independent emitters (CLI-stderr
|
|
198
269
|
// capture + deterministic preflight) - collapse to a single visible entry.
|
|
@@ -205,6 +276,7 @@ export function addDiagnostic(msg, opts) {
|
|
|
205
276
|
message: msg.message || "",
|
|
206
277
|
actionable: msg.actionable || null,
|
|
207
278
|
buildUpdate: msg.buildUpdate || null,
|
|
279
|
+
persistent: msg.persistent === true,
|
|
208
280
|
ts: now,
|
|
209
281
|
id: _nextDiagnosticId++,
|
|
210
282
|
};
|
|
@@ -226,6 +298,20 @@ export function addDiagnostic(msg, opts) {
|
|
|
226
298
|
}
|
|
227
299
|
}
|
|
228
300
|
|
|
301
|
+
// Only the newest restart confirmation is live: the daemon spends an offer's
|
|
302
|
+
// token on first use, so an older card would carry a dead one. A re-issued
|
|
303
|
+
// offer (expired token, or something changed) replaces it, even when its text
|
|
304
|
+
// matches the card it replaces.
|
|
305
|
+
// Returns the arrival time; the retraction happens before the duplicate check
|
|
306
|
+
// so the replaced card's text is no longer on record as seen.
|
|
307
|
+
function _arrivalTime(msg) {
|
|
308
|
+
if (_actionOf(msg) === CONFIRM_BUILD_UPDATE) retractDiagnostics(msg.source || "", CONFIRM_BUILD_UPDATE);
|
|
309
|
+
// A persistent state (a restart pending) is stated once however many times
|
|
310
|
+
// and from however many paths it arrives, so a repeat replaces its card.
|
|
311
|
+
if (msg.persistent === true) retractDiagnostics(msg.source || "");
|
|
312
|
+
return Date.now();
|
|
313
|
+
}
|
|
314
|
+
|
|
229
315
|
// The standing build-update notice is replayed to every connection and refreshed
|
|
230
316
|
// while the build is stale; build-notice-gate.js decides whether this arrival
|
|
231
317
|
// adds, replaces, re-toasts or is dropped. Anything else passes through.
|
|
@@ -408,8 +494,9 @@ function _showDiagnosticToast(entry) {
|
|
|
408
494
|
|
|
409
495
|
// Auto-dismiss after 6s — EXCEPT when an action button is present: an
|
|
410
496
|
// operator deciding whether to restart must not have the offer vanish out
|
|
411
|
-
// from under them before they've read it.
|
|
412
|
-
|
|
497
|
+
// from under them before they've read it. Likewise a persistent state (a
|
|
498
|
+
// restart pending) stays until the operator closes it or the page reloads.
|
|
499
|
+
var timer = (hasAction || entry.persistent) ? null : setTimeout(function () { _removeDiagnosticToast(el); }, 6000);
|
|
413
500
|
|
|
414
501
|
// Manual dismiss.
|
|
415
502
|
dismissBtn.addEventListener("click", function () {
|
|
@@ -418,9 +505,11 @@ function _showDiagnosticToast(entry) {
|
|
|
418
505
|
_removeDiagnosticToast(el);
|
|
419
506
|
});
|
|
420
507
|
|
|
421
|
-
// Keyboard dismiss.
|
|
508
|
+
// Keyboard dismiss. Enter and Space bubble up from the toast's own buttons
|
|
509
|
+
// when they are activated; that must activate the button, not close the card.
|
|
422
510
|
el.addEventListener("keydown", function (e) {
|
|
423
|
-
|
|
511
|
+
var fromButton = e.target && e.target.tagName === "BUTTON";
|
|
512
|
+
if (e.key === "Escape" || ((e.key === "Enter" || e.key === " ") && !fromButton)) {
|
|
424
513
|
clearTimeout(timer);
|
|
425
514
|
_noticeGate.toastClosed(entry.noticeKey, Date.now());
|
|
426
515
|
_removeDiagnosticToast(el);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Maps the recorded sender of an injected message onto the existing
|
|
2
|
+
// name and avatar helpers. A sender only gains identity here when it matches a
|
|
3
|
+
// known mate or agent; the match changes the display name and avatar and
|
|
4
|
+
// nothing else, so an injected entry never reads as the operator.
|
|
5
|
+
|
|
6
|
+
import { mateAvatarUrl } from "./avatar.js";
|
|
7
|
+
import { injectedSenderName } from "./injected-label.js";
|
|
8
|
+
|
|
9
|
+
// Fixed seeds keep the avatar of anonymous senders stable across renders.
|
|
10
|
+
var UNDECLARED_SEED = "undeclared-sender";
|
|
11
|
+
var UNRECORDED_SEED = "unrecorded-sender";
|
|
12
|
+
var AUTOMATION_SEED_PREFIX = "console-automation:";
|
|
13
|
+
|
|
14
|
+
function norm(value) {
|
|
15
|
+
return typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function findKnownIdentity(known, fromId, fromName) {
|
|
19
|
+
var keys = [norm(fromId), norm(fromName)].filter(Boolean);
|
|
20
|
+
if (!keys.length || !Array.isArray(known)) return null;
|
|
21
|
+
for (var i = 0; i < known.length; i++) {
|
|
22
|
+
var entry = known[i];
|
|
23
|
+
if (!entry) continue;
|
|
24
|
+
var names = [entry.id, entry.agentName, entry.name, entry.slug].map(norm);
|
|
25
|
+
for (var k = 0; k < keys.length; k++) {
|
|
26
|
+
if (names.indexOf(keys[k]) !== -1) return entry;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// injected: { senderKind, fromName, ... }; fromId: the recorded `from`;
|
|
33
|
+
// known: mates and agents as { id, name, agentName?, slug?, avatar fields }.
|
|
34
|
+
// Returns { name, avatarUrl, matched }.
|
|
35
|
+
export function resolveInjectedIdentity(injected, fromId, known, size) {
|
|
36
|
+
var extracted = injected.senderKind === "extracted";
|
|
37
|
+
var declared = injected.senderKind === "declared" || extracted;
|
|
38
|
+
if (declared) {
|
|
39
|
+
// An extracted sender is matched on its agent name; its fromName is the
|
|
40
|
+
// "<agent>@<project>" label, which names no agent by itself.
|
|
41
|
+
var hit = extracted
|
|
42
|
+
? findKnownIdentity(known, undefined, injected.senderAgent)
|
|
43
|
+
: findKnownIdentity(known, fromId, injected.fromName);
|
|
44
|
+
if (hit) {
|
|
45
|
+
return {
|
|
46
|
+
name: extracted ? injectedSenderName(injected) : (hit.name || hit.agentName || injectedSenderName(injected)),
|
|
47
|
+
avatarUrl: mateAvatarUrl(hit, size),
|
|
48
|
+
matched: true,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// An extracted agent keeps its own avatar when the receiving project does not
|
|
53
|
+
// list it: same id the list would give it.
|
|
54
|
+
if (extracted && injected.senderAgentSlug) {
|
|
55
|
+
return {
|
|
56
|
+
name: injectedSenderName(injected),
|
|
57
|
+
avatarUrl: mateAvatarUrl({ id: injected.senderAgentSlug }, size),
|
|
58
|
+
matched: false,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// The console's own automations keep one avatar each, whichever session or
|
|
62
|
+
// project they run in, and never match a mate or agent by name.
|
|
63
|
+
if (injected.senderKind === "automation") {
|
|
64
|
+
return {
|
|
65
|
+
name: injectedSenderName(injected),
|
|
66
|
+
avatarUrl: mateAvatarUrl({ avatarStyle: "bottts", avatarSeed: AUTOMATION_SEED_PREFIX + (injected.fromName || "console") }, size),
|
|
67
|
+
matched: false,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
var seed = declared
|
|
71
|
+
? (injected.fromName || fromId || UNDECLARED_SEED)
|
|
72
|
+
: (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
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Text shown for a message that another process injected into the session.
|
|
2
|
+
// senderKind is extracted (derived from the console's own records; fromName is
|
|
3
|
+
// "<agent or vendor>@<project>", always, even within the same project), declared
|
|
4
|
+
// (the caller named itself), undeclared (it named nobody) or unrecorded (a
|
|
5
|
+
// legacy entry). Never the operator's name.
|
|
6
|
+
|
|
7
|
+
export function injectedSenderName(injected) {
|
|
8
|
+
if ((injected.senderKind === "declared" || injected.senderKind === "extracted" || injected.senderKind === "automation") && injected.fromName) return injected.fromName;
|
|
9
|
+
if (injected.senderKind === "undeclared") return "Undeclared sender";
|
|
10
|
+
return "injected (sender not recorded)";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// A run-now is the same schedule fired early; the label says so.
|
|
14
|
+
var INITIATOR_TEXT = { "scheduled-now": "scheduled · sent now" };
|
|
15
|
+
|
|
16
|
+
// "trigger · note · declared": who injected, why, and how far the name can be trusted.
|
|
17
|
+
// "loop · job-hunter · iteration 3": a turn the console composed itself.
|
|
18
|
+
export function injectedLabel(injected) {
|
|
19
|
+
var parts = [];
|
|
20
|
+
if (injected.initiator) parts.push(INITIATOR_TEXT[injected.initiator] || injected.initiator);
|
|
21
|
+
if (injected.contextNote) parts.push(injected.contextNote);
|
|
22
|
+
if (injected.senderKind === "declared" || injected.senderKind === "undeclared" || injected.senderKind === "extracted") {
|
|
23
|
+
parts.push(injected.senderKind);
|
|
24
|
+
}
|
|
25
|
+
// A --from that names someone else is shown beside the extracted identity.
|
|
26
|
+
if (injected.senderKind === "extracted" && injected.declaredName) parts.push("declared as " + injected.declaredName);
|
|
27
|
+
return parts.join(" · ");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// The full sender session id, for hover or tap: it tells apart two sessions with
|
|
31
|
+
// the same agent and project, which the label does not. "" when not recorded.
|
|
32
|
+
export function injectedSessionNote(injected) {
|
|
33
|
+
if (injected.senderKind !== "extracted" || !injected.senderSessionId) return "";
|
|
34
|
+
return "session " + injected.senderSessionId;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The record-format marker lib/injected-sender.js stamps on every new entry.
|
|
38
|
+
// A marked entry always names its initiator, so one that does not fails closed:
|
|
39
|
+
// it is not the operator's. An unmarked entry is legacy and renders as before,
|
|
40
|
+
// the operator's unless the server completed a sender onto it.
|
|
41
|
+
function isMarked(msg) {
|
|
42
|
+
return typeof msg.entryFormat === "number" && msg.entryFormat >= 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The injected descriptor for a user_message, or null for one the operator typed.
|
|
46
|
+
export function injectedFromMessage(msg) {
|
|
47
|
+
if (isMarked(msg)) {
|
|
48
|
+
if (msg.initiator === "human" && !msg.senderKind) return null;
|
|
49
|
+
} else if (!msg.senderKind) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
senderKind: msg.senderKind || "unrecorded",
|
|
54
|
+
fromName: msg.fromName,
|
|
55
|
+
initiator: msg.initiator,
|
|
56
|
+
contextNote: msg.contextNote,
|
|
57
|
+
senderAgent: msg.senderAgent,
|
|
58
|
+
senderAgentSlug: msg.senderAgentSlug,
|
|
59
|
+
senderSessionId: msg.senderSessionId,
|
|
60
|
+
declaredName: msg.declaredName,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -5,7 +5,10 @@ import { checkForMention, showMentionMenu, hideMentionMenu, isMentionMenuVisible
|
|
|
5
5
|
import { initAtAgents, showAgentMenu, hideAgentMenu, isAgentMenuActive, agentMenuKeydown, requestProjectAgents } from './at-agents.js';
|
|
6
6
|
import { store } from './store.js';
|
|
7
7
|
import { sendWsQuiet } from './ws-ref.js';
|
|
8
|
-
import { getScheduleDelayMs,
|
|
8
|
+
import { getScheduleDelayMs, getArmedSchedule, setArmedSchedule, canArmScheduledInput, getScheduledInputs } from './rate-limit-state.js';
|
|
9
|
+
import { createSchedulePanel } from './schedule-panel.js';
|
|
10
|
+
import { scheduleMessageFor, specLabel, specTitle } from './schedule-time.js';
|
|
11
|
+
import { sendScheduledNow, cancelScheduledInput } from './scheduled-input-actions.js';
|
|
9
12
|
|
|
10
13
|
var ctx;
|
|
11
14
|
|
|
@@ -23,7 +26,8 @@ var isRemoteInput = false;
|
|
|
23
26
|
// module-scoped variable — that was the root cause of arming in one project
|
|
24
27
|
// silently overwriting another project's armed state, since the SPA never
|
|
25
28
|
// reloads the page on project switch).
|
|
26
|
-
var
|
|
29
|
+
var _showArmedScheduleFn = null; // set by initInput: paints the clock button
|
|
30
|
+
var _schedulePanel = null; // set by initInput
|
|
27
31
|
var slashMenuBound = false;
|
|
28
32
|
|
|
29
33
|
function currentSessionId() {
|
|
@@ -46,14 +50,20 @@ export function getScheduleDelay(sessionId) {
|
|
|
46
50
|
return getScheduleDelayMs(sessionId === undefined ? currentSessionId() : sessionId);
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
// Arms (or disarms, with
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
53
|
+
// Arms (or disarms, with null) what the next typed message of a session is
|
|
54
|
+
// scheduled as: { kind: "once", delayMs | atMs } or { kind: "recurring",
|
|
55
|
+
// everyMs, untilMs | count }. Only touches the visible schedule button when
|
|
56
|
+
// sessionId is the currently focused session — arming a background session
|
|
57
|
+
// (e.g. a rate-limit hit in a project the user isn't looking at) must not
|
|
58
|
+
// repaint the UI for whatever session IS focused (lr-0827ba).
|
|
59
|
+
export function setArmedScheduleForSession(sessionId, spec) {
|
|
60
|
+
setArmedSchedule(sessionId, spec);
|
|
61
|
+
if (sessionId === currentSessionId() && _showArmedScheduleFn) _showArmedScheduleFn(spec);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Arms (or disarms, with ms=0) an "in N minutes" delay for a specific session.
|
|
54
65
|
export function setScheduleDelayForSession(sessionId, ms) {
|
|
55
|
-
|
|
56
|
-
if (sessionId === currentSessionId() && _setScheduleDelayFn) _setScheduleDelayFn(ms);
|
|
66
|
+
setArmedScheduleForSession(sessionId, ms > 0 ? { kind: "once", delayMs: ms } : null);
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
// Arms (or disarms, with ms=0) the schedule delay for the currently active
|
|
@@ -66,19 +76,18 @@ export function setScheduleDelayMs(ms) {
|
|
|
66
76
|
// without re-triggering any arm/disarm side effects — used when switching
|
|
67
77
|
// back into a session that has a background-armed schedule (lr-0827ba).
|
|
68
78
|
export function restoreScheduleDelayUi() {
|
|
69
|
-
if (
|
|
79
|
+
if (_showArmedScheduleFn) _showArmedScheduleFn(getArmedSchedule(currentSessionId()));
|
|
70
80
|
}
|
|
71
81
|
|
|
72
82
|
export function clearScheduleDelayForSession(sessionId) {
|
|
73
|
-
|
|
83
|
+
setArmedSchedule(sessionId, null);
|
|
74
84
|
if (sessionId !== currentSessionId()) return;
|
|
85
|
+
if (_showArmedScheduleFn) { _showArmedScheduleFn(null); return; }
|
|
75
86
|
var btn = document.getElementById("schedule-btn");
|
|
76
87
|
if (btn) {
|
|
77
88
|
btn.classList.remove("schedule-active", "schedule-expanded");
|
|
78
89
|
var lbl = btn.querySelector(".schedule-delay-label");
|
|
79
90
|
if (lbl) lbl.remove();
|
|
80
|
-
var inp = btn.querySelector(".schedule-inline-input");
|
|
81
|
-
if (inp) inp.remove();
|
|
82
91
|
btn.title = "Schedule message";
|
|
83
92
|
}
|
|
84
93
|
}
|
|
@@ -87,17 +96,20 @@ export function clearScheduleDelay() {
|
|
|
87
96
|
clearScheduleDelayForSession(currentSessionId());
|
|
88
97
|
}
|
|
89
98
|
|
|
90
|
-
|
|
99
|
+
// Recomputes the button from the on-screen session's own list of scheduled
|
|
100
|
+
// inputs. The button always opens the panel, also at the cap, because the
|
|
101
|
+
// panel is where a queued input is cancelled or sent now; at the cap only the
|
|
102
|
+
// panel's Schedule control is off (see schedule-panel.js). The button just says
|
|
103
|
+
// so in its tooltip.
|
|
104
|
+
export function refreshScheduleControls() {
|
|
91
105
|
var btn = document.getElementById("schedule-btn");
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
if (disabled) {
|
|
95
|
-
btn.style.opacity = "0.3";
|
|
96
|
-
btn.style.pointerEvents = "none";
|
|
97
|
-
} else {
|
|
106
|
+
if (btn) {
|
|
107
|
+
btn.disabled = false;
|
|
98
108
|
btn.style.opacity = "";
|
|
99
109
|
btn.style.pointerEvents = "";
|
|
110
|
+
if (btn.classList) btn.classList.toggle("schedule-at-cap", !canArmScheduledInput(currentSessionId()));
|
|
100
111
|
}
|
|
112
|
+
if (_schedulePanel) _schedulePanel.refresh();
|
|
101
113
|
}
|
|
102
114
|
|
|
103
115
|
export var builtinCommands = [
|
|
@@ -257,11 +269,10 @@ export function sendMessage() {
|
|
|
257
269
|
return;
|
|
258
270
|
}
|
|
259
271
|
|
|
260
|
-
// Scheduled
|
|
261
|
-
var
|
|
262
|
-
if (
|
|
263
|
-
|
|
264
|
-
ctx.ws.send(JSON.stringify({ type: "schedule_message", text: text || "", resetsAt: resetsAt }));
|
|
272
|
+
// Scheduled input: the armed schedule (once or a repeat) takes this message.
|
|
273
|
+
var _armedSchedule = getArmedSchedule(currentSessionId());
|
|
274
|
+
if (_armedSchedule) {
|
|
275
|
+
ctx.ws.send(JSON.stringify(scheduleMessageFor(_armedSchedule, text || "", Date.now())));
|
|
265
276
|
clearScheduleDelay();
|
|
266
277
|
ctx.inputEl.value = "";
|
|
267
278
|
sendInputSync();
|
|
@@ -879,109 +890,48 @@ export function initInput(_ctx) {
|
|
|
879
890
|
});
|
|
880
891
|
}
|
|
881
892
|
|
|
882
|
-
// Schedule button —
|
|
893
|
+
// Schedule button — opens the schedule panel (once or repeat, and the
|
|
894
|
+
// session's armed scheduled inputs). Armed, it shows what the next typed
|
|
895
|
+
// message is scheduled as; clicking it then clears that.
|
|
883
896
|
var scheduleBtn = document.getElementById("schedule-btn");
|
|
884
|
-
var
|
|
885
|
-
var scheduleInlineLabel = null;
|
|
886
|
-
var scheduleOutsideHandler = null;
|
|
887
|
-
|
|
888
|
-
function formatDelayLabel(ms) {
|
|
889
|
-
var mins = Math.round(ms / 60000);
|
|
890
|
-
if (mins < 60) return mins + "m";
|
|
891
|
-
var hrs = Math.floor(mins / 60);
|
|
892
|
-
var rem = mins % 60;
|
|
893
|
-
return rem > 0 ? hrs + "h " + rem + "m" : hrs + "h";
|
|
894
|
-
}
|
|
897
|
+
var scheduleLabelEl = null;
|
|
895
898
|
|
|
896
|
-
|
|
899
|
+
// Paints the clock button for an armed schedule, or none.
|
|
900
|
+
function showArmedSchedule(spec) {
|
|
897
901
|
if (!scheduleBtn) return;
|
|
898
|
-
|
|
899
|
-
if (
|
|
900
|
-
if (scheduleInlineLabel) { scheduleInlineLabel.remove(); scheduleInlineLabel = null; }
|
|
901
|
-
if (scheduleOutsideHandler) {
|
|
902
|
-
document.removeEventListener("mousedown", scheduleOutsideHandler);
|
|
903
|
-
scheduleOutsideHandler = null;
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
function setScheduleDelay(ms) {
|
|
908
|
-
setSessionScheduleDelayMs(currentSessionId(), ms);
|
|
909
|
-
if (!scheduleBtn) return;
|
|
910
|
-
collapseScheduleBtn();
|
|
911
|
-
if (ms > 0) {
|
|
912
|
-
scheduleBtn.classList.add("schedule-active", "schedule-expanded");
|
|
913
|
-
scheduleBtn.title = "Scheduled: " + formatDelayLabel(ms) + " (click to clear)";
|
|
914
|
-
scheduleInlineLabel = document.createElement("span");
|
|
915
|
-
scheduleInlineLabel.className = "schedule-delay-label";
|
|
916
|
-
scheduleInlineLabel.textContent = formatDelayLabel(ms);
|
|
917
|
-
scheduleBtn.appendChild(scheduleInlineLabel);
|
|
918
|
-
} else {
|
|
902
|
+
if (scheduleLabelEl) { scheduleLabelEl.remove(); scheduleLabelEl = null; }
|
|
903
|
+
if (!spec) {
|
|
919
904
|
scheduleBtn.classList.remove("schedule-active", "schedule-expanded");
|
|
920
905
|
scheduleBtn.title = "Schedule message";
|
|
906
|
+
return;
|
|
921
907
|
}
|
|
908
|
+
scheduleBtn.classList.add("schedule-active", "schedule-expanded");
|
|
909
|
+
scheduleBtn.title = "Scheduled: " + specTitle(spec, Date.now()) + " (click to clear)";
|
|
910
|
+
scheduleLabelEl = document.createElement("span");
|
|
911
|
+
scheduleLabelEl.className = "schedule-delay-label";
|
|
912
|
+
scheduleLabelEl.textContent = specLabel(spec);
|
|
913
|
+
scheduleBtn.appendChild(scheduleLabelEl);
|
|
922
914
|
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
function expandScheduleInput() {
|
|
926
|
-
if (!scheduleBtn) return;
|
|
927
|
-
scheduleBtn.classList.add("schedule-expanded");
|
|
928
|
-
scheduleInlineInput = document.createElement("input");
|
|
929
|
-
scheduleInlineInput.type = "number";
|
|
930
|
-
scheduleInlineInput.min = "1";
|
|
931
|
-
scheduleInlineInput.max = "1440";
|
|
932
|
-
scheduleInlineInput.placeholder = "min";
|
|
933
|
-
scheduleInlineInput.className = "schedule-inline-input";
|
|
934
|
-
scheduleBtn.appendChild(scheduleInlineInput);
|
|
935
|
-
|
|
936
|
-
setTimeout(function () { scheduleInlineInput.focus(); }, 0);
|
|
937
|
-
|
|
938
|
-
scheduleInlineInput.addEventListener("click", function (e) { e.stopPropagation(); });
|
|
939
|
-
scheduleInlineInput.addEventListener("keydown", function (e) {
|
|
940
|
-
if (e.key === "Enter") {
|
|
941
|
-
e.preventDefault();
|
|
942
|
-
var val = parseInt(scheduleInlineInput.value, 10);
|
|
943
|
-
if (val >= 1 && val <= 1440) {
|
|
944
|
-
setScheduleDelay(val * 60000);
|
|
945
|
-
} else {
|
|
946
|
-
collapseScheduleBtn();
|
|
947
|
-
}
|
|
948
|
-
} else if (e.key === "Escape") {
|
|
949
|
-
collapseScheduleBtn();
|
|
950
|
-
}
|
|
951
|
-
});
|
|
915
|
+
_showArmedScheduleFn = showArmedSchedule;
|
|
952
916
|
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
} else {
|
|
962
|
-
collapseScheduleBtn();
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
document.removeEventListener("mousedown", scheduleOutsideHandler);
|
|
966
|
-
scheduleOutsideHandler = null;
|
|
967
|
-
}
|
|
968
|
-
};
|
|
969
|
-
document.addEventListener("mousedown", scheduleOutsideHandler);
|
|
970
|
-
}, 0);
|
|
971
|
-
}
|
|
917
|
+
_schedulePanel = scheduleBtn ? createSchedulePanel({
|
|
918
|
+
anchorEl: scheduleBtn,
|
|
919
|
+
getInputs: function () { return getScheduledInputs(currentSessionId()); },
|
|
920
|
+
canArm: function () { return canArmScheduledInput(currentSessionId()); },
|
|
921
|
+
onArm: function (spec) { setArmedScheduleForSession(currentSessionId(), spec); },
|
|
922
|
+
onSendNow: sendScheduledNow,
|
|
923
|
+
onCancel: cancelScheduledInput,
|
|
924
|
+
}) : null;
|
|
972
925
|
|
|
973
926
|
if (scheduleBtn) {
|
|
974
927
|
scheduleBtn.addEventListener("click", function (e) {
|
|
975
928
|
e.stopPropagation();
|
|
976
|
-
if (
|
|
977
|
-
|
|
929
|
+
if (getArmedSchedule(currentSessionId())) {
|
|
930
|
+
_schedulePanel.close();
|
|
931
|
+
setArmedScheduleForSession(currentSessionId(), null);
|
|
978
932
|
return;
|
|
979
933
|
}
|
|
980
|
-
|
|
981
|
-
collapseScheduleBtn();
|
|
982
|
-
} else {
|
|
983
|
-
expandScheduleInput();
|
|
984
|
-
}
|
|
934
|
+
_schedulePanel.toggle();
|
|
985
935
|
});
|
|
986
936
|
}
|
|
987
937
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// loop-hooks-warning.js - the notice shown on a loop's settings when its
|
|
2
|
+
// LOOP.json turns hooks off (settings.disableAllHooks). The setting is the
|
|
3
|
+
// loop author's own and is kept as written; this only says what it does.
|
|
4
|
+
// disableAllHooks is not limited to a loop's own hooks: it also turns off the
|
|
5
|
+
// hooks you set up yourself, including PreToolUse guard hooks that block or
|
|
6
|
+
// confirm tool calls. Import-free so it can be exercised without the frontend
|
|
7
|
+
// module graph.
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The warning card, or an empty string when the loop does not turn hooks off.
|
|
11
|
+
* @param {?object} settings - the loop's LOOP.json settings.
|
|
12
|
+
* @returns {string} HTML.
|
|
13
|
+
*/
|
|
14
|
+
export function loopHooksWarningHtml(settings) {
|
|
15
|
+
if (!settings || settings.disableAllHooks !== true) return "";
|
|
16
|
+
return '<div class="settings-card"><div class="settings-field">' +
|
|
17
|
+
'<span class="settings-label">Hooks are turned off for this loop</span>' +
|
|
18
|
+
'<div class="settings-hint" role="alert">This loop sets disableAllHooks. That also turns off your own hooks, including PreToolUse guard hooks, so a guard you rely on will not run for this loop’s tool calls.</div>' +
|
|
19
|
+
'</div></div>';
|
|
20
|
+
}
|