@clagentic/console 1.10.0-beta.4 → 1.11.0-beta.1
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 -0
- package/bin/cli.js +15 -3
- 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/schedule-input-subcommands.js +327 -0
- package/lib/cli/session-subcommands.js +100 -17
- package/lib/client-build-id.js +56 -0
- package/lib/daemon.js +20 -5
- 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-summary.js +67 -0
- package/lib/project-connection.js +2 -1
- package/lib/project-external-trigger.js +9 -1
- package/lib/project-loop.js +26 -20
- package/lib/project-prompt-responses.js +20 -14
- package/lib/project-sessions.js +73 -21
- package/lib/project-user-message.js +18 -47
- package/lib/project.js +36 -62
- package/lib/public/app.js +3 -5
- 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/modules/app-connection.js +18 -1
- package/lib/public/modules/app-messages.js +19 -17
- package/lib/public/modules/app-panels.js +9 -2
- package/lib/public/modules/app-rate-limit.js +63 -87
- package/lib/public/modules/app-rendering.js +37 -6
- 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/mode-options.js +19 -16
- 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/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/sdk-bridge.js +137 -152
- 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 +28 -8
- package/lib/session-directory.js +224 -0
- package/lib/session-file-scan.js +55 -0
- package/lib/session-input-ipc.js +20 -0
- package/lib/session-input.js +355 -19
- package/lib/session-name-holder.js +82 -0
- package/lib/session-resume.js +1 -0
- package/lib/sessions.js +44 -0
- package/lib/turn-initiator.js +6 -2
- package/lib/ws-schema.js +15 -7
- package/lib/yoke/adapters/claude-worker.js +3 -1
- package/lib/yoke/adapters/claude.js +13 -7
- 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,234 @@
|
|
|
1
|
+
// schedule-panel.js - the small panel the clock button opens: arm the next
|
|
2
|
+
// message to go once (in N minutes, or at a clock time) or on a repeat (every N
|
|
3
|
+
// minutes, until a clock time or for N times), and see, send now or cancel the
|
|
4
|
+
// session's armed scheduled inputs.
|
|
5
|
+
//
|
|
6
|
+
// Arming works as the minutes field always did: it sets what the next typed
|
|
7
|
+
// message is scheduled as; pressing Send in the composer sends it. The panel
|
|
8
|
+
// shows when it will go, "tomorrow" included, before anything is armed.
|
|
9
|
+
//
|
|
10
|
+
// The time logic is in schedule-time.js; this file only builds and updates the
|
|
11
|
+
// elements.
|
|
12
|
+
|
|
13
|
+
import { buildSchedule, inputSummary } from './schedule-time.js';
|
|
14
|
+
|
|
15
|
+
var ATTRS_MINUTES = { type: "number", min: "1", max: "1440", placeholder: "min" };
|
|
16
|
+
|
|
17
|
+
function make(tag, className, text) {
|
|
18
|
+
var node = document.createElement(tag);
|
|
19
|
+
if (className) node.className = className;
|
|
20
|
+
if (text !== undefined) node.textContent = text;
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function field(className, attrs) {
|
|
25
|
+
var input = make("input", className);
|
|
26
|
+
Object.keys(attrs).forEach(function (k) { input.setAttribute(k, attrs[k]); });
|
|
27
|
+
return input;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function labeled(text, input, trailing) {
|
|
31
|
+
var row = make("label", "schedule-row");
|
|
32
|
+
if (text) row.appendChild(make("span", "schedule-row-label", text));
|
|
33
|
+
row.appendChild(input);
|
|
34
|
+
if (trailing) row.appendChild(make("span", "schedule-row-unit", trailing));
|
|
35
|
+
return row;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// deps: { anchorEl, getInputs() -> list, canArm() -> bool, onArm(spec),
|
|
39
|
+
// onSendNow(id), onCancel(id), now()? }
|
|
40
|
+
export function createSchedulePanel(deps) {
|
|
41
|
+
var now = deps.now || Date.now;
|
|
42
|
+
var form = { mode: "once", onceBy: "in", inMinutes: "", at: "", everyMinutes: "", endBy: "until", until: "", count: "" };
|
|
43
|
+
var el = null;
|
|
44
|
+
var refs = {};
|
|
45
|
+
var open = false;
|
|
46
|
+
var outsideHandler = null;
|
|
47
|
+
var keyHandler = null;
|
|
48
|
+
|
|
49
|
+
function radio(name, value, onPick) {
|
|
50
|
+
var r = field("schedule-radio", { type: "radio", name: "schedule-" + name, value: value });
|
|
51
|
+
r.addEventListener("change", onPick);
|
|
52
|
+
r.addEventListener("click", onPick);
|
|
53
|
+
return r;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function bindText(input, key) {
|
|
57
|
+
input.addEventListener("input", function () { form[key] = input.value; render(); });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function build() {
|
|
61
|
+
el = make("div", "schedule-panel hidden");
|
|
62
|
+
el.setAttribute("role", "dialog");
|
|
63
|
+
el.setAttribute("aria-label", "Schedule a message");
|
|
64
|
+
|
|
65
|
+
var tabs = make("div", "schedule-tabs");
|
|
66
|
+
refs.tabs = {};
|
|
67
|
+
[["once", "Once"], ["repeat", "Repeat"]].forEach(function (pair) {
|
|
68
|
+
var tab = make("button", "schedule-tab", pair[1]);
|
|
69
|
+
tab.setAttribute("type", "button");
|
|
70
|
+
tab.addEventListener("click", function () { form.mode = pair[0]; render(); });
|
|
71
|
+
refs.tabs[pair[0]] = tab;
|
|
72
|
+
tabs.appendChild(tab);
|
|
73
|
+
});
|
|
74
|
+
el.appendChild(tabs);
|
|
75
|
+
|
|
76
|
+
refs.once = make("div", "schedule-section");
|
|
77
|
+
refs.inRadio = radio("once-by", "in", function () { form.onceBy = "in"; render(); });
|
|
78
|
+
refs.inMinutes = field("schedule-inline-input", ATTRS_MINUTES);
|
|
79
|
+
bindText(refs.inMinutes, "inMinutes");
|
|
80
|
+
var inRow = labeled("", refs.inMinutes, "min from now");
|
|
81
|
+
inRow.insertBefore(refs.inRadio, inRow.firstChild);
|
|
82
|
+
inRow.insertBefore(make("span", "schedule-row-label", "In"), refs.inMinutes);
|
|
83
|
+
refs.once.appendChild(inRow);
|
|
84
|
+
refs.atRadio = radio("once-by", "at", function () { form.onceBy = "at"; render(); });
|
|
85
|
+
refs.at = field("schedule-time-input", { type: "time" });
|
|
86
|
+
bindText(refs.at, "at");
|
|
87
|
+
var atRow = labeled("", refs.at);
|
|
88
|
+
atRow.insertBefore(refs.atRadio, atRow.firstChild);
|
|
89
|
+
atRow.insertBefore(make("span", "schedule-row-label", "At"), refs.at);
|
|
90
|
+
refs.once.appendChild(atRow);
|
|
91
|
+
el.appendChild(refs.once);
|
|
92
|
+
|
|
93
|
+
refs.repeat = make("div", "schedule-section");
|
|
94
|
+
refs.every = field("schedule-inline-input", ATTRS_MINUTES);
|
|
95
|
+
bindText(refs.every, "everyMinutes");
|
|
96
|
+
refs.repeat.appendChild(labeled("Every", refs.every, "min"));
|
|
97
|
+
refs.untilRadio = radio("end-by", "until", function () { form.endBy = "until"; render(); });
|
|
98
|
+
refs.until = field("schedule-time-input", { type: "time" });
|
|
99
|
+
bindText(refs.until, "until");
|
|
100
|
+
var untilRow = labeled("", refs.until);
|
|
101
|
+
untilRow.insertBefore(refs.untilRadio, untilRow.firstChild);
|
|
102
|
+
untilRow.insertBefore(make("span", "schedule-row-label", "Until"), refs.until);
|
|
103
|
+
refs.repeat.appendChild(untilRow);
|
|
104
|
+
refs.countRadio = radio("end-by", "count", function () { form.endBy = "count"; render(); });
|
|
105
|
+
refs.count = field("schedule-inline-input", { type: "number", min: "1", max: "1000", placeholder: "times" });
|
|
106
|
+
bindText(refs.count, "count");
|
|
107
|
+
var countRow = labeled("", refs.count, "times");
|
|
108
|
+
countRow.insertBefore(refs.countRadio, countRow.firstChild);
|
|
109
|
+
countRow.insertBefore(make("span", "schedule-row-label", "For"), refs.count);
|
|
110
|
+
refs.repeat.appendChild(countRow);
|
|
111
|
+
refs.repeat.appendChild(make("div", "schedule-note", "A repeat always has an end."));
|
|
112
|
+
el.appendChild(refs.repeat);
|
|
113
|
+
|
|
114
|
+
refs.preview = make("div", "schedule-preview");
|
|
115
|
+
el.appendChild(refs.preview);
|
|
116
|
+
|
|
117
|
+
var actions = make("div", "schedule-actions");
|
|
118
|
+
refs.arm = make("button", "schedule-arm", "Schedule");
|
|
119
|
+
refs.arm.setAttribute("type", "button");
|
|
120
|
+
refs.arm.addEventListener("click", function () {
|
|
121
|
+
var built = buildSchedule(form, now());
|
|
122
|
+
if (built.error || !deps.canArm()) return;
|
|
123
|
+
deps.onArm(built.spec);
|
|
124
|
+
close();
|
|
125
|
+
});
|
|
126
|
+
actions.appendChild(refs.arm);
|
|
127
|
+
actions.appendChild(make("span", "schedule-hint", "Then type your message and press Send."));
|
|
128
|
+
el.appendChild(actions);
|
|
129
|
+
|
|
130
|
+
refs.listTitle = make("div", "schedule-list-title");
|
|
131
|
+
el.appendChild(refs.listTitle);
|
|
132
|
+
refs.list = make("div", "schedule-list");
|
|
133
|
+
el.appendChild(refs.list);
|
|
134
|
+
|
|
135
|
+
document.body.appendChild(el);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function blank() {
|
|
139
|
+
if (form.mode === "once") return form.onceBy === "at" ? !form.at : !form.inMinutes;
|
|
140
|
+
if (!form.everyMinutes) return true;
|
|
141
|
+
return form.endBy === "count" ? !form.count : !form.until;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function render() {
|
|
145
|
+
if (!el) return;
|
|
146
|
+
refs.tabs.once.classList.toggle("active", form.mode === "once");
|
|
147
|
+
refs.tabs.repeat.classList.toggle("active", form.mode === "repeat");
|
|
148
|
+
refs.tabs.once.setAttribute("aria-pressed", String(form.mode === "once"));
|
|
149
|
+
refs.tabs.repeat.setAttribute("aria-pressed", String(form.mode === "repeat"));
|
|
150
|
+
refs.once.classList.toggle("hidden", form.mode !== "once");
|
|
151
|
+
refs.repeat.classList.toggle("hidden", form.mode !== "repeat");
|
|
152
|
+
refs.inRadio.checked = form.onceBy === "in";
|
|
153
|
+
refs.atRadio.checked = form.onceBy === "at";
|
|
154
|
+
refs.untilRadio.checked = form.endBy === "until";
|
|
155
|
+
refs.countRadio.checked = form.endBy === "count";
|
|
156
|
+
|
|
157
|
+
var canArm = deps.canArm();
|
|
158
|
+
var built = buildSchedule(form, now());
|
|
159
|
+
if (!canArm) {
|
|
160
|
+
refs.preview.textContent = "This session has reached its limit of scheduled messages. Send now or cancel one below to add another.";
|
|
161
|
+
refs.preview.classList.add("error");
|
|
162
|
+
} else if (blank()) {
|
|
163
|
+
refs.preview.textContent = "Choose when to send.";
|
|
164
|
+
refs.preview.classList.remove("error");
|
|
165
|
+
} else {
|
|
166
|
+
refs.preview.textContent = built.error || built.summary;
|
|
167
|
+
refs.preview.classList.toggle("error", !!built.error);
|
|
168
|
+
}
|
|
169
|
+
refs.arm.disabled = !canArm || blank() || !!built.error;
|
|
170
|
+
refs.arm.title = canArm ? "" : "Limit of scheduled messages reached";
|
|
171
|
+
renderList();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function renderList() {
|
|
175
|
+
if (!el) return;
|
|
176
|
+
var inputs = deps.getInputs();
|
|
177
|
+
refs.listTitle.textContent = inputs.length ? "Scheduled for this session" : "";
|
|
178
|
+
refs.list.innerHTML = "";
|
|
179
|
+
inputs.forEach(function (input) {
|
|
180
|
+
var row = make("div", "schedule-list-row");
|
|
181
|
+
row.setAttribute("data-id", input.id);
|
|
182
|
+
row.appendChild(make("span", "schedule-list-text", inputSummary(input, now())));
|
|
183
|
+
var send = make("button", "scheduled-msg-send-now", "Send now");
|
|
184
|
+
send.setAttribute("type", "button");
|
|
185
|
+
send.addEventListener("click", function () { deps.onSendNow(input.id); });
|
|
186
|
+
var cancel = make("button", "scheduled-msg-cancel", "Cancel");
|
|
187
|
+
cancel.setAttribute("type", "button");
|
|
188
|
+
cancel.addEventListener("click", function () { deps.onCancel(input.id); });
|
|
189
|
+
var actions = make("span", "scheduled-msg-actions");
|
|
190
|
+
actions.appendChild(send);
|
|
191
|
+
actions.appendChild(make("span", "scheduled-msg-sep", "·"));
|
|
192
|
+
actions.appendChild(cancel);
|
|
193
|
+
row.appendChild(actions);
|
|
194
|
+
refs.list.appendChild(row);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function position() {
|
|
199
|
+
var rect = deps.anchorEl && deps.anchorEl.getBoundingClientRect ? deps.anchorEl.getBoundingClientRect() : null;
|
|
200
|
+
if (!rect) return;
|
|
201
|
+
el.style.left = Math.max(8, rect.left) + "px";
|
|
202
|
+
el.style.bottom = Math.max(8, window.innerHeight - rect.top + 8) + "px";
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function openPanel() {
|
|
206
|
+
if (!el) build();
|
|
207
|
+
open = true;
|
|
208
|
+
el.classList.remove("hidden");
|
|
209
|
+
position();
|
|
210
|
+
render();
|
|
211
|
+
outsideHandler = function (ev) {
|
|
212
|
+
if (el.contains(ev.target) || (deps.anchorEl && deps.anchorEl.contains(ev.target))) return;
|
|
213
|
+
close();
|
|
214
|
+
};
|
|
215
|
+
keyHandler = function (ev) { if (ev.key === "Escape") close(); };
|
|
216
|
+
document.addEventListener("mousedown", outsideHandler);
|
|
217
|
+
document.addEventListener("keydown", keyHandler);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function close() {
|
|
221
|
+
open = false;
|
|
222
|
+
if (el) el.classList.add("hidden");
|
|
223
|
+
if (outsideHandler) { document.removeEventListener("mousedown", outsideHandler); outsideHandler = null; }
|
|
224
|
+
if (keyHandler) { document.removeEventListener("keydown", keyHandler); keyHandler = null; }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
toggle: function () { if (open) close(); else openPanel(); },
|
|
229
|
+
close: close,
|
|
230
|
+
isOpen: function () { return open; },
|
|
231
|
+
// The session's list or the cap changed: redraw if the panel is showing.
|
|
232
|
+
refresh: function () { if (open) render(); },
|
|
233
|
+
};
|
|
234
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// schedule-time.js - the time arithmetic and wording of the schedule panel.
|
|
2
|
+
// DOM-free, so it can be tested under plain Node.
|
|
3
|
+
//
|
|
4
|
+
// resolveClockTime mirrors the CLI's (lib/cli/schedule-input-subcommands.js),
|
|
5
|
+
// which the browser cannot load; test/scheduled-input-client.test.js feeds both the
|
|
6
|
+
// same cases. Everything is the browser's local time zone.
|
|
7
|
+
|
|
8
|
+
var MIN_EVERY_MIN = 1;
|
|
9
|
+
var MAX_EVERY_MIN = 24 * 60;
|
|
10
|
+
var MAX_ONCE_MIN = 24 * 60;
|
|
11
|
+
var MAX_COUNT = 1000;
|
|
12
|
+
|
|
13
|
+
function pad2(n) {
|
|
14
|
+
return (n < 10 ? "0" : "") + n;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// A whole number of minutes from a field's text, or null.
|
|
18
|
+
export function parseMinutes(raw, max) {
|
|
19
|
+
var text = typeof raw === "string" ? raw.trim() : String(raw == null ? "" : raw);
|
|
20
|
+
if (!/^\d+$/.test(text)) return null;
|
|
21
|
+
var n = parseInt(text, 10);
|
|
22
|
+
return n >= 1 && n <= max ? n : null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// The next occurrence, strictly after `now`, of a local HH:MM. A time that has
|
|
26
|
+
// passed today means tomorrow. Returns { ms, tomorrow } or { error }.
|
|
27
|
+
export function resolveClockTime(raw, now) {
|
|
28
|
+
var m = /^(\d{1,2}):(\d{2})$/.exec(typeof raw === "string" ? raw.trim() : "");
|
|
29
|
+
if (!m) return { error: "Enter a time as HH:MM." };
|
|
30
|
+
var h = parseInt(m[1], 10);
|
|
31
|
+
var mi = parseInt(m[2], 10);
|
|
32
|
+
if (h > 23 || mi > 59) return { error: "Enter a time from 00:00 to 23:59." };
|
|
33
|
+
var d = new Date(now);
|
|
34
|
+
d.setHours(h, mi, 0, 0);
|
|
35
|
+
var tomorrow = false;
|
|
36
|
+
if (d.getTime() <= now) {
|
|
37
|
+
d.setDate(d.getDate() + 1);
|
|
38
|
+
tomorrow = true;
|
|
39
|
+
}
|
|
40
|
+
return { ms: d.getTime(), tomorrow: tomorrow };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function clockText(ms) {
|
|
44
|
+
var d = new Date(ms);
|
|
45
|
+
return pad2(d.getHours()) + ":" + pad2(d.getMinutes());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
49
|
+
|
|
50
|
+
// "today at 20:01", "tomorrow at 20:01", or "Mar 3 at 20:01" for a later day.
|
|
51
|
+
export function dayTimeText(ms, now) {
|
|
52
|
+
var d = new Date(ms);
|
|
53
|
+
var today = new Date(now);
|
|
54
|
+
today.setHours(0, 0, 0, 0);
|
|
55
|
+
var dayStart = new Date(ms);
|
|
56
|
+
dayStart.setHours(0, 0, 0, 0);
|
|
57
|
+
var days = Math.round((dayStart.getTime() - today.getTime()) / 86400000);
|
|
58
|
+
var when;
|
|
59
|
+
if (days === 0) when = "today";
|
|
60
|
+
else if (days === 1) when = "tomorrow";
|
|
61
|
+
else when = MONTHS[d.getMonth()] + " " + d.getDate();
|
|
62
|
+
return when + " at " + clockText(ms);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function durationText(ms) {
|
|
66
|
+
var mins = Math.round(ms / 60000);
|
|
67
|
+
if (mins < 60) return mins + " min";
|
|
68
|
+
var hrs = Math.floor(mins / 60);
|
|
69
|
+
var rem = mins % 60;
|
|
70
|
+
return rem ? hrs + " h " + rem + " min" : hrs + " h";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// form: { mode: "once" | "repeat",
|
|
74
|
+
// onceBy: "in" | "at", inMinutes, at,
|
|
75
|
+
// everyMinutes, endBy: "until" | "count", until, count }
|
|
76
|
+
// Returns { spec, summary } or { error }. spec is what the composer arms (see
|
|
77
|
+
// scheduleMessageFor); summary says, before anything is armed, when it will go,
|
|
78
|
+
// including "tomorrow".
|
|
79
|
+
export function buildSchedule(form, now) {
|
|
80
|
+
if (form.mode === "once") {
|
|
81
|
+
if (form.onceBy === "at") {
|
|
82
|
+
var at = resolveClockTime(form.at, now);
|
|
83
|
+
if (at.error) return { error: at.error };
|
|
84
|
+
return { spec: { kind: "once", atMs: at.ms }, summary: "Sends " + dayTimeText(at.ms, now) + "." };
|
|
85
|
+
}
|
|
86
|
+
var mins = parseMinutes(form.inMinutes, MAX_ONCE_MIN);
|
|
87
|
+
if (mins === null) return { error: "Enter a number of minutes from 1 to " + MAX_ONCE_MIN + "." };
|
|
88
|
+
return { spec: { kind: "once", delayMs: mins * 60000 }, summary: "Sends in " + durationText(mins * 60000) + ", at " + clockText(now + mins * 60000) + "." };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
var every = parseMinutes(form.everyMinutes, MAX_EVERY_MIN);
|
|
92
|
+
if (every === null) return { error: "Repeat every a number of minutes from " + MIN_EVERY_MIN + " to " + MAX_EVERY_MIN + " (24 hours)." };
|
|
93
|
+
var everyMs = every * 60000;
|
|
94
|
+
var first = "first " + dayTimeText(now + everyMs, now);
|
|
95
|
+
if (form.endBy === "count") {
|
|
96
|
+
var count = parseMinutes(form.count, MAX_COUNT);
|
|
97
|
+
if (count === null) return { error: "Enter how many times, from 1 to " + MAX_COUNT + "." };
|
|
98
|
+
return {
|
|
99
|
+
spec: { kind: "recurring", everyMs: everyMs, count: count },
|
|
100
|
+
summary: "Sends every " + durationText(everyMs) + ", " + count + (count === 1 ? " time" : " times") + " (" + first + ").",
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
var until = resolveClockTime(form.until, now);
|
|
104
|
+
if (until.error) return { error: until.error };
|
|
105
|
+
if (until.ms < now + everyMs) {
|
|
106
|
+
return { error: "That end time is before the first send (" + dayTimeText(now + everyMs, now) + "). Pick a later end or a shorter interval." };
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
spec: { kind: "recurring", everyMs: everyMs, untilMs: until.ms },
|
|
110
|
+
summary: "Sends every " + durationText(everyMs) + " until " + dayTimeText(until.ms, now) + " (" + first + ").",
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// The websocket message the composer sends for an armed spec and the typed text.
|
|
115
|
+
export function scheduleMessageFor(spec, text, now) {
|
|
116
|
+
if (spec.kind === "once") {
|
|
117
|
+
return { type: "schedule_message", text: text, resetsAt: spec.atMs != null ? spec.atMs : now + spec.delayMs };
|
|
118
|
+
}
|
|
119
|
+
var msg = { type: "schedule_message", text: text, kind: "recurring", every: spec.everyMs };
|
|
120
|
+
if (spec.untilMs != null) msg.until = spec.untilMs;
|
|
121
|
+
else msg.count = spec.count;
|
|
122
|
+
return msg;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function shortDuration(ms) {
|
|
126
|
+
var mins = Math.round(ms / 60000);
|
|
127
|
+
if (mins < 60) return mins + "m";
|
|
128
|
+
var hrs = Math.floor(mins / 60);
|
|
129
|
+
var rem = mins % 60;
|
|
130
|
+
return rem > 0 ? hrs + "h " + rem + "m" : hrs + "h";
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// The short text beside the clock button while a schedule is armed.
|
|
134
|
+
export function specLabel(spec) {
|
|
135
|
+
if (spec.kind === "once") return spec.atMs != null ? "at " + clockText(spec.atMs) : shortDuration(spec.delayMs);
|
|
136
|
+
return "every " + shortDuration(spec.everyMs);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// The longer wording of the same, for the button's tooltip.
|
|
140
|
+
export function specTitle(spec, now) {
|
|
141
|
+
if (spec.kind === "once") {
|
|
142
|
+
return spec.atMs != null ? dayTimeText(spec.atMs, now) : "in " + durationText(spec.delayMs);
|
|
143
|
+
}
|
|
144
|
+
var end = spec.untilMs != null ? "until " + dayTimeText(spec.untilMs, now) : spec.count + (spec.count === 1 ? " time" : " times");
|
|
145
|
+
return "every " + durationText(spec.everyMs) + ", " + end;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// What the chat and the lists call an input: plain words, and the automatic
|
|
149
|
+
// resume under its own name.
|
|
150
|
+
export function inputLabel(input) {
|
|
151
|
+
if (input.createdBy === "rate-limit") return "Automatic resume after rate limit";
|
|
152
|
+
return input.kind === "recurring" ? "Scheduled repeat" : "Scheduled message";
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// The line under a scheduled-message bubble, refreshed every second:
|
|
156
|
+
// "Sends at 08:30 PM (4m 12s)", and for a repeat the next time and its end.
|
|
157
|
+
export function countdownText(input, now) {
|
|
158
|
+
var lead = "";
|
|
159
|
+
if (input.createdBy === "rate-limit") lead = "Automatic resume after rate limit · ";
|
|
160
|
+
else if (input.kind === "recurring") lead = "Scheduled repeat · ";
|
|
161
|
+
var remaining = input.nextAt - now;
|
|
162
|
+
if (remaining <= 0) return lead + "Sending...";
|
|
163
|
+
var hrs = Math.floor(remaining / 3600000);
|
|
164
|
+
var mins = Math.floor((remaining % 3600000) / 60000);
|
|
165
|
+
var secs = Math.floor((remaining % 60000) / 1000);
|
|
166
|
+
var timeStr = "";
|
|
167
|
+
if (hrs > 0) timeStr += hrs + "h ";
|
|
168
|
+
if (mins > 0 || hrs > 0) timeStr += mins + "m ";
|
|
169
|
+
timeStr += secs + "s";
|
|
170
|
+
var abs = new Date(input.nextAt).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
171
|
+
var text = lead + (input.kind === "recurring" ? "Next at " : "Sends at ") + abs + " (" + timeStr + ")";
|
|
172
|
+
if (input.kind === "recurring") {
|
|
173
|
+
text += " · every " + durationText(input.every);
|
|
174
|
+
if (input.until != null) text += " until " + dayTimeText(input.until, now).replace(/^today at /, "");
|
|
175
|
+
else if (input.count != null) text += " · " + (input.count - input.firedCount) + " of " + input.count + " left";
|
|
176
|
+
}
|
|
177
|
+
return text;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// "Scheduled repeat · every 30 min · next 19:30 · until 21:00", for the panel
|
|
181
|
+
// list and the bubble.
|
|
182
|
+
export function inputSummary(input, now) {
|
|
183
|
+
var parts = [inputLabel(input)];
|
|
184
|
+
if (input.kind === "recurring") {
|
|
185
|
+
parts.push("every " + durationText(input.every));
|
|
186
|
+
parts.push("next " + dayTimeText(input.nextAt, now).replace(/^today at /, ""));
|
|
187
|
+
if (input.until != null) parts.push("until " + dayTimeText(input.until, now).replace(/^today at /, ""));
|
|
188
|
+
else if (input.count != null) parts.push((input.count - input.firedCount) + " of " + input.count + " left");
|
|
189
|
+
} else {
|
|
190
|
+
parts.push(dayTimeText(input.nextAt, now).replace(/^today at /, ""));
|
|
191
|
+
}
|
|
192
|
+
return parts.join(" · ");
|
|
193
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// scheduled-input-actions.js - the messages the schedule panel and the
|
|
2
|
+
// scheduled-message bubbles send to the server about a scheduled input. One
|
|
3
|
+
// place, so the two surfaces cannot drift apart.
|
|
4
|
+
|
|
5
|
+
import { sendWs } from './ws-ref.js';
|
|
6
|
+
|
|
7
|
+
export function sendScheduledNow(id) {
|
|
8
|
+
return sendWs({ type: "send_scheduled_now", id: id });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function cancelScheduledInput(id) {
|
|
12
|
+
return sendWs({ type: "cancel_scheduled_message", id: id });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Asks for the armed inputs of the session on screen; the answer arrives as
|
|
16
|
+
// scheduled_input_list.
|
|
17
|
+
export function requestScheduledInputList() {
|
|
18
|
+
return sendWs({ type: "scheduled_input_list_request" });
|
|
19
|
+
}
|
package/lib/runtime-env.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
var crypto = require("crypto");
|
|
23
23
|
var protectedKeys = require("./runtime-env-keys");
|
|
24
|
+
var senderRef = require("./sender-ref");
|
|
24
25
|
|
|
25
26
|
var KEY_RE = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
26
27
|
var SHELL_META_RE = /[`$\\;|&><(){}\n]/;
|
|
@@ -185,6 +186,9 @@ function composeRuntimeEnv(base, overlay, opts) {
|
|
|
185
186
|
}
|
|
186
187
|
env[name] = overlay[name];
|
|
187
188
|
}
|
|
189
|
+
// The session reference is the console's alone to set, per session; a value
|
|
190
|
+
// inherited from the daemon's own environment would name some other session.
|
|
191
|
+
senderRef.strip(env);
|
|
188
192
|
return env;
|
|
189
193
|
}
|
|
190
194
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// ipc.js - the daemon side of `clagentic-console schedule-input`: which fields
|
|
2
|
+
// of an IPC message reach the scheduled-input service, and what each verb
|
|
3
|
+
// answers. The CLI is the same primitive the clock button uses; both go through
|
|
4
|
+
// the one service, so a record made by either shows in the other's list.
|
|
5
|
+
//
|
|
6
|
+
// schedule_input_create { projectSlug, sessionId, prompt, at | every + until | count,
|
|
7
|
+
// senderProject?, senderSessionId? }
|
|
8
|
+
// schedule_input_list { projectSlug?, sessionId?, state? }
|
|
9
|
+
// schedule_input_delete { id, projectSlug? }
|
|
10
|
+
//
|
|
11
|
+
// Times arrive as absolute milliseconds: the CLI resolves "in 10m" and a local
|
|
12
|
+
// "20:01" in the caller's own time zone.
|
|
13
|
+
|
|
14
|
+
var senderRef = require("../sender-ref");
|
|
15
|
+
var { isMs } = require("./records");
|
|
16
|
+
|
|
17
|
+
function refused(reason) {
|
|
18
|
+
return { ok: false, result: "refused", reason: reason };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// What the record says made it: the calling console session ("<agent>@<project>"),
|
|
22
|
+
// as send-input records its sender, else the plain CLI.
|
|
23
|
+
function createdByFor(getProject, msg) {
|
|
24
|
+
var extracted = senderRef.resolve(getProject, { project: msg.senderProject, sessionId: msg.senderSessionId });
|
|
25
|
+
return extracted ? extracted.name : "cli";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function create(deps, msg) {
|
|
29
|
+
if (typeof msg.projectSlug !== "string" || !msg.projectSlug) return Promise.resolve(refused("a project is required"));
|
|
30
|
+
if (typeof msg.prompt !== "string" || !msg.prompt) return Promise.resolve(refused("prompt must be a non-empty string"));
|
|
31
|
+
var recurring = msg.every !== undefined;
|
|
32
|
+
if (recurring ? !isMs(msg.every) : !isMs(msg.at)) {
|
|
33
|
+
return Promise.resolve(refused(recurring ? "every must be a duration" : "a once input needs the time to send at"));
|
|
34
|
+
}
|
|
35
|
+
return deps.service.resolveTarget(msg.projectSlug, msg.sessionId).then(function (resolved) {
|
|
36
|
+
if (!resolved.ok) return resolved;
|
|
37
|
+
var out = deps.service.create(msg.projectSlug, {
|
|
38
|
+
target: resolved.target,
|
|
39
|
+
session: resolved.session || undefined,
|
|
40
|
+
kind: recurring ? "recurring" : "once",
|
|
41
|
+
text: msg.prompt,
|
|
42
|
+
note: recurring ? "scheduled repeat" : "scheduled message",
|
|
43
|
+
createdBy: createdByFor(deps.getProject, msg),
|
|
44
|
+
at: recurring ? undefined : msg.at,
|
|
45
|
+
every: recurring ? msg.every : undefined,
|
|
46
|
+
until: recurring && msg.until !== undefined ? msg.until : undefined,
|
|
47
|
+
count: recurring && msg.count !== undefined ? msg.count : undefined,
|
|
48
|
+
});
|
|
49
|
+
if (out.ok) out.project = msg.projectSlug;
|
|
50
|
+
return out;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function list(deps, msg) {
|
|
55
|
+
var slugs = typeof msg.projectSlug === "string" && msg.projectSlug ? [msg.projectSlug] : deps.service.projectSlugs();
|
|
56
|
+
var inputs = [];
|
|
57
|
+
// Projects whose list cannot be saved (nothing of theirs is delivered).
|
|
58
|
+
var storeErrors = [];
|
|
59
|
+
for (var i = 0; i < slugs.length; i++) {
|
|
60
|
+
var part = deps.service.list(slugs[i], { sessionId: msg.sessionId, state: msg.state });
|
|
61
|
+
if (!part.ok) return part;
|
|
62
|
+
part.inputs.forEach(function (r) { inputs.push(Object.assign({ project: slugs[i] }, r)); });
|
|
63
|
+
if (part.store) storeErrors.push(Object.assign({ project: slugs[i] }, part.store));
|
|
64
|
+
}
|
|
65
|
+
inputs.sort(function (a, b) { return (a.nextAt === null ? Infinity : a.nextAt) - (b.nextAt === null ? Infinity : b.nextAt); });
|
|
66
|
+
var listed = { ok: true, result: "listed", count: inputs.length, inputs: inputs };
|
|
67
|
+
if (storeErrors.length) listed.storeErrors = storeErrors;
|
|
68
|
+
return listed;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function remove(deps, msg) {
|
|
72
|
+
if (typeof msg.id !== "string" || !msg.id) return refused("an id is required");
|
|
73
|
+
var slugs = typeof msg.projectSlug === "string" && msg.projectSlug ? [msg.projectSlug] : deps.service.projectSlugs();
|
|
74
|
+
var last = { ok: false, result: "not-found", reason: "no scheduled input " + JSON.stringify(msg.id.slice(0, 64)) };
|
|
75
|
+
for (var i = 0; i < slugs.length; i++) {
|
|
76
|
+
var out = deps.service.remove(slugs[i], msg.id);
|
|
77
|
+
if (out.ok) { out.project = slugs[i]; return out; }
|
|
78
|
+
if (out.result !== "not-found") last = out;
|
|
79
|
+
}
|
|
80
|
+
return last;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// deps: { service, getProject(slug) }
|
|
84
|
+
// Returns the result, or a Promise of it; undefined when msg.cmd is not ours.
|
|
85
|
+
function handleScheduledInputCommand(deps, msg) {
|
|
86
|
+
if (msg.cmd === "schedule_input_create") return create(deps, msg);
|
|
87
|
+
if (msg.cmd === "schedule_input_list") return list(deps, msg);
|
|
88
|
+
if (msg.cmd === "schedule_input_delete") return remove(deps, msg);
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = { handleScheduledInputCommand: handleScheduledInputCommand };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// rate-limit-resume.js - the one scheduled input the console arms by itself: an
|
|
2
|
+
// automatic "continue" for a session that hit a rate limit.
|
|
3
|
+
//
|
|
4
|
+
// It is an ordinary once record with its own note. The one thing that is its
|
|
5
|
+
// own is its timing, which lives here and nowhere else, so a person's "in 10
|
|
6
|
+
// min" fires at 10 minutes.
|
|
7
|
+
|
|
8
|
+
// What the chat says an automatic "continue" after a rate limit is.
|
|
9
|
+
var RATE_LIMIT_RESUME_NOTE = "automatic resume after rate limit";
|
|
10
|
+
|
|
11
|
+
var RESUME_TEXT = "continue";
|
|
12
|
+
// After the limit resets, the vendor needs a moment before it accepts a turn.
|
|
13
|
+
var RESET_BUFFER_MS = 60 * 1000;
|
|
14
|
+
// With extra usage available (or a reset already past) there is nothing to wait
|
|
15
|
+
// for except the rejected query finishing.
|
|
16
|
+
var IMMEDIATE_DELAY_MS = 5 * 1000;
|
|
17
|
+
|
|
18
|
+
// When to send the resume for a limit that resets at `resetsAt` (ms).
|
|
19
|
+
function resumeAt(resetsAt, now) {
|
|
20
|
+
if (!resetsAt || resetsAt <= now) return now + IMMEDIATE_DELAY_MS;
|
|
21
|
+
return resetsAt + RESET_BUFFER_MS;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// The two calls the SDK bridge makes for a project: arm the resume for a
|
|
25
|
+
// session, and ask whether one is already armed (its guard). A project with no
|
|
26
|
+
// scheduled-input service arms nothing.
|
|
27
|
+
// deps: { service, slug, now? }
|
|
28
|
+
function createRateLimitResume(deps) {
|
|
29
|
+
var now = deps.now || Date.now;
|
|
30
|
+
return {
|
|
31
|
+
schedule: function (session, resetsAt) {
|
|
32
|
+
if (!deps.service || !session || session.destroying) return;
|
|
33
|
+
var armed = deps.service.armResume(deps.slug, session, {
|
|
34
|
+
at: resumeAt(resetsAt, now()),
|
|
35
|
+
text: RESUME_TEXT,
|
|
36
|
+
note: RATE_LIMIT_RESUME_NOTE,
|
|
37
|
+
});
|
|
38
|
+
if (armed && !armed.ok) console.error("[rate-limit-resume] could not arm the resume for session " + session.localId + ": " + armed.reason);
|
|
39
|
+
},
|
|
40
|
+
has: function (session) {
|
|
41
|
+
return !!deps.service && deps.service.hasArmedResume(deps.slug, session);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
createRateLimitResume: createRateLimitResume,
|
|
48
|
+
RATE_LIMIT_RESUME_NOTE: RATE_LIMIT_RESUME_NOTE,
|
|
49
|
+
RESUME_TEXT: RESUME_TEXT,
|
|
50
|
+
RESET_BUFFER_MS: RESET_BUFFER_MS,
|
|
51
|
+
IMMEDIATE_DELAY_MS: IMMEDIATE_DELAY_MS,
|
|
52
|
+
resumeAt: resumeAt,
|
|
53
|
+
};
|