@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,132 @@
|
|
|
1
|
+
// store.js - the scheduled inputs of one project, kept in a file in the console
|
|
2
|
+
// config directory so they survive a daemon restart.
|
|
3
|
+
//
|
|
4
|
+
// The file is written whole through a temporary file and a rename, so a crash
|
|
5
|
+
// leaves either the old list or the new one. A file that cannot be read is set
|
|
6
|
+
// aside under a new name, never silently overwritten, and the project starts
|
|
7
|
+
// with an empty list. If it cannot be set aside either, the store is read-only:
|
|
8
|
+
// every save is refused and the file is left exactly as it is.
|
|
9
|
+
|
|
10
|
+
var fs = require("fs");
|
|
11
|
+
var path = require("path");
|
|
12
|
+
|
|
13
|
+
var { STATE, isValidRecord } = require("./records");
|
|
14
|
+
|
|
15
|
+
var FORMAT = 1;
|
|
16
|
+
// Finished records stay listed for a while so a person or a script can see
|
|
17
|
+
// what happened to a schedule; only the newest are kept.
|
|
18
|
+
var MAX_FINISHED = 20;
|
|
19
|
+
|
|
20
|
+
function messageOf(err) {
|
|
21
|
+
return err && err.message ? err.message : String(err);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// opts: { file }
|
|
25
|
+
function createStore(opts) {
|
|
26
|
+
var file = opts.file;
|
|
27
|
+
var records = [];
|
|
28
|
+
// Set when the file is unreadable and could not be moved out of the way: a
|
|
29
|
+
// save would then replace the only copy of the person's schedules, so none is
|
|
30
|
+
// made. The store stays empty and read-only until the next load.
|
|
31
|
+
var readOnlyReason = null;
|
|
32
|
+
|
|
33
|
+
function setAside(reason) {
|
|
34
|
+
var aside = file + ".unreadable-" + Date.now();
|
|
35
|
+
try {
|
|
36
|
+
fs.renameSync(file, aside);
|
|
37
|
+
console.error("[scheduled-input] " + file + " is unreadable (" + reason + "); set aside as " + aside + ", starting empty");
|
|
38
|
+
} catch (e) {
|
|
39
|
+
readOnlyReason = file + " is unreadable (" + reason + ") and could not be set aside (" + messageOf(e) + "); saving is refused so it is not overwritten";
|
|
40
|
+
console.error("[scheduled-input] " + readOnlyReason);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function load() {
|
|
45
|
+
records = [];
|
|
46
|
+
readOnlyReason = null;
|
|
47
|
+
var raw;
|
|
48
|
+
try { raw = fs.readFileSync(file, "utf8"); }
|
|
49
|
+
catch (e) {
|
|
50
|
+
if (e && e.code === "ENOENT") return records;
|
|
51
|
+
setAside(messageOf(e));
|
|
52
|
+
return records;
|
|
53
|
+
}
|
|
54
|
+
var parsed;
|
|
55
|
+
try { parsed = JSON.parse(raw); }
|
|
56
|
+
catch (e) {
|
|
57
|
+
setAside("not valid JSON");
|
|
58
|
+
return records;
|
|
59
|
+
}
|
|
60
|
+
if (!parsed || !Array.isArray(parsed.records)) {
|
|
61
|
+
setAside("no records list");
|
|
62
|
+
return records;
|
|
63
|
+
}
|
|
64
|
+
if (parsed.format !== FORMAT) {
|
|
65
|
+
setAside("format " + JSON.stringify(parsed.format) + " is not the supported format " + FORMAT);
|
|
66
|
+
return records;
|
|
67
|
+
}
|
|
68
|
+
if (!parsed.records.every(isValidRecord)) {
|
|
69
|
+
setAside("a record is missing what it needs to fire");
|
|
70
|
+
return records;
|
|
71
|
+
}
|
|
72
|
+
records = parsed.records;
|
|
73
|
+
return records;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function prune() {
|
|
77
|
+
var finished = records.filter(function (r) { return r.state !== STATE.ARMED; });
|
|
78
|
+
if (finished.length <= MAX_FINISHED) return;
|
|
79
|
+
finished.sort(function (a, b) { return (b.endedAt || 0) - (a.endedAt || 0); });
|
|
80
|
+
var drop = finished.slice(MAX_FINISHED);
|
|
81
|
+
records = records.filter(function (r) { return drop.indexOf(r) === -1; });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Returns true when the list reached the disk.
|
|
85
|
+
function save() {
|
|
86
|
+
if (readOnlyReason !== null) {
|
|
87
|
+
console.error("[scheduled-input] save refused: " + readOnlyReason);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
prune();
|
|
91
|
+
try {
|
|
92
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
93
|
+
var tmp = file + ".tmp";
|
|
94
|
+
fs.writeFileSync(tmp, JSON.stringify({ format: FORMAT, records: records }, null, 2) + "\n", { mode: 0o600 });
|
|
95
|
+
fs.renameSync(tmp, file);
|
|
96
|
+
return true;
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error("[scheduled-input] could not save " + file + ":", messageOf(e));
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function all() {
|
|
104
|
+
return records;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function get(id) {
|
|
108
|
+
for (var i = 0; i < records.length; i++) {
|
|
109
|
+
if (records[i].id === id) return records[i];
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function add(record) {
|
|
115
|
+
records.push(record);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function remove(id) {
|
|
119
|
+
var before = records.length;
|
|
120
|
+
records = records.filter(function (r) { return r.id !== id; });
|
|
121
|
+
return records.length !== before;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// { readOnly, error }: error is the reason saving is refused, or null.
|
|
125
|
+
function health() {
|
|
126
|
+
return { readOnly: readOnlyReason !== null, error: readOnlyReason };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return { load: load, save: save, all: all, get: get, add: add, remove: remove, health: health };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
module.exports = { createStore: createStore, MAX_FINISHED: MAX_FINISHED };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// ws.js - the browser's side of scheduled input, both directions.
|
|
2
|
+
//
|
|
3
|
+
// From the browser (createWsHandlers): the messages the clock button and the
|
|
4
|
+
// scheduled-message bubble send.
|
|
5
|
+
//
|
|
6
|
+
// schedule_message arm an input on the session on screen
|
|
7
|
+
// { text, resetsAt } once (the original shape)
|
|
8
|
+
// { text, kind: "recurring", every, until | count }
|
|
9
|
+
// cancel_scheduled_message { id? } delete one of its inputs
|
|
10
|
+
// send_scheduled_now { id? } deliver one now
|
|
11
|
+
// scheduled_input_list_request answer the session's armed inputs
|
|
12
|
+
//
|
|
13
|
+
// An id names the record. A browser still running the client from before
|
|
14
|
+
// records had ids sends none, and gets the input that fires first. A browser
|
|
15
|
+
// only ever acts on the session it has on screen; the CLI is the path that can
|
|
16
|
+
// name any session.
|
|
17
|
+
//
|
|
18
|
+
// To the browser (createPublisher): what happened to a session's scheduled
|
|
19
|
+
// inputs, for the session's viewers only. Two kinds of message:
|
|
20
|
+
//
|
|
21
|
+
// scheduled_input_list the session's armed inputs, in full, after every
|
|
22
|
+
// change; the client takes its state from this alone
|
|
23
|
+
// scheduled_message_queued / _sent / _cancelled
|
|
24
|
+
// the names the scheduled message always used, kept
|
|
25
|
+
// for a browser still running an older client until
|
|
26
|
+
// it reloads; recorded in the session's history as
|
|
27
|
+
// before. A current client takes no state from them.
|
|
28
|
+
|
|
29
|
+
var records = require("./records");
|
|
30
|
+
|
|
31
|
+
var KIND = records.KIND;
|
|
32
|
+
|
|
33
|
+
// What the chat and the bubble call each kind.
|
|
34
|
+
var KIND_NOTE = Object.freeze({
|
|
35
|
+
[KIND.ONCE]: "scheduled message",
|
|
36
|
+
[KIND.RECURRING]: "scheduled repeat",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// A Set, not an object: the type is the browser's string, and "toString" or
|
|
40
|
+
// "constructor" must not find a property on Object.prototype.
|
|
41
|
+
var HANDLED = new Set([
|
|
42
|
+
"schedule_message",
|
|
43
|
+
"cancel_scheduled_message",
|
|
44
|
+
"send_scheduled_now",
|
|
45
|
+
"scheduled_input_list_request",
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
// The session's armed inputs, in full, with the cap the server applies, so the
|
|
49
|
+
// client holds no copy of the limit.
|
|
50
|
+
function listMessage(session, inputs) {
|
|
51
|
+
return {
|
|
52
|
+
type: "scheduled_input_list",
|
|
53
|
+
localId: session.localId,
|
|
54
|
+
limit: records.LIMITS.MAX_ARMED_PER_SESSION,
|
|
55
|
+
inputs: inputs,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// deps: { slug, service, getSessionForWs(ws), sendTo(ws, obj) }
|
|
60
|
+
function createWsHandlers(deps) {
|
|
61
|
+
var slug = deps.slug;
|
|
62
|
+
var service = deps.service;
|
|
63
|
+
|
|
64
|
+
function createdBy(ws) {
|
|
65
|
+
var user = ws && ws._clagenticUser;
|
|
66
|
+
if (!user) return "browser";
|
|
67
|
+
return "browser:" + String(user.username || user.displayName || user.id || "user").slice(0, 60);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function refuse(ws, reason) {
|
|
71
|
+
deps.sendTo(ws, { type: "error", text: "Clagentic: Console could not schedule that: " + reason });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function kindOf(msg) {
|
|
75
|
+
if (msg.kind === undefined || msg.kind === KIND.ONCE) return KIND.ONCE;
|
|
76
|
+
if (msg.kind === KIND.RECURRING) return KIND.RECURRING;
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function schedule(ws, session, msg) {
|
|
81
|
+
var kind = kindOf(msg);
|
|
82
|
+
if (!kind) return refuse(ws, "unknown kind");
|
|
83
|
+
var result = service.create(slug, {
|
|
84
|
+
target: records.targetOf(session),
|
|
85
|
+
session: session,
|
|
86
|
+
kind: kind,
|
|
87
|
+
text: msg.text,
|
|
88
|
+
note: KIND_NOTE[kind],
|
|
89
|
+
createdBy: createdBy(ws),
|
|
90
|
+
at: kind === KIND.ONCE ? msg.resetsAt : undefined,
|
|
91
|
+
every: kind === KIND.RECURRING ? msg.every : undefined,
|
|
92
|
+
until: kind === KIND.RECURRING ? msg.until : undefined,
|
|
93
|
+
count: kind === KIND.RECURRING ? msg.count : undefined,
|
|
94
|
+
});
|
|
95
|
+
if (!result.ok) refuse(ws, result.reason);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function idFor(session, msg) {
|
|
99
|
+
if (typeof msg.id === "string" && msg.id) return msg.id;
|
|
100
|
+
var armed = service.armedForSession(slug, session).sort(function (a, b) { return a.nextAt - b.nextAt; });
|
|
101
|
+
return armed.length ? armed[0].id : null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Answers true when the message was one of ours.
|
|
105
|
+
function handle(ws, msg) {
|
|
106
|
+
if (!msg || !HANDLED.has(msg.type)) return false;
|
|
107
|
+
var session = deps.getSessionForWs(ws);
|
|
108
|
+
if (!session) return true;
|
|
109
|
+
if (!service) {
|
|
110
|
+
refuse(ws, "scheduling is not available here");
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
if (msg.type === "scheduled_input_list_request") {
|
|
114
|
+
deps.sendTo(ws, listMessage(session, service.armedForSession(slug, session)));
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
if (msg.type === "schedule_message") {
|
|
118
|
+
schedule(ws, session, msg);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
var id = idFor(session, msg);
|
|
122
|
+
if (!id) return true;
|
|
123
|
+
if (msg.type === "cancel_scheduled_message") {
|
|
124
|
+
var removed = service.remove(slug, id, session);
|
|
125
|
+
// Refused while the text is being sent: the person is told, and the bubble
|
|
126
|
+
// stays because nothing changed.
|
|
127
|
+
if (!removed.ok && removed.result === "busy") {
|
|
128
|
+
deps.sendTo(ws, { type: "error", text: "Clagentic: Console could not cancel that: " + removed.reason });
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
// send_scheduled_now: a person forced it, so it joins a running turn.
|
|
133
|
+
service.sendNow(slug, id, session).then(function (res) {
|
|
134
|
+
if (!res.ok) deps.sendTo(ws, { type: "error", text: "Clagentic: Console could not send that now: " + res.reason });
|
|
135
|
+
});
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return { handle: handle };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// deps: { getProject(slug), listFor(slug, session) -> the session's inputs }
|
|
143
|
+
function createPublisher(deps) {
|
|
144
|
+
function sessionFor(event, project) {
|
|
145
|
+
return event.session || records.liveSessionOf(project.sm, event.record);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function fields(record) {
|
|
149
|
+
return {
|
|
150
|
+
id: record.id,
|
|
151
|
+
kind: record.kind,
|
|
152
|
+
every: record.every === undefined ? null : record.every,
|
|
153
|
+
until: record.until === undefined ? null : record.until,
|
|
154
|
+
count: record.count === undefined ? null : record.count,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function legacy(event, session) {
|
|
159
|
+
var record = event.record;
|
|
160
|
+
var base = Object.assign({ localId: session.localId }, fields(record));
|
|
161
|
+
if (event.type === "queued") {
|
|
162
|
+
return Object.assign(base, {
|
|
163
|
+
type: "scheduled_message_queued",
|
|
164
|
+
text: record.text,
|
|
165
|
+
resetsAt: record.nextAt,
|
|
166
|
+
scheduledAt: record.createdAt,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (event.type === "sent") {
|
|
170
|
+
return Object.assign(base, { type: "scheduled_message_sent", final: record.state !== records.STATE.ARMED });
|
|
171
|
+
}
|
|
172
|
+
if (event.type === "cancelled" || event.type === "ended") {
|
|
173
|
+
return Object.assign(base, { type: "scheduled_message_cancelled", reason: record.endReason || null });
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return function publish(event) {
|
|
179
|
+
var project = deps.getProject(event.slug);
|
|
180
|
+
if (!project || !project.sm) return;
|
|
181
|
+
var session = sessionFor(event, project);
|
|
182
|
+
if (!session) return;
|
|
183
|
+
var old = legacy(event, session);
|
|
184
|
+
if (old) project.sm.sendAndRecord(session, old);
|
|
185
|
+
project.sm.sendToSession(session, listMessage(session, deps.listFor(event.slug, session)));
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
module.exports = {
|
|
190
|
+
createWsHandlers: createWsHandlers,
|
|
191
|
+
createPublisher: createPublisher,
|
|
192
|
+
listMessage: listMessage,
|
|
193
|
+
KIND_NOTE: KIND_NOTE,
|
|
194
|
+
};
|