@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,306 @@
|
|
|
1
|
+
// outbound-ledger.js - the sender-side record of what a session sent out.
|
|
2
|
+
//
|
|
3
|
+
// Every open-session and send-input request (CLI verb or file drop) leaves one
|
|
4
|
+
// line here, written by the sender: the delivery, or the refusal or failure.
|
|
5
|
+
// The target's own history holds a delivered prompt too, but nothing there lists
|
|
6
|
+
// what one sender sent, and a refused request leaves no trace at all.
|
|
7
|
+
//
|
|
8
|
+
// Location: <console data dir>/outbound/ (0700; files 0600)
|
|
9
|
+
// sessions/<project>/<sender>.jsonl a sender the console identified from its
|
|
10
|
+
// own records (senderKind "extracted")
|
|
11
|
+
// unattributed/declared/<name>.jsonl a sender that only named itself (--from)
|
|
12
|
+
// unattributed/undeclared/undeclared.jsonl a sender that named nobody
|
|
13
|
+
// Unattributed lines are self-reported and unverified; they are kept apart so a
|
|
14
|
+
// reader never mistakes one for an identified sender.
|
|
15
|
+
//
|
|
16
|
+
// One JSON object per line, appended with a single write; a reader skips a line
|
|
17
|
+
// it cannot parse. The line holds the full prompt text, so the files are as
|
|
18
|
+
// private as the session history and are removed after the retention period
|
|
19
|
+
// (default 30 days, daemon.json "outboundRetentionDays"; 0 turns the ledger off).
|
|
20
|
+
//
|
|
21
|
+
// Writing never fails the request it describes: record() logs and returns.
|
|
22
|
+
|
|
23
|
+
var crypto = require("crypto");
|
|
24
|
+
var fs = require("fs");
|
|
25
|
+
var path = require("path");
|
|
26
|
+
|
|
27
|
+
var FORMAT_VERSION = 1;
|
|
28
|
+
var DIR_NAME = "outbound";
|
|
29
|
+
var DEFAULT_RETENTION_DAYS = 30;
|
|
30
|
+
var MAX_RETENTION_DAYS = 3650;
|
|
31
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
32
|
+
var PRUNE_INTERVAL_MS = 6 * 60 * 60 * 1000;
|
|
33
|
+
|
|
34
|
+
var SENDER_DIR = "sessions";
|
|
35
|
+
var UNATTRIBUTED_DIR = "unattributed";
|
|
36
|
+
|
|
37
|
+
// The retention in days a configured value means. A missing value is the
|
|
38
|
+
// default; anything that is not a whole number of days from 0 to 3650 is the
|
|
39
|
+
// default too, and { invalid: true } says so, so a typo is not silently kept.
|
|
40
|
+
function retentionDaysFrom(raw) {
|
|
41
|
+
if (raw === undefined || raw === null) return { days: DEFAULT_RETENTION_DAYS };
|
|
42
|
+
if (typeof raw === "number" && Number.isInteger(raw) && raw >= 0 && raw <= MAX_RETENTION_DAYS) return { days: raw };
|
|
43
|
+
return { days: DEFAULT_RETENTION_DAYS, invalid: true };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// A name that is safe as one path component. A value that is not a plain id is
|
|
47
|
+
// replaced by a hash of itself, so two different values never share a file and
|
|
48
|
+
// nothing a sender chose can name a path.
|
|
49
|
+
function segment(raw) {
|
|
50
|
+
var s = String(raw);
|
|
51
|
+
if (/^[A-Za-z0-9_][A-Za-z0-9_-]{0,63}$/.test(s)) return s;
|
|
52
|
+
return "x-" + crypto.createHash("sha256").update(s).digest("hex").slice(0, 16);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The file an entry belongs in, relative to the ledger root.
|
|
56
|
+
function relativePathFor(entry) {
|
|
57
|
+
var sender = entry.sender || {};
|
|
58
|
+
if (sender.attribution === "extracted" && sender.project && (sender.cliSessionId || sender.sessionId)) {
|
|
59
|
+
// The vendor session id survives a daemon restart; the console id is
|
|
60
|
+
// renumbered, so it names a sender only until the vendor has named it.
|
|
61
|
+
var key = sender.cliSessionId ? segment(sender.cliSessionId) : "console-" + segment(sender.sessionId);
|
|
62
|
+
return path.join(SENDER_DIR, segment(sender.project), key + ".jsonl");
|
|
63
|
+
}
|
|
64
|
+
if (sender.kind === "declared" && sender.name) {
|
|
65
|
+
return path.join(UNATTRIBUTED_DIR, "declared", segment(sender.name) + ".jsonl");
|
|
66
|
+
}
|
|
67
|
+
return path.join(UNATTRIBUTED_DIR, "undeclared", "undeclared.jsonl");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parseLines(text) {
|
|
71
|
+
var out = [];
|
|
72
|
+
var lines = text.split("\n");
|
|
73
|
+
for (var i = 0; i < lines.length; i++) {
|
|
74
|
+
if (!lines[i]) continue;
|
|
75
|
+
try {
|
|
76
|
+
var obj = JSON.parse(lines[i]);
|
|
77
|
+
if (obj && typeof obj === "object" && !Array.isArray(obj)) out.push({ line: lines[i], entry: obj });
|
|
78
|
+
} catch (e) {
|
|
79
|
+
// A torn final line after a crash, or a damaged one: not readable, skipped.
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function tsOf(entry) {
|
|
86
|
+
var ms = typeof entry.ts === "string" ? Date.parse(entry.ts) : NaN;
|
|
87
|
+
return isFinite(ms) ? ms : null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function errorText(e) {
|
|
91
|
+
return e && e.message ? e.message : String(e);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// A ledger path that is not there holds no entries; any other failure to read
|
|
95
|
+
// it (permissions, a file where a directory belongs, I/O) is an error the
|
|
96
|
+
// reader must report, never an empty list that looks like "nothing was sent".
|
|
97
|
+
function isAbsent(e) {
|
|
98
|
+
return !!e && e.code === "ENOENT";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function unreadable(file, e) {
|
|
102
|
+
var err = new Error("the outbound ledger cannot be read: " + file + " (" + ((e && e.code) || errorText(e)) + ")");
|
|
103
|
+
err.code = (e && e.code) || "EIO";
|
|
104
|
+
err.path = file;
|
|
105
|
+
return err;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// opts:
|
|
109
|
+
// getBaseDir() the console data directory (read at use)
|
|
110
|
+
// getRetentionDays() the configured value, or undefined (read at use, so a
|
|
111
|
+
// change in daemon.json applies without a restart)
|
|
112
|
+
// now() ms clock (default Date.now), for tests
|
|
113
|
+
// log console-like (default console)
|
|
114
|
+
function createOutboundLedger(opts) {
|
|
115
|
+
var getBaseDir = opts.getBaseDir;
|
|
116
|
+
var getRetentionDays = opts.getRetentionDays || function () { return undefined; };
|
|
117
|
+
var now = opts.now || Date.now;
|
|
118
|
+
var log = opts.log || console;
|
|
119
|
+
var timer = null;
|
|
120
|
+
var warnedInvalid = null;
|
|
121
|
+
|
|
122
|
+
function root() {
|
|
123
|
+
return path.join(getBaseDir(), DIR_NAME);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function retentionDays() {
|
|
127
|
+
var raw = getRetentionDays();
|
|
128
|
+
var r = retentionDaysFrom(raw);
|
|
129
|
+
if (r.invalid && warnedInvalid !== JSON.stringify(raw)) {
|
|
130
|
+
warnedInvalid = JSON.stringify(raw);
|
|
131
|
+
log.warn("[outbound-ledger] outboundRetentionDays must be a whole number of days from 0 to " + MAX_RETENTION_DAYS + "; using " + DEFAULT_RETENTION_DAYS);
|
|
132
|
+
}
|
|
133
|
+
return r.days;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Appends one entry. Never throws: the request it describes is already
|
|
137
|
+
// decided, and a ledger that cannot be written must not change that.
|
|
138
|
+
function record(entry) {
|
|
139
|
+
try {
|
|
140
|
+
if (retentionDays() === 0) return false;
|
|
141
|
+
var file = path.join(root(), relativePathFor(entry));
|
|
142
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
143
|
+
fs.appendFileSync(file, JSON.stringify(entry) + "\n", { mode: 0o600 });
|
|
144
|
+
return true;
|
|
145
|
+
} catch (e) {
|
|
146
|
+
log.error("[outbound-ledger] could not write the entry:", errorText(e));
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// The ledger files under a subdirectory: [{ file, dir }] (dir is the
|
|
152
|
+
// component under it, the project or the unattributed kind). A directory that
|
|
153
|
+
// is absent has none; one that cannot be read throws (see unreadable()).
|
|
154
|
+
function filesUnder(sub, onlyDir) {
|
|
155
|
+
var base = path.join(root(), sub);
|
|
156
|
+
var dirs;
|
|
157
|
+
try { dirs = fs.readdirSync(base); } catch (e) {
|
|
158
|
+
if (isAbsent(e)) return [];
|
|
159
|
+
throw unreadable(base, e);
|
|
160
|
+
}
|
|
161
|
+
var out = [];
|
|
162
|
+
dirs.forEach(function (d) {
|
|
163
|
+
if (onlyDir !== undefined && d !== onlyDir) return;
|
|
164
|
+
var names;
|
|
165
|
+
// Absent here means a prune removed the directory after the listing above.
|
|
166
|
+
try { names = fs.readdirSync(path.join(base, d)); } catch (e) {
|
|
167
|
+
if (isAbsent(e)) return;
|
|
168
|
+
throw unreadable(path.join(base, d), e);
|
|
169
|
+
}
|
|
170
|
+
names.forEach(function (n) {
|
|
171
|
+
if (n.endsWith(".jsonl")) out.push({ file: path.join(base, d, n), dir: d });
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Entries at or after sinceMs and within the retention, oldest first.
|
|
178
|
+
// A file last written before the cut-off holds nothing newer and is not read.
|
|
179
|
+
// Throws (see unreadable()) when a file that exists cannot be read.
|
|
180
|
+
function readFiles(files, sinceMs) {
|
|
181
|
+
var days = retentionDays();
|
|
182
|
+
if (days === 0) return [];
|
|
183
|
+
var cutoff = Math.max(typeof sinceMs === "number" ? sinceMs : 0, now() - days * DAY_MS);
|
|
184
|
+
var out = [];
|
|
185
|
+
files.forEach(function (f) {
|
|
186
|
+
var text;
|
|
187
|
+
try {
|
|
188
|
+
if (fs.statSync(f.file).mtimeMs < cutoff) return;
|
|
189
|
+
text = fs.readFileSync(f.file, "utf8");
|
|
190
|
+
} catch (e) {
|
|
191
|
+
// Absent: pruned between the listing and this read.
|
|
192
|
+
if (isAbsent(e)) return;
|
|
193
|
+
log.error("[outbound-ledger] could not read " + path.basename(f.file) + ":", errorText(e));
|
|
194
|
+
throw unreadable(f.file, e);
|
|
195
|
+
}
|
|
196
|
+
parseLines(text).forEach(function (l) {
|
|
197
|
+
var ts = tsOf(l.entry);
|
|
198
|
+
if (ts !== null && ts >= cutoff) out.push(l.entry);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
out.sort(function (a, b) { return tsOf(a) - tsOf(b); });
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Entries of identified senders, optionally of one project.
|
|
206
|
+
function readAttributed(query) {
|
|
207
|
+
query = query || {};
|
|
208
|
+
var only = query.project === undefined ? undefined : segment(query.project);
|
|
209
|
+
return readFiles(filesUnder(SENDER_DIR, only), query.sinceMs);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Entries of senders that only named themselves, or nobody.
|
|
213
|
+
function readUnattributed(query) {
|
|
214
|
+
query = query || {};
|
|
215
|
+
return readFiles(filesUnder(UNATTRIBUTED_DIR), query.sinceMs);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Rewrites a file without its expired lines, through a temporary file and a
|
|
219
|
+
// rename; removes it when nothing is left. Returns the number of lines dropped.
|
|
220
|
+
function pruneFile(file, cutoff) {
|
|
221
|
+
var text = fs.readFileSync(file, "utf8");
|
|
222
|
+
var all = text.split("\n").filter(function (l) { return l; });
|
|
223
|
+
var kept = parseLines(text).filter(function (l) {
|
|
224
|
+
var ts = tsOf(l.entry);
|
|
225
|
+
return ts !== null && ts >= cutoff;
|
|
226
|
+
});
|
|
227
|
+
if (kept.length === all.length) return 0;
|
|
228
|
+
if (!kept.length) {
|
|
229
|
+
fs.unlinkSync(file);
|
|
230
|
+
return all.length;
|
|
231
|
+
}
|
|
232
|
+
var tmp = file + ".tmp";
|
|
233
|
+
fs.writeFileSync(tmp, kept.map(function (l) { return l.line; }).join("\n") + "\n", { mode: 0o600 });
|
|
234
|
+
fs.renameSync(tmp, file);
|
|
235
|
+
return all.length - kept.length;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ENOTEMPTY (a file is still there) and ENOENT (already gone) are expected;
|
|
239
|
+
// anything else is logged once per path and errno.
|
|
240
|
+
var warnedRmdir = new Set();
|
|
241
|
+
function removeIfEmpty(dir) {
|
|
242
|
+
try { fs.rmdirSync(dir); } catch (e) {
|
|
243
|
+
if (e && (e.code === "ENOTEMPTY" || e.code === "ENOENT")) return;
|
|
244
|
+
var key = dir + "|" + (e && e.code);
|
|
245
|
+
if (warnedRmdir.has(key)) return;
|
|
246
|
+
warnedRmdir.add(key);
|
|
247
|
+
log.error("[outbound-ledger] could not remove the directory " + dir + " (" + ((e && e.code) || errorText(e)) + ")");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Removes every entry older than the retention. Synchronous end to end, so no
|
|
252
|
+
// append interleaves with a rewrite. Returns { files, removed }.
|
|
253
|
+
function prune() {
|
|
254
|
+
var cutoff = now() - retentionDays() * DAY_MS;
|
|
255
|
+
var removed = 0;
|
|
256
|
+
var files = 0;
|
|
257
|
+
[SENDER_DIR, UNATTRIBUTED_DIR].forEach(function (sub) {
|
|
258
|
+
filesUnder(sub).forEach(function (f) {
|
|
259
|
+
try {
|
|
260
|
+
var n = pruneFile(f.file, cutoff);
|
|
261
|
+
if (n) { removed += n; files++; }
|
|
262
|
+
// An emptied directory is removed; one still holding files is left.
|
|
263
|
+
removeIfEmpty(path.dirname(f.file));
|
|
264
|
+
} catch (e) {
|
|
265
|
+
log.error("[outbound-ledger] could not prune " + path.basename(f.file) + ":", errorText(e));
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
if (removed) log.log("[outbound-ledger] pruned " + removed + " expired entr" + (removed === 1 ? "y" : "ies") + " from " + files + " file(s)");
|
|
270
|
+
return { files: files, removed: removed };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Prunes now and then every few hours. The timer never keeps the process up.
|
|
274
|
+
function start() {
|
|
275
|
+
try { prune(); } catch (e) { log.error("[outbound-ledger] prune failed:", errorText(e)); }
|
|
276
|
+
if (timer) return;
|
|
277
|
+
timer = setInterval(function () {
|
|
278
|
+
try { prune(); } catch (e) { log.error("[outbound-ledger] prune failed:", errorText(e)); }
|
|
279
|
+
}, PRUNE_INTERVAL_MS);
|
|
280
|
+
if (typeof timer.unref === "function") timer.unref();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function stop() {
|
|
284
|
+
if (timer) clearInterval(timer);
|
|
285
|
+
timer = null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
record: record,
|
|
290
|
+
readAttributed: readAttributed,
|
|
291
|
+
readUnattributed: readUnattributed,
|
|
292
|
+
prune: prune,
|
|
293
|
+
start: start,
|
|
294
|
+
stop: stop,
|
|
295
|
+
retentionDays: retentionDays,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
module.exports = {
|
|
300
|
+
FORMAT_VERSION: FORMAT_VERSION,
|
|
301
|
+
DIR_NAME: DIR_NAME,
|
|
302
|
+
DEFAULT_RETENTION_DAYS: DEFAULT_RETENTION_DAYS,
|
|
303
|
+
MAX_RETENTION_DAYS: MAX_RETENTION_DAYS,
|
|
304
|
+
retentionDaysFrom: retentionDaysFrom,
|
|
305
|
+
createOutboundLedger: createOutboundLedger,
|
|
306
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// outbound-query.js - the read side of the outbound ledger: what one session
|
|
2
|
+
// sent out through open-session and send-input, for the `list-outbound` verb.
|
|
3
|
+
//
|
|
4
|
+
// Read-only. Returns the outbound calls only (target, prompt, time, initiator,
|
|
5
|
+
// result), never any transcript content. A prompt is returned only when the
|
|
6
|
+
// caller may read the target session (lib/outbound-access.js); otherwise the
|
|
7
|
+
// entry carries its metadata, `prompt: null` and the reason it was withheld.
|
|
8
|
+
// For a target that runs as another OS user the text was never stored (the
|
|
9
|
+
// writer, lib/outbound-entry.js, withholds it), so the entry already carries
|
|
10
|
+
// promptWithheld, contextNoteWithheld and the reason as stored.
|
|
11
|
+
|
|
12
|
+
var { isSafeSessionId } = require("./session-id");
|
|
13
|
+
var { VERB } = require("./outbound-entry");
|
|
14
|
+
|
|
15
|
+
var KIND_TO_VERB = Object.freeze({ sent: VERB.SEND_INPUT, opens: VERB.OPEN_SESSION });
|
|
16
|
+
var KIND_OF_VERB = Object.freeze({ send_input: "sent", open_session: "opens" });
|
|
17
|
+
|
|
18
|
+
function refused(reason) {
|
|
19
|
+
return { ok: false, result: "refused", reason: reason };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// A ledger that cannot be read is an error result, not an empty list.
|
|
23
|
+
function unreadable(err) {
|
|
24
|
+
return { ok: false, result: "error", reason: err && err.message ? err.message : String(err), code: (err && err.code) || null };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function shape(entry, verdict) {
|
|
28
|
+
var out = {};
|
|
29
|
+
for (var k in entry) if (k !== "prompt" && k !== "formatVersion") out[k] = entry[k];
|
|
30
|
+
out.kind = KIND_OF_VERB[entry.verb] || null;
|
|
31
|
+
// The context note is message content the caller wrote alongside the prompt,
|
|
32
|
+
// so it is shown only when the prompt may be. The other free-text fields
|
|
33
|
+
// (reason, sender and target names, addresses) are console-made or are names
|
|
34
|
+
// and addresses, not message content.
|
|
35
|
+
if (!verdict.allowed && typeof entry.contextNote === "string") {
|
|
36
|
+
delete out.contextNote;
|
|
37
|
+
out.contextNoteWithheld = true;
|
|
38
|
+
}
|
|
39
|
+
if (typeof entry.prompt !== "string") {
|
|
40
|
+
out.prompt = null;
|
|
41
|
+
} else if (verdict.allowed) {
|
|
42
|
+
out.prompt = entry.prompt;
|
|
43
|
+
} else {
|
|
44
|
+
out.prompt = null;
|
|
45
|
+
out.promptWithheld = true;
|
|
46
|
+
out.promptWithheldReason = verdict.reason;
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// deps:
|
|
52
|
+
// ledger lib/outbound-ledger.js createOutboundLedger() result
|
|
53
|
+
// access lib/outbound-access.js createOutboundAccess() result
|
|
54
|
+
// caller { user, authenticated } the principal behind this transport
|
|
55
|
+
function createOutboundQuery(deps) {
|
|
56
|
+
var ledger = deps.ledger;
|
|
57
|
+
var access = deps.access;
|
|
58
|
+
var caller = deps.caller;
|
|
59
|
+
|
|
60
|
+
function present(entries) {
|
|
61
|
+
return entries.map(function (e) { return shape(e, access.canReadPrompt(e, caller)); });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// req: { sessionId, projectSlug?, sinceMs?, kind? }
|
|
65
|
+
// sessionId the vendor's own session id of the sender (never a console id)
|
|
66
|
+
// sinceMs only entries at or after this time (epoch ms)
|
|
67
|
+
// kind "sent" (send-input) or "opens" (open-session)
|
|
68
|
+
function list(req) {
|
|
69
|
+
req = req || {};
|
|
70
|
+
if (typeof req.sessionId !== "string" || !isSafeSessionId(req.sessionId)) {
|
|
71
|
+
return refused("a session id is required and must be a plain id (letters, digits, _ and -)");
|
|
72
|
+
}
|
|
73
|
+
// A console id is renumbered at a daemon restart, so one number can name
|
|
74
|
+
// different sessions over the ledger's retention; it is never an identity.
|
|
75
|
+
if (/^[0-9]+$/.test(req.sessionId)) {
|
|
76
|
+
return refused("--session takes the vendor session id, not a console id: console ids are renumbered when the daemon restarts, so one can name different sessions over time. The vendor id is shown by list-sessions (sessionId).");
|
|
77
|
+
}
|
|
78
|
+
if (req.projectSlug !== undefined && (typeof req.projectSlug !== "string" || !req.projectSlug)) {
|
|
79
|
+
return refused("project must be a non-empty string");
|
|
80
|
+
}
|
|
81
|
+
if (req.sinceMs !== undefined && !(typeof req.sinceMs === "number" && isFinite(req.sinceMs))) {
|
|
82
|
+
return refused("since must be a time");
|
|
83
|
+
}
|
|
84
|
+
var verb = null;
|
|
85
|
+
if (req.kind !== undefined) {
|
|
86
|
+
verb = Object.prototype.hasOwnProperty.call(KIND_TO_VERB, req.kind) ? KIND_TO_VERB[req.kind] : null;
|
|
87
|
+
if (!verb) return refused("unknown kind " + JSON.stringify(String(req.kind).slice(0, 32)) + " (accepted: sent, opens)");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
var days = ledger.retentionDays();
|
|
91
|
+
var base = { ok: true, result: "listed", retentionDays: days };
|
|
92
|
+
if (days === 0) {
|
|
93
|
+
return Object.assign(base, { count: 0, messages: [], unattributed: [], note: "the outbound ledger is turned off (outboundRetentionDays is 0)" });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
var id = req.sessionId;
|
|
97
|
+
var mine;
|
|
98
|
+
try {
|
|
99
|
+
mine = ledger.readAttributed({ project: req.projectSlug, sinceMs: req.sinceMs }).filter(function (e) {
|
|
100
|
+
return (e.sender || {}).cliSessionId === id;
|
|
101
|
+
});
|
|
102
|
+
} catch (e) {
|
|
103
|
+
return unreadable(e);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Vendor ids are unique, but a ledger written by hand or by an older
|
|
107
|
+
// writer could repeat one across projects; never merge those silently.
|
|
108
|
+
// A Set, not an object: a slug such as __proto__ must count as a key.
|
|
109
|
+
var projects = new Set();
|
|
110
|
+
mine.forEach(function (e) { projects.add(e.sender.project); });
|
|
111
|
+
var projectNames = Array.from(projects);
|
|
112
|
+
if (projectNames.length > 1) {
|
|
113
|
+
return {
|
|
114
|
+
ok: false,
|
|
115
|
+
result: "ambiguous",
|
|
116
|
+
reason: "the session id " + JSON.stringify(id) + " names a sender in " + projectNames.length + " projects; send again with --project",
|
|
117
|
+
projects: projectNames.sort(),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// The vendor ids this sender has used, to find calls that only named it.
|
|
122
|
+
var vendorIds = new Set([id]);
|
|
123
|
+
mine.forEach(function (e) { if (e.sender.cliSessionId) vendorIds.add(e.sender.cliSessionId); });
|
|
124
|
+
|
|
125
|
+
// Self-reported: a declared sender names the session it claims to be. Kept
|
|
126
|
+
// apart and labelled, never merged into the identified senders' list.
|
|
127
|
+
var claimed;
|
|
128
|
+
try {
|
|
129
|
+
claimed = ledger.readUnattributed({ sinceMs: req.sinceMs }).filter(function (e) {
|
|
130
|
+
return e.sender && typeof e.sender.fromSession === "string" && vendorIds.has(e.sender.fromSession);
|
|
131
|
+
});
|
|
132
|
+
} catch (e) {
|
|
133
|
+
return unreadable(e);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function wanted(e) { return !verb || e.verb === verb; }
|
|
137
|
+
var messages = mine.filter(wanted);
|
|
138
|
+
var unattributed = claimed.filter(wanted);
|
|
139
|
+
|
|
140
|
+
return Object.assign(base, {
|
|
141
|
+
session: { id: id, project: projectNames[0] || req.projectSlug || null },
|
|
142
|
+
count: messages.length,
|
|
143
|
+
messages: present(messages),
|
|
144
|
+
unattributedCount: unattributed.length,
|
|
145
|
+
unattributed: present(unattributed),
|
|
146
|
+
unattributedNote: "Calls whose sender only named itself (--from-session). The console cannot verify them; they are listed so they are not lost, not as this session's own calls.",
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return { list: list };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = { createOutboundQuery: createOutboundQuery, KIND_TO_VERB: KIND_TO_VERB };
|
package/lib/pending-prompts.js
CHANGED
|
@@ -24,11 +24,9 @@ function ageSeconds(createdAt, now) {
|
|
|
24
24
|
return Math.max(0, Math.floor((now - createdAt) / 1000));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
function pendingPrompts(session, now) {
|
|
31
|
-
var out = [];
|
|
27
|
+
// Calls visit(id, record, kind) for every operator-facing prompt (kind.journal,
|
|
28
|
+
// the ones a banner is raised for) a session holds in the registry's maps.
|
|
29
|
+
function eachPending(session, visit) {
|
|
32
30
|
STORES.forEach(function (store) {
|
|
33
31
|
var map = session && session[store];
|
|
34
32
|
if (!map) return;
|
|
@@ -37,19 +35,36 @@ function pendingPrompts(session, now) {
|
|
|
37
35
|
if (!record) return;
|
|
38
36
|
var kind = promptKinds.kindOfRecord(record, store);
|
|
39
37
|
if (!kind || !kind.journal) return;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
visit(id, record, kind);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// How many operator prompts the session waits on. Cheap: no summary is built,
|
|
44
|
+
// so the session list can ask it of every session on every broadcast.
|
|
45
|
+
function countPending(session) {
|
|
46
|
+
var n = 0;
|
|
47
|
+
eachPending(session, function () { n += 1; });
|
|
48
|
+
return n;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Returns [{ requestId, kind, tool, summary, ageSeconds }], oldest first;
|
|
52
|
+
// empty when the session waits on nothing.
|
|
53
|
+
function pendingPrompts(session, now) {
|
|
54
|
+
var out = [];
|
|
55
|
+
eachPending(session, function (id, record, kind) {
|
|
56
|
+
out.push({
|
|
57
|
+
createdAt: typeof record.createdAt === "number" ? record.createdAt : 0,
|
|
58
|
+
view: {
|
|
59
|
+
requestId: id,
|
|
60
|
+
kind: kind.name,
|
|
61
|
+
tool: typeof record.toolName === "string" ? record.toolName : null,
|
|
62
|
+
summary: TOOL_KINDS[kind.name] ? summarize(record.toolName, record.toolInput) : "",
|
|
63
|
+
ageSeconds: ageSeconds(record.createdAt, now),
|
|
64
|
+
},
|
|
50
65
|
});
|
|
51
66
|
});
|
|
52
67
|
return out.sort(function (a, b) { return a.createdAt - b.createdAt; }).map(function (e) { return e.view; });
|
|
53
68
|
}
|
|
54
69
|
|
|
55
|
-
module.exports = { pendingPrompts: pendingPrompts };
|
|
70
|
+
module.exports = { pendingPrompts: pendingPrompts, countPending: countPending };
|
|
@@ -5,11 +5,17 @@ var userPresence = require("./user-presence");
|
|
|
5
5
|
var { authOf } = require("./project-access");
|
|
6
6
|
var { getCodexConfig } = require("./codex-defaults");
|
|
7
7
|
var { promptsFor } = require("./prompt-registry");
|
|
8
|
+
var { snapshotLivePrompts } = require("./notify/live-prompts");
|
|
8
9
|
var { settingsMessage } = require("./permission-settings");
|
|
10
|
+
var userShellSettings = require("./user-shell-settings");
|
|
11
|
+
var { rosterMessage, callerOf } = require("./agent-roster-ws");
|
|
9
12
|
var { effectiveSessionMode } = require("./sessions");
|
|
10
13
|
var sessionReclaim = require("./session-reclaim");
|
|
11
14
|
var clientBuildId = require("./client-build-id");
|
|
12
15
|
var { buildVendorRegistryMessage } = require("./vendor-registry-message");
|
|
16
|
+
var { logField } = require("./log-field");
|
|
17
|
+
var { clientIdOf } = require("./prompt-source");
|
|
18
|
+
var openSockets = require("./open-sockets");
|
|
13
19
|
// detectLite is cached per-project in project.js and passed via ctx.liteStatus.
|
|
14
20
|
// This import is retained only for backward compat if ctx.liteStatus is absent.
|
|
15
21
|
var { detectLite } = require("./lite-detect");
|
|
@@ -175,21 +181,27 @@ function attachConnection(ctx) {
|
|
|
175
181
|
if (typeof opts.onGetPermissionSettings === "function") {
|
|
176
182
|
sendTo(ws, settingsMessage(opts.onGetPermissionSettings()));
|
|
177
183
|
}
|
|
184
|
+
if (typeof opts.onGetUserShellSettings === "function") {
|
|
185
|
+
sendTo(ws, userShellSettings.settingsMessage(opts.onGetUserShellSettings()));
|
|
186
|
+
}
|
|
187
|
+
// Every client holds the roster's avatar choices from the start: a transcript
|
|
188
|
+
// draws agents before the Team view is ever opened.
|
|
189
|
+
// The roster is filtered to what this connection may read, as on request.
|
|
190
|
+
if (opts.agentRoster) sendTo(ws, rosterMessage(opts.agentRoster, callerOf(ws)));
|
|
178
191
|
sendTo(ws, { type: "term_list", terminals: tm.list(ws) });
|
|
179
192
|
// Context sources sent after session is resolved (per-session storage)
|
|
180
193
|
sendTo(ws, { type: "notes_list", notes: nm.list() });
|
|
181
194
|
sendTo(ws, { type: "loop_registry_updated", records: getHubSchedules(_userId, authOf(ws)) });
|
|
182
195
|
_loop.sendConnectionState(ws);
|
|
183
196
|
if (_mcp) _mcp.sendConnectionState(ws);
|
|
184
|
-
if (_notifications)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
197
|
+
if (_notifications) {
|
|
198
|
+
_notifications.sendConnectionState(ws, sendTo, snapshotLivePrompts({
|
|
199
|
+
slug: slug,
|
|
200
|
+
sessions: sm.sessions,
|
|
201
|
+
prompts: promptsFor(sm),
|
|
202
|
+
viewerId: wsUser ? wsUser.id : null,
|
|
203
|
+
}));
|
|
191
204
|
}
|
|
192
|
-
|
|
193
205
|
// Session list (filtered for access control)
|
|
194
206
|
// Use the canonical mapper from sessions.js
|
|
195
207
|
var activeId = restoredActive ? restoredActive.localId : sm.activeSessionId;
|
|
@@ -306,6 +318,16 @@ function attachConnection(ctx) {
|
|
|
306
318
|
}
|
|
307
319
|
broadcastPresence();
|
|
308
320
|
|
|
321
|
+
// One journal line per socket, so a tab holding more than one is visible
|
|
322
|
+
// from the daemon. Identifiers only: never the ticket, cookies, headers or
|
|
323
|
+
// remote address. The client id is the same label prompt sources carry.
|
|
324
|
+
ws._clagenticConnectedAt = Date.now();
|
|
325
|
+
openSockets.opened(slug);
|
|
326
|
+
console.log("[connection] connect: project=" + logField(slug)
|
|
327
|
+
+ " client=" + logField(clientIdOf(ws))
|
|
328
|
+
+ " user=" + logField(_userId)
|
|
329
|
+
+ " session=" + logField(ws._clagenticActiveSession));
|
|
330
|
+
|
|
309
331
|
ws.on("message", function (raw) {
|
|
310
332
|
var msg;
|
|
311
333
|
try { msg = JSON.parse(raw.toString()); } catch (e) { return; }
|
|
@@ -329,7 +351,24 @@ function attachConnection(ctx) {
|
|
|
329
351
|
});
|
|
330
352
|
}
|
|
331
353
|
|
|
354
|
+
// Logs the disconnect and leaves the open-socket count, once per socket, so
|
|
355
|
+
// a repeated close cannot drive the count below the truth. Project destroy
|
|
356
|
+
// calls it too: its ws.close() only starts the handshake, and the close
|
|
357
|
+
// event can arrive long after the project is gone.
|
|
358
|
+
function recordDisconnect(ws) {
|
|
359
|
+
if (!ws._clagenticConnectedAt) return;
|
|
360
|
+
var _seconds = Math.round((Date.now() - ws._clagenticConnectedAt) / 1000);
|
|
361
|
+
ws._clagenticConnectedAt = 0;
|
|
362
|
+
openSockets.closed(slug);
|
|
363
|
+
console.log("[connection] disconnect: project=" + logField(slug)
|
|
364
|
+
+ " client=" + logField(clientIdOf(ws))
|
|
365
|
+
+ " user=" + logField(ws._clagenticUser ? ws._clagenticUser.id : null)
|
|
366
|
+
+ " session=" + logField(ws._clagenticActiveSession)
|
|
367
|
+
+ " duration_s=" + _seconds);
|
|
368
|
+
}
|
|
369
|
+
|
|
332
370
|
function handleDisconnection(ws) {
|
|
371
|
+
recordDisconnect(ws);
|
|
333
372
|
if (ws._clagenticActiveSession) {
|
|
334
373
|
var dcPresKey = ws._clagenticUser ? ws._clagenticUser.id : "_default";
|
|
335
374
|
var dcExisting = userPresence.getPresence(slug, dcPresKey);
|
|
@@ -347,6 +386,7 @@ function attachConnection(ctx) {
|
|
|
347
386
|
return {
|
|
348
387
|
handleConnection: handleConnection,
|
|
349
388
|
handleDisconnection: handleDisconnection,
|
|
389
|
+
recordDisconnect: recordDisconnect,
|
|
350
390
|
};
|
|
351
391
|
}
|
|
352
392
|
|