@clagentic/console 1.12.0-beta.1 → 1.12.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSES/README.md +5 -0
- package/README.md +1 -0
- package/bin/cli.js +5 -2
- package/lib/agent-roster-ws.js +84 -0
- package/lib/agent-roster.js +312 -0
- package/lib/auth-required-notify.js +42 -0
- package/lib/build-changes.js +8 -2
- package/lib/build-sha.json +2 -2
- package/lib/build-update-notify.js +45 -0
- package/lib/build-update-offer.js +34 -11
- package/lib/build-update-standing.js +34 -14
- package/lib/claude-settings-env.js +142 -0
- package/lib/cli/duration.js +27 -0
- package/lib/cli/schedule-input-subcommands.js +1 -22
- package/lib/cli/session-subcommands.js +60 -11
- package/lib/client-address.js +44 -0
- package/lib/daemon.js +31 -10
- package/lib/idle-compaction-setting.js +203 -0
- package/lib/mcp-bridge-credential.js +41 -0
- package/lib/notification-prefs.js +18 -22
- package/lib/notify/core.js +210 -0
- package/lib/notify/index.js +31 -0
- package/lib/notify/live-prompts.js +36 -0
- package/lib/notify/payload.js +62 -0
- package/lib/notify/target.js +5 -0
- package/lib/notify/type-registry.js +81 -0
- package/lib/notify/types.js +57 -0
- package/lib/open-sockets.js +27 -0
- package/lib/outbound-access.js +85 -0
- package/lib/outbound-entry.js +116 -0
- package/lib/outbound-ledger.js +306 -0
- package/lib/outbound-query.js +153 -0
- package/lib/pending-prompts.js +31 -16
- package/lib/project-connection.js +48 -8
- package/lib/project-filesystem.js +43 -5
- package/lib/project-http.js +9 -1
- package/lib/project-loop.js +38 -26
- package/lib/project-notifications.js +122 -39
- package/lib/project-prompt-responses.js +1 -1
- package/lib/project-sessions.js +11 -1
- package/lib/project-user-mention.js +22 -34
- package/lib/project-user-message.js +208 -4
- package/lib/project-user-shell.js +298 -0
- package/lib/project.js +41 -5
- package/lib/prompt-answer.js +145 -0
- package/lib/prompt-expiry.js +50 -0
- package/lib/prompt-registry.js +98 -25
- package/lib/prompt-reminders.js +38 -33
- package/lib/prompt-source.js +59 -8
- package/lib/public/app.js +32 -2
- package/lib/public/css/agent-messages.css +96 -0
- package/lib/public/css/agent-roster.css +93 -0
- package/lib/public/css/diagnostics.css +29 -1
- package/lib/public/css/home-hub.css +12 -0
- package/lib/public/css/icon-strip.css +9 -0
- package/lib/public/css/input.css +20 -141
- package/lib/public/css/login-panel.css +73 -0
- package/lib/public/css/menus.css +2 -2
- package/lib/public/css/mobile-nav.css +11 -0
- package/lib/public/css/sidebar.css +18 -0
- package/lib/public/css/team-panel.css +1 -6
- package/lib/public/css/team-view.css +101 -0
- package/lib/public/css/title-bar.css +10 -0
- package/lib/public/css/user-shell.css +144 -0
- package/lib/public/index.html +44 -7
- package/lib/public/modules/activity-state.js +20 -4
- package/lib/public/modules/agent-avatar-picker.js +162 -0
- package/lib/public/modules/agent-avatar.js +153 -0
- package/lib/public/modules/agent-messages.js +285 -0
- package/lib/public/modules/agent-roster.js +157 -0
- package/lib/public/modules/app-connection.js +34 -5
- package/lib/public/modules/app-messages.js +55 -16
- package/lib/public/modules/app-notifications.js +104 -75
- package/lib/public/modules/app-panels.js +26 -3
- package/lib/public/modules/app-projects.js +3 -1
- package/lib/public/modules/app-rate-limit.js +8 -165
- package/lib/public/modules/app-rendering.js +32 -7
- package/lib/public/modules/build-update-sessions.js +81 -0
- package/lib/public/modules/collapsible-text.js +33 -18
- package/lib/public/modules/compaction-state.js +34 -0
- package/lib/public/modules/custom-icons.js +23 -5
- package/lib/public/modules/diagnostics.js +61 -57
- package/lib/public/modules/env-shadow-notice.js +34 -0
- package/lib/public/modules/injected-identity.js +24 -21
- package/lib/public/modules/input.js +176 -15
- package/lib/public/modules/login-panel.js +136 -0
- package/lib/public/modules/login-parser.js +73 -0
- package/lib/public/modules/login-tab.js +66 -0
- package/lib/public/modules/notifications.js +9 -1
- package/lib/public/modules/notify-client.js +246 -0
- package/lib/public/modules/pending-term-request.js +30 -0
- package/lib/public/modules/project-icon.js +22 -2
- package/lib/public/modules/project-settings.js +5 -0
- package/lib/public/modules/prompt-state.js +3 -3
- package/lib/public/modules/prompts.js +1 -1
- package/lib/public/modules/queued-button.js +11 -0
- package/lib/public/modules/scheduled-input-actions.js +12 -4
- package/lib/public/modules/scheduled-outbox.js +230 -0
- package/lib/public/modules/send-now.js +200 -0
- package/lib/public/modules/server-settings.js +50 -1
- package/lib/public/modules/shell-card.js +76 -0
- package/lib/public/modules/shell-line.js +49 -0
- package/lib/public/modules/shell-queue.js +253 -0
- package/lib/public/modules/shell-settings-controls.js +76 -0
- package/lib/public/modules/sidebar-mobile.js +3 -3
- package/lib/public/modules/sidebar-sessions.js +8 -0
- package/lib/public/modules/sidebar-users.js +5 -7
- package/lib/public/modules/team-panel.js +30 -88
- package/lib/public/modules/team-view.js +211 -0
- package/lib/public/modules/terminal-links.js +193 -0
- package/lib/public/modules/terminal.js +84 -107
- package/lib/public/modules/tools.js +19 -0
- package/lib/public/modules/user-shell.js +824 -0
- package/lib/public/notify-sw-logic.js +252 -0
- package/lib/public/notify-target.js +157 -0
- package/lib/public/style.css +5 -0
- package/lib/public/sw.js +20 -69
- package/lib/push.js +63 -19
- package/lib/queued-chat.js +392 -0
- package/lib/runtime-env.js +1 -0
- package/lib/scheduled-input/ws.js +67 -9
- package/lib/sdk-bridge.js +184 -73
- package/lib/sdk-message-processor.js +124 -76
- package/lib/server-auth.js +6 -4
- package/lib/server-dm.js +11 -20
- package/lib/server-settings.js +39 -1
- package/lib/server.js +112 -16
- package/lib/session-directory.js +39 -12
- package/lib/session-end.js +97 -0
- package/lib/session-input-ipc.js +37 -1
- package/lib/session-input.js +263 -21
- package/lib/session-liveness.js +53 -0
- package/lib/session-reclaim.js +37 -2
- package/lib/session-resume.js +1 -0
- package/lib/session-settings-file.js +53 -0
- package/lib/sessions.js +80 -9
- package/lib/team-traffic-ws.js +68 -0
- package/lib/team-traffic.js +318 -0
- package/lib/usage-store.js +36 -7
- package/lib/user-shell-settings.js +105 -0
- package/lib/vendor-auth.js +33 -2
- package/lib/ws-schema.js +33 -5
- package/lib/yoke/adapters/claude-capabilities.js +2 -0
- package/lib/yoke/adapters/claude-vendor.js +17 -1
- package/lib/yoke/adapters/claude-worker.js +39 -11
- package/lib/yoke/adapters/claude.js +225 -6
- package/lib/yoke/adapters/codex-capabilities.js +6 -1
- package/lib/yoke/adapters/codex-user-shell.js +265 -0
- package/lib/yoke/adapters/codex-vendor.js +7 -0
- package/lib/yoke/adapters/codex.js +186 -52
- package/lib/yoke/auth-checks.js +17 -2
- package/lib/yoke/codex-app-server.js +8 -2
- package/lib/yoke/index.js +21 -3
- package/lib/yoke/interface.js +54 -1
- package/lib/yoke/mcp-bridge-server.js +12 -8
- package/lib/yoke/provider-credentials.js +24 -0
- package/lib/yoke/registry.js +40 -1
- package/lib/yoke/user-shell.js +224 -0
- package/package.json +2 -2
- package/scripts/check-test-count.js +14 -0
- package/lib/public/modules/build-notice-gate.js +0 -73
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// The service worker's notification logic, factored out of sw.js so it runs
|
|
2
|
+
// under test with fake browser objects. A classic script (importScripts in the
|
|
3
|
+
// worker, require in node); it needs notify-target.js loaded first.
|
|
4
|
+
//
|
|
5
|
+
// env: { registration, clients, userAgent, scope, setTimeout }
|
|
6
|
+
(function (root, factory) {
|
|
7
|
+
var target = typeof module === "object" && module.exports ? require("./notify-target.js") : root.NotifyTarget;
|
|
8
|
+
var api = factory(target);
|
|
9
|
+
// Always published on the global too: a module-graph import in a CommonJS
|
|
10
|
+
// host (the tests) evaluates this file as CJS and reads it from there.
|
|
11
|
+
root.NotifySw = api;
|
|
12
|
+
if (typeof module === "object" && module.exports) module.exports = api;
|
|
13
|
+
})(typeof self !== "undefined" ? self : globalThis, function (NotifyTarget) {
|
|
14
|
+
var RESOLVED_LINGER_MS = 4000;
|
|
15
|
+
|
|
16
|
+
function isCore(data) {
|
|
17
|
+
return !!data && data.core === 1;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Browsers that enforce userVisibleOnly (Chrome and other Chromium browsers,
|
|
21
|
+
// iOS and desktop Safari) fail a push event that shows no notification: Safari
|
|
22
|
+
// revokes the subscription, Chrome posts its own generic "updated in the
|
|
23
|
+
// background" notice. No browser is known to allow a silent push, so every
|
|
24
|
+
// push shows something, whatever the user agent.
|
|
25
|
+
function requiresVisible() {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The tag of the silent notice for a push that names no tag to replace.
|
|
30
|
+
var SILENT_TAG = "console-silent";
|
|
31
|
+
|
|
32
|
+
/** The options a core notification is shown with: all from the payload. */
|
|
33
|
+
function optionsFor(data) {
|
|
34
|
+
return {
|
|
35
|
+
body: data.body || "",
|
|
36
|
+
tag: data.tag,
|
|
37
|
+
data: data,
|
|
38
|
+
requireInteraction: data.requireInteraction === true,
|
|
39
|
+
renotify: data.renotify === true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function showCore(env, data) {
|
|
44
|
+
return env.registration.showNotification(data.title || "Clagentic: Console", optionsFor(data));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var markerSeq = 0;
|
|
48
|
+
|
|
49
|
+
function isPlaceholder(n) {
|
|
50
|
+
return !!n && !!n.data && n.data.resolved === true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Shows the silent notice under a tag and closes it after `lingerMs` (at
|
|
54
|
+
// once for 0). The notice carries a marker unique to this close, and only a
|
|
55
|
+
// notification carrying that marker is closed afterwards: a newer live
|
|
56
|
+
// notification that took the tag in the meantime is left alone.
|
|
57
|
+
function showPlaceholder(env, data, tag, lingerMs) {
|
|
58
|
+
var marker = tag + "#" + Date.now() + "#" + (++markerSeq);
|
|
59
|
+
var wait = env.setTimeout || setTimeout;
|
|
60
|
+
function closeMine() {
|
|
61
|
+
return env.registration.getNotifications({ tag: tag }).then(function (left) {
|
|
62
|
+
left.forEach(function (n) {
|
|
63
|
+
if (n.data && n.data.resolvedMarker === marker) n.close();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return env.registration.showNotification(data.title || "Clagentic: Console", {
|
|
68
|
+
body: data.body || "",
|
|
69
|
+
tag: tag,
|
|
70
|
+
silent: true,
|
|
71
|
+
requireInteraction: false,
|
|
72
|
+
renotify: false,
|
|
73
|
+
data: { resolved: true, resolvedMarker: marker },
|
|
74
|
+
}).then(function () {
|
|
75
|
+
if (lingerMs <= 0) return closeMine();
|
|
76
|
+
return new Promise(function (done) {
|
|
77
|
+
wait(function () { closeMine().then(done, done); }, lingerMs);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Closes the shown notification under each tag. The shown one is replaced
|
|
83
|
+
// under the same tag by a silent, non-interactive notice that closes itself
|
|
84
|
+
// shortly after. When nothing was shown under any tag (the person already
|
|
85
|
+
// dismissed it), the push still has to show something, so a single silent
|
|
86
|
+
// notice is shown and closed at once: the least visible thing a browser
|
|
87
|
+
// allows.
|
|
88
|
+
function closeByTags(env, data) {
|
|
89
|
+
var tags = Array.isArray(data.tags) ? data.tags : [];
|
|
90
|
+
return Promise.all(tags.map(function (tag) {
|
|
91
|
+
return env.registration.getNotifications({ tag: tag }).then(function (shown) {
|
|
92
|
+
return { tag: tag, shown: shown.filter(function (n) { return !isPlaceholder(n); }) };
|
|
93
|
+
});
|
|
94
|
+
})).then(function (found) {
|
|
95
|
+
var matched = found.filter(function (f) { return f.shown.length > 0; });
|
|
96
|
+
if (matched.length === 0) {
|
|
97
|
+
return showPlaceholder(env, data, tags.length ? tags[0] : SILENT_TAG, 0);
|
|
98
|
+
}
|
|
99
|
+
return Promise.all(matched.map(function (f) {
|
|
100
|
+
return showPlaceholder(env, data, f.tag, RESOLVED_LINGER_MS);
|
|
101
|
+
}));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Whether the page's own record still lists the prompt a shown notification
|
|
106
|
+
// names. Only the notifications whose payload says the page can verify them
|
|
107
|
+
// (liveInState) are judged.
|
|
108
|
+
// notifications: the page's banner list (notifications_state).
|
|
109
|
+
// livePrompts: the server's list of prompts awaiting the operator, with
|
|
110
|
+
// the server time it was taken; a notification sent after that is not
|
|
111
|
+
// judged by it, as the prompt may have opened since.
|
|
112
|
+
function isLive(data, notifications, livePrompts) {
|
|
113
|
+
var t = NotifyTarget.makeTarget(data.target);
|
|
114
|
+
if (!t) return true;
|
|
115
|
+
var sessionKey = NotifyTarget.sessionKey(t);
|
|
116
|
+
var banner = (notifications || []).some(function (n) {
|
|
117
|
+
if (n && n.key && n.key === data.tag) return true;
|
|
118
|
+
var meta = (n && n.meta) || {};
|
|
119
|
+
if (data.collapse === "request" && t.requestId) {
|
|
120
|
+
if (meta.requestId === t.requestId) return true;
|
|
121
|
+
return Array.isArray(meta.requestIds) && meta.requestIds.indexOf(t.requestId) !== -1;
|
|
122
|
+
}
|
|
123
|
+
return meta.reminderKey === sessionKey;
|
|
124
|
+
});
|
|
125
|
+
if (banner) return true;
|
|
126
|
+
if (data.collapse !== "request" || !t.requestId || !livePrompts) return false;
|
|
127
|
+
if (typeof data.sentAt !== "number" || data.sentAt >= livePrompts.at) return true;
|
|
128
|
+
return (livePrompts.items || []).some(function (p) {
|
|
129
|
+
return String(p.sessionId) === t.sessionId &&
|
|
130
|
+
(p.requestId === t.requestId || p.toolUseId === t.requestId);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The same live check for an in-app banner: the banner's notification, in the
|
|
136
|
+
* shape isLive judges a shown push in. A banner the registry does not mark
|
|
137
|
+
* liveInState is not judged and reads as live.
|
|
138
|
+
* @param {object} notif a notification from notifications_state or
|
|
139
|
+
* notification_created.
|
|
140
|
+
* @param {object[]} notifications the page's notifications_state list.
|
|
141
|
+
* @param {?object} livePrompts the live-prompt record of the connection.
|
|
142
|
+
*/
|
|
143
|
+
function isBannerLive(notif, notifications, livePrompts) {
|
|
144
|
+
if (!notif || notif.liveInState !== true) return true;
|
|
145
|
+
var meta = notif.meta || {};
|
|
146
|
+
return isLive({
|
|
147
|
+
target: { slug: notif.slug, sessionId: notif.sessionId, requestId: meta.requestId },
|
|
148
|
+
collapse: notif.collapse,
|
|
149
|
+
tag: notif.key,
|
|
150
|
+
sentAt: notif.createdAt,
|
|
151
|
+
}, notifications, livePrompts);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Closes the shown core notifications whose prompt has ended. The backup for
|
|
156
|
+
* a close push that never arrived. A page never judges another project's
|
|
157
|
+
* notifications: only those whose target is the page's own project.
|
|
158
|
+
* @param {object} registration
|
|
159
|
+
* @param {object[]} notifications the page's notifications_state list.
|
|
160
|
+
* @param {{slug: string, livePrompts: ?object}} scope the page's project
|
|
161
|
+
* slug, and the live-prompt record of its connection.
|
|
162
|
+
* @returns {Promise<number>} how many were closed.
|
|
163
|
+
*/
|
|
164
|
+
function reconcileShown(registration, notifications, scope) {
|
|
165
|
+
var slug = scope && typeof scope.slug === "string" && scope.slug ? scope.slug : null;
|
|
166
|
+
if (!slug) return Promise.resolve(0);
|
|
167
|
+
var livePrompts = scope.livePrompts || null;
|
|
168
|
+
return registration.getNotifications().then(function (shown) {
|
|
169
|
+
var closed = 0;
|
|
170
|
+
shown.forEach(function (n) {
|
|
171
|
+
var data = n.data;
|
|
172
|
+
if (!isCore(data) || data.liveInState !== true) return;
|
|
173
|
+
if (!data.target || data.target.slug !== slug) return;
|
|
174
|
+
if (isLive(data, notifications, livePrompts)) return;
|
|
175
|
+
n.close();
|
|
176
|
+
closed++;
|
|
177
|
+
});
|
|
178
|
+
return closed;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @param {object} env
|
|
184
|
+
* @param {object} data the parsed push payload.
|
|
185
|
+
* @returns {Promise<*>}
|
|
186
|
+
*/
|
|
187
|
+
function handlePush(env, data) {
|
|
188
|
+
// A push that has nothing to display (a test push, an absent or malformed
|
|
189
|
+
// payload, one queued on a device before the notification core with no
|
|
190
|
+
// core mark) still shows the silent notice, closed at once, so the browser
|
|
191
|
+
// posts no generic notice of its own. Showing it carries no title or body
|
|
192
|
+
// from the payload: those are not trusted when the payload is unmarked.
|
|
193
|
+
if (!isCore(data)) return showPlaceholder(env, {}, SILENT_TAG, 0);
|
|
194
|
+
if (data.type === "notify_close") return closeByTags(env, data);
|
|
195
|
+
return showCore(env, data);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Focus a window and hand it the target to route to; open one at the deep
|
|
199
|
+
// link when none exists. A window already on the target's project is
|
|
200
|
+
// preferred, so a tap does not move another project's window.
|
|
201
|
+
function coreClick(env, data) {
|
|
202
|
+
var t = NotifyTarget.makeTarget(data.target);
|
|
203
|
+
var base = env.scope || "/";
|
|
204
|
+
// A window opened cold has no router message to wait for: the type rides
|
|
205
|
+
// in the URL so the page lands on the place the notice leads to.
|
|
206
|
+
var url = NotifyTarget.urlForTarget(t, base, isCore(data) ? data.type : undefined);
|
|
207
|
+
var prefix = t && t.slug ? base + "p/" + t.slug + "/" : null;
|
|
208
|
+
return env.clients.matchAll({ type: "window", includeUncontrolled: true }).then(function (list) {
|
|
209
|
+
var pick = null;
|
|
210
|
+
var i;
|
|
211
|
+
if (prefix) {
|
|
212
|
+
for (i = 0; i < list.length && !pick; i++) {
|
|
213
|
+
if (list[i].url.indexOf(prefix) !== -1) pick = list[i];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
for (i = 0; i < list.length && !pick; i++) {
|
|
217
|
+
if (list[i].visibilityState !== "hidden") pick = list[i];
|
|
218
|
+
}
|
|
219
|
+
if (!pick && list.length > 0) pick = list[0];
|
|
220
|
+
if (!pick) return env.clients.openWindow(url);
|
|
221
|
+
return Promise.resolve(pick.focus()).then(function () {
|
|
222
|
+
// The type travels with the target: a system target names no place, and
|
|
223
|
+
// the page's router looks the place up by type.
|
|
224
|
+
var route = { type: "notify_route", target: t };
|
|
225
|
+
if (isCore(data) && typeof data.type === "string") route.notifyType = data.type;
|
|
226
|
+
pick.postMessage(route);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @param {object} env
|
|
233
|
+
* @param {object} notification the clicked notification (already closed by
|
|
234
|
+
* the caller).
|
|
235
|
+
*/
|
|
236
|
+
function handleClick(env, notification) {
|
|
237
|
+
var data = notification.data || {};
|
|
238
|
+
if (data.resolved === true) return Promise.resolve();
|
|
239
|
+
// A notification shown before the upgrade has no target: it opens the app.
|
|
240
|
+
return coreClick(env, data);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
handlePush: handlePush,
|
|
245
|
+
handleClick: handleClick,
|
|
246
|
+
reconcileShown: reconcileShown,
|
|
247
|
+
isLive: isLive,
|
|
248
|
+
isBannerLive: isBannerLive,
|
|
249
|
+
requiresVisible: requiresVisible,
|
|
250
|
+
RESOLVED_LINGER_MS: RESOLVED_LINGER_MS,
|
|
251
|
+
};
|
|
252
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// The notification target model, shared by the server notification core
|
|
2
|
+
// (lib/notify/), the service worker (importScripts) and the page's ES modules
|
|
3
|
+
// (side-effect import, then read from globalThis). A classic script with no
|
|
4
|
+
// import/export so all three can load it.
|
|
5
|
+
//
|
|
6
|
+
// A target names where a notification's action lives: the project (slug), the
|
|
7
|
+
// console session (sessionId) and, where there is one, the prompt (requestId).
|
|
8
|
+
// Session ids restart in every project, so a target without its slug is
|
|
9
|
+
// ambiguous: the slug is always part of its identity. A direct message belongs
|
|
10
|
+
// to no project: its target names the other person (peerId) instead.
|
|
11
|
+
(function (root, factory) {
|
|
12
|
+
var api = factory();
|
|
13
|
+
// Always published on the global too: a module-graph import in a CommonJS
|
|
14
|
+
// host (the tests) evaluates this file as CJS and reads it from there.
|
|
15
|
+
root.NotifyTarget = api;
|
|
16
|
+
if (typeof module === "object" && module.exports) module.exports = api;
|
|
17
|
+
})(typeof self !== "undefined" ? self : globalThis, function () {
|
|
18
|
+
var SLUG_RE = /^[a-z0-9_-]+$/;
|
|
19
|
+
// User ids, as the direct-message keys accept them.
|
|
20
|
+
var PEER_RE = /^[A-Za-z0-9_-]+$/;
|
|
21
|
+
var TYPE_RE = /^[a-z][a-z0-9_]*$/;
|
|
22
|
+
|
|
23
|
+
// An id is a string or a number; anything else (an object from a hostile or
|
|
24
|
+
// broken message) names nothing, and is never coerced to text.
|
|
25
|
+
function present(v) {
|
|
26
|
+
return (typeof v === "string" && v !== "") || typeof v === "number";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {{slug: ?string, sessionId: ?(number|string), requestId: ?string, peerId: ?string}} t
|
|
31
|
+
* @returns {{slug: ?string, sessionId: ?string, requestId: ?string, peerId?: string}|null}
|
|
32
|
+
* a normalised target, or null when the input names no valid target. An id
|
|
33
|
+
* is carried as a string; a slug that is not a plain project slug is
|
|
34
|
+
* refused, since it ends up in a URL path. peerId (the other person of a
|
|
35
|
+
* direct message) is present only when given.
|
|
36
|
+
*/
|
|
37
|
+
function makeTarget(t) {
|
|
38
|
+
if (!t || typeof t !== "object") return null;
|
|
39
|
+
var slug = present(t.slug) ? String(t.slug) : null;
|
|
40
|
+
if (slug !== null && !SLUG_RE.test(slug)) return null;
|
|
41
|
+
var peerId = null;
|
|
42
|
+
if (present(t.peerId)) {
|
|
43
|
+
peerId = String(t.peerId);
|
|
44
|
+
if (!PEER_RE.test(peerId)) return null;
|
|
45
|
+
}
|
|
46
|
+
var out = {
|
|
47
|
+
slug: slug,
|
|
48
|
+
sessionId: present(t.sessionId) ? String(t.sessionId) : null,
|
|
49
|
+
requestId: present(t.requestId) ? String(t.requestId) : null,
|
|
50
|
+
};
|
|
51
|
+
if (peerId !== null) out.peerId = peerId;
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The identity of where a target lives, before any request: the project and
|
|
56
|
+
// session, or the conversation with a peer.
|
|
57
|
+
function placeKey(n) {
|
|
58
|
+
return n.peerId ? "dm:" + n.peerId : (n.slug || "") + ":" + (n.sessionId || "");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The one identity behind collapse, close and route: slug:sessionId[:requestId]. */
|
|
62
|
+
function targetKey(t) {
|
|
63
|
+
var n = makeTarget(t);
|
|
64
|
+
if (!n) return "";
|
|
65
|
+
var key = placeKey(n);
|
|
66
|
+
return n.requestId ? key + ":" + n.requestId : key;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The session-level identity (no request): slug:sessionId. */
|
|
70
|
+
function sessionKey(t) {
|
|
71
|
+
var n = makeTarget(t);
|
|
72
|
+
return n ? placeKey(n) : "";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The tag a notification of a type shows under, on every device: the type
|
|
77
|
+
* and the target's identity, at the type's collapse level. The server core
|
|
78
|
+
* and the page's own notifications derive it here, so they agree.
|
|
79
|
+
* @param {string} typeName
|
|
80
|
+
* @param {"request"|"session"} collapse
|
|
81
|
+
* @param {object} target
|
|
82
|
+
*/
|
|
83
|
+
function tagFor(typeName, collapse, target) {
|
|
84
|
+
return "n:" + typeName + ":" + (collapse === "request" ? targetKey(target) : sessionKey(target));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The deep link that opens a target: <base>p/<slug>/?session=<id>[&request=<id>].
|
|
89
|
+
* A target with no slug (a system notice) opens the base page; a direct
|
|
90
|
+
* message's, the base page with its conversation named. A system target also
|
|
91
|
+
* names its notification type when one is given, so a page opened cold knows
|
|
92
|
+
* which place the notice leads to: <base>?notify=<type>.
|
|
93
|
+
* @param {object} target
|
|
94
|
+
* @param {string} [base] the app root with a trailing slash; "/" by default.
|
|
95
|
+
* @param {string} [type] the notification type, used only for a system target.
|
|
96
|
+
*/
|
|
97
|
+
function urlForTarget(target, base, type) {
|
|
98
|
+
var n = makeTarget(target);
|
|
99
|
+
var root = base || "/";
|
|
100
|
+
if (root.charAt(root.length - 1) !== "/") root += "/";
|
|
101
|
+
if (n && n.peerId) return root + "?dm=" + encodeURIComponent(n.peerId);
|
|
102
|
+
if (!n || !n.slug) return typeof type === "string" && TYPE_RE.test(type) ? root + "?notify=" + type : root;
|
|
103
|
+
var url = root + "p/" + n.slug + "/";
|
|
104
|
+
var q = [];
|
|
105
|
+
if (n.sessionId) q.push("session=" + encodeURIComponent(n.sessionId));
|
|
106
|
+
if (n.requestId) q.push("request=" + encodeURIComponent(n.requestId));
|
|
107
|
+
return q.length ? url + "?" + q.join("&") : url;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Reads a deep link's query. The slug comes from the path the page was
|
|
112
|
+
* served on, so only the session and the request are in the query.
|
|
113
|
+
* @param {string} search location.search
|
|
114
|
+
* @returns {{sessionId: string, requestId: ?string}|null}
|
|
115
|
+
*/
|
|
116
|
+
function parseDeepLink(search) {
|
|
117
|
+
if (typeof search !== "string" || !search) return null;
|
|
118
|
+
var params = new URLSearchParams(search);
|
|
119
|
+
var session = params.get("session");
|
|
120
|
+
if (!session || !/^[0-9]+$/.test(session)) return null;
|
|
121
|
+
var request = params.get("request");
|
|
122
|
+
return { sessionId: session, requestId: request || null };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Reads the conversation a deep link names: the base page with ?dm=<userId>.
|
|
127
|
+
* @param {string} search location.search
|
|
128
|
+
* @returns {?string} the other person's user id.
|
|
129
|
+
*/
|
|
130
|
+
function parsePeerLink(search) {
|
|
131
|
+
if (typeof search !== "string" || !search) return null;
|
|
132
|
+
var peer = new URLSearchParams(search).get("dm");
|
|
133
|
+
return peer && PEER_RE.test(peer) ? peer : null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Reads the system notification type a cold-start deep link names.
|
|
138
|
+
* @param {string} search location.search
|
|
139
|
+
* @returns {?string}
|
|
140
|
+
*/
|
|
141
|
+
function parsePlaceLink(search) {
|
|
142
|
+
if (typeof search !== "string" || !search) return null;
|
|
143
|
+
var type = new URLSearchParams(search).get("notify");
|
|
144
|
+
return type && TYPE_RE.test(type) ? type : null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
makeTarget: makeTarget,
|
|
149
|
+
parsePeerLink: parsePeerLink,
|
|
150
|
+
parsePlaceLink: parsePlaceLink,
|
|
151
|
+
targetKey: targetKey,
|
|
152
|
+
sessionKey: sessionKey,
|
|
153
|
+
tagFor: tagFor,
|
|
154
|
+
urlForTarget: urlForTarget,
|
|
155
|
+
parseDeepLink: parseDeepLink,
|
|
156
|
+
};
|
|
157
|
+
});
|
package/lib/public/style.css
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@import url("css/base.css");
|
|
2
|
+
@import url("css/login-panel.css");
|
|
2
3
|
@import url("css/icon-strip.css");
|
|
3
4
|
@import url("css/title-bar.css");
|
|
4
5
|
@import url("css/sidebar.css");
|
|
@@ -33,5 +34,9 @@
|
|
|
33
34
|
@import url("css/at-agents.css");
|
|
34
35
|
@import url("css/notifications-center.css");
|
|
35
36
|
@import url("css/team-panel.css");
|
|
37
|
+
@import url("css/team-view.css");
|
|
38
|
+
@import url("css/agent-messages.css");
|
|
39
|
+
@import url("css/agent-roster.css");
|
|
36
40
|
@import url("css/diagnostics.css");
|
|
41
|
+
@import url("css/user-shell.css");
|
|
37
42
|
|
package/lib/public/sw.js
CHANGED
|
@@ -115,81 +115,32 @@ self.addEventListener("fetch", function (event) {
|
|
|
115
115
|
|
|
116
116
|
// --- Push notifications ---
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
data: data,
|
|
118
|
+
// The show, close and tap logic lives in notify-sw-logic.js so it can be tested
|
|
119
|
+
// without a browser; this file only wires it to the worker's events.
|
|
120
|
+
importScripts("/notify-target.js", "/notify-sw-logic.js");
|
|
121
|
+
|
|
122
|
+
function notifyEnv() {
|
|
123
|
+
return {
|
|
124
|
+
registration: self.registration,
|
|
125
|
+
clients: self.clients,
|
|
126
|
+
userAgent: self.navigator ? self.navigator.userAgent : "",
|
|
127
|
+
scope: self.registration.scope || "/",
|
|
129
128
|
};
|
|
129
|
+
}
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
options.renotify = true;
|
|
140
|
-
} else if (data.type === "done") {
|
|
141
|
-
options.tag = data.tag || "claude-done";
|
|
142
|
-
} else if (data.type === "ask_user") {
|
|
143
|
-
options.requireInteraction = true;
|
|
144
|
-
options.tag = "claude-ask";
|
|
145
|
-
} else if (data.type === "error") {
|
|
146
|
-
options.requireInteraction = true;
|
|
147
|
-
options.tag = "claude-error";
|
|
148
|
-
} else if (data.type === "dm") {
|
|
149
|
-
options.tag = data.tag || "dm";
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
event.waitUntil(
|
|
153
|
-
self.clients.matchAll({ type: "window", includeUncontrolled: true }).then(function (clientList) {
|
|
154
|
-
// Always show permission requests, questions, and errors
|
|
155
|
-
// Only suppress "done" notifications when app is in foreground
|
|
156
|
-
if (data.type !== "permission_request" && data.type !== "permission_reminder" && data.type !== "ask_user" && data.type !== "error") {
|
|
157
|
-
for (var i = 0; i < clientList.length; i++) {
|
|
158
|
-
if (clientList[i].focused || clientList[i].visibilityState === "visible") return;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return self.registration.showNotification(data.title || "Clagentic: Console", options);
|
|
162
|
-
}).catch(function () {})
|
|
163
|
-
);
|
|
131
|
+
self.addEventListener("push", function (event) {
|
|
132
|
+
// An unreadable payload is handled as an empty one: the push still shows the
|
|
133
|
+
// silent notice instead of leaving the browser to post its generic one.
|
|
134
|
+
var data = null;
|
|
135
|
+
try { data = event.data.json(); } catch (e) { data = null; }
|
|
136
|
+
event.waitUntil(NotifySw.handlePush(notifyEnv(), data).catch(function () {
|
|
137
|
+
return NotifySw.handlePush(notifyEnv(), null).catch(function () {});
|
|
138
|
+
}));
|
|
164
139
|
});
|
|
165
140
|
|
|
166
141
|
// --- Notification click ---
|
|
167
142
|
|
|
168
143
|
self.addEventListener("notificationclick", function (event) {
|
|
169
|
-
var data = event.notification.data || {};
|
|
170
144
|
event.notification.close();
|
|
171
|
-
|
|
172
|
-
// Build target URL from slug so we open the correct project
|
|
173
|
-
var baseUrl = self.registration.scope || "/";
|
|
174
|
-
var targetUrl = data.slug ? baseUrl + "p/" + data.slug + "/" : baseUrl;
|
|
175
|
-
|
|
176
|
-
event.waitUntil(
|
|
177
|
-
self.clients.matchAll({ type: "window", includeUncontrolled: true }).then(function (clientList) {
|
|
178
|
-
// Prefer a client already on the correct project
|
|
179
|
-
for (var i = 0; i < clientList.length; i++) {
|
|
180
|
-
if (clientList[i].url.indexOf(targetUrl) !== -1) {
|
|
181
|
-
return clientList[i].focus();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// Fall back to any visible client
|
|
185
|
-
for (var i = 0; i < clientList.length; i++) {
|
|
186
|
-
if (clientList[i].visibilityState !== "hidden") {
|
|
187
|
-
return clientList[i].focus();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (clientList.length > 0) return clientList[0].focus();
|
|
191
|
-
return self.clients.openWindow(targetUrl);
|
|
192
|
-
})
|
|
193
|
-
);
|
|
145
|
+
event.waitUntil(NotifySw.handleClick(notifyEnv(), event.notification));
|
|
194
146
|
});
|
|
195
|
-
|
package/lib/push.js
CHANGED
|
@@ -4,6 +4,17 @@ var path = require("path");
|
|
|
4
4
|
var config = require("./config");
|
|
5
5
|
var store = require("./store");
|
|
6
6
|
var { categoryOfPush } = require("./notification-prefs");
|
|
7
|
+
var usersModule = require("./users");
|
|
8
|
+
|
|
9
|
+
// The daemon's mode; a mode that cannot be read counts as multi-user, the
|
|
10
|
+
// stricter one (same rule as lib/push-audience.js).
|
|
11
|
+
function multiUserMode(isMultiUser) {
|
|
12
|
+
try {
|
|
13
|
+
return isMultiUser() !== false;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
7
18
|
|
|
8
19
|
function loadOrCreateVapidKeys() {
|
|
9
20
|
var dir = config.CONFIG_DIR;
|
|
@@ -31,9 +42,13 @@ function loadOrCreateVapidKeys() {
|
|
|
31
42
|
* user has muted is not sent to that user's subscriptions; this is the one
|
|
32
43
|
* place push is filtered, so a muted type never reaches the phone whichever
|
|
33
44
|
* caller raised it.
|
|
45
|
+
* @param {function(): boolean} [opts.isMultiUser] the daemon's mode; defaults to
|
|
46
|
+
* the users store. In multi-user mode a subscription with no user is neither
|
|
47
|
+
* stored nor sent to: nobody can say whose device it is.
|
|
34
48
|
*/
|
|
35
49
|
function initPush(opts) {
|
|
36
50
|
var prefs = opts && opts.prefs ? opts.prefs : null;
|
|
51
|
+
var isMultiUser = opts && opts.isMultiUser ? opts.isMultiUser : usersModule.isMultiUser;
|
|
37
52
|
|
|
38
53
|
var keys = loadOrCreateVapidKeys();
|
|
39
54
|
|
|
@@ -89,8 +104,16 @@ function initPush(opts) {
|
|
|
89
104
|
})(startupEndpoints[si]);
|
|
90
105
|
}
|
|
91
106
|
|
|
107
|
+
/**
|
|
108
|
+
* @returns {boolean} false when the subscription was refused: it has no
|
|
109
|
+
* endpoint, or it has no user in multi-user mode.
|
|
110
|
+
*/
|
|
92
111
|
function addSubscription(sub, replaceEndpoint, userId) {
|
|
93
|
-
if (!sub || !sub.endpoint) return;
|
|
112
|
+
if (!sub || !sub.endpoint) return false;
|
|
113
|
+
if (!userId && multiUserMode(isMultiUser)) {
|
|
114
|
+
console.log("[push] refused anonymous subscription in multi-user mode");
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
94
117
|
// Remove previous subscription from the same client if endpoint changed.
|
|
95
118
|
// Only delete replaceEndpoint if it belongs to the same caller — prevents an
|
|
96
119
|
// unauthenticated request from unsubscribing arbitrary known endpoints.
|
|
@@ -106,8 +129,14 @@ function initPush(opts) {
|
|
|
106
129
|
subscriptions.delete(replaceEndpoint);
|
|
107
130
|
}
|
|
108
131
|
}
|
|
109
|
-
// Attach userId for per-user targeting
|
|
110
|
-
|
|
132
|
+
// Attach userId for per-user targeting. An authenticated re-register of an
|
|
133
|
+
// endpoint stored without a user claims it, so a device subscribed before
|
|
134
|
+
// the user was recorded recovers when its client re-sends the subscription.
|
|
135
|
+
if (userId) {
|
|
136
|
+
var stored = subscriptions.get(sub.endpoint);
|
|
137
|
+
if (stored && !stored._userId) console.log("[push] claimed anonymous subscription user=" + userId);
|
|
138
|
+
sub._userId = userId;
|
|
139
|
+
}
|
|
111
140
|
// Store immediately, then validate async. Invalid subs get cleaned on first sendPush.
|
|
112
141
|
subscriptions.set(sub.endpoint, sub);
|
|
113
142
|
save();
|
|
@@ -137,36 +166,50 @@ function initPush(opts) {
|
|
|
137
166
|
return allowed;
|
|
138
167
|
}
|
|
139
168
|
|
|
169
|
+
// Sends still on the wire, so a shutdown can wait for them (flush).
|
|
170
|
+
var inflight = new Set();
|
|
171
|
+
|
|
172
|
+
function sendTo(sub, endpoint, json) {
|
|
173
|
+
var sent = webpush.sendNotification(sub, json, { vapidDetails: vapidDetails })
|
|
174
|
+
.then(function () {})
|
|
175
|
+
.catch(function (err) {
|
|
176
|
+
if (err.statusCode === 410 || err.statusCode === 404 || err.statusCode === 403) {
|
|
177
|
+
subscriptions.delete(endpoint);
|
|
178
|
+
save();
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
.then(function () { inflight.delete(sent); });
|
|
182
|
+
inflight.add(sent);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Resolves once every push sent so far has been handed to the push service. */
|
|
186
|
+
function flush() {
|
|
187
|
+
return Promise.all(Array.from(inflight));
|
|
188
|
+
}
|
|
189
|
+
|
|
140
190
|
function sendPush(payload) {
|
|
141
191
|
var json = JSON.stringify(payload);
|
|
192
|
+
var multi = multiUserMode(isMultiUser);
|
|
142
193
|
subscriptions.forEach(function (sub, endpoint) {
|
|
194
|
+
// A subscription stored before users were recorded has no owner; in
|
|
195
|
+
// multi-user mode a broadcast must not reach a device nobody can name.
|
|
196
|
+
if (multi && !sub._userId) return;
|
|
143
197
|
if (!wanted(sub, payload)) return;
|
|
144
|
-
|
|
145
|
-
.then(function () {})
|
|
146
|
-
.catch(function (err) {
|
|
147
|
-
if (err.statusCode === 410 || err.statusCode === 404 || err.statusCode === 403) {
|
|
148
|
-
subscriptions.delete(endpoint);
|
|
149
|
-
save();
|
|
150
|
-
}
|
|
151
|
-
});
|
|
198
|
+
sendTo(sub, endpoint, json);
|
|
152
199
|
});
|
|
153
200
|
}
|
|
154
201
|
|
|
155
202
|
function sendPushToUser(userId, payload) {
|
|
156
203
|
if (!userId) return;
|
|
157
204
|
var json = JSON.stringify(payload);
|
|
205
|
+
var matched = 0;
|
|
158
206
|
subscriptions.forEach(function (sub, endpoint) {
|
|
159
207
|
if (sub._userId !== userId) return;
|
|
208
|
+
matched++;
|
|
160
209
|
if (!wanted(sub, payload)) return;
|
|
161
|
-
|
|
162
|
-
.then(function () {})
|
|
163
|
-
.catch(function (err) {
|
|
164
|
-
if (err.statusCode === 410 || err.statusCode === 404 || err.statusCode === 403) {
|
|
165
|
-
subscriptions.delete(endpoint);
|
|
166
|
-
save();
|
|
167
|
-
}
|
|
168
|
-
});
|
|
210
|
+
sendTo(sub, endpoint, json);
|
|
169
211
|
});
|
|
212
|
+
if (!matched) console.log("[push] no-subscription user=" + userId + " type=" + payload.type);
|
|
170
213
|
}
|
|
171
214
|
|
|
172
215
|
return {
|
|
@@ -175,6 +218,7 @@ function initPush(opts) {
|
|
|
175
218
|
removeSubscription: removeSubscription,
|
|
176
219
|
sendPush: sendPush,
|
|
177
220
|
sendPushToUser: sendPushToUser,
|
|
221
|
+
flush: flush,
|
|
178
222
|
};
|
|
179
223
|
}
|
|
180
224
|
|