@clagentic/console 1.11.0 → 1.12.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/bin/cli.js +14 -2
- package/lib/build-changes.js +8 -2
- package/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +31 -7
- package/lib/claude-settings-env.js +142 -0
- package/lib/cli/arg-validation.js +1 -1
- package/lib/cli/duration.js +27 -0
- package/lib/cli/ipc-subcommands.js +26 -0
- package/lib/cli/schedule-input-subcommands.js +1 -22
- package/lib/cli/session-subcommands.js +38 -7
- package/lib/daemon.js +26 -0
- package/lib/notification-prefs.js +257 -0
- package/lib/notify/core.js +175 -0
- package/lib/notify/index.js +31 -0
- package/lib/notify/live-prompts.js +36 -0
- package/lib/notify/payload.js +63 -0
- package/lib/notify/target.js +5 -0
- package/lib/notify/type-registry.js +64 -0
- package/lib/notify/types.js +20 -0
- package/lib/open-sockets.js +27 -0
- package/lib/outbound-access.js +74 -0
- package/lib/outbound-entry.js +109 -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 +40 -1
- package/lib/project-filesystem.js +20 -5
- package/lib/project-http.js +9 -1
- package/lib/project-loop.js +25 -13
- package/lib/project-notifications.js +206 -42
- package/lib/project-prompt-responses.js +1 -1
- package/lib/project-sessions.js +30 -1
- package/lib/project.js +15 -1
- package/lib/prompt-registry.js +92 -24
- package/lib/prompt-reminders.js +282 -0
- package/lib/prompt-source.js +43 -8
- package/lib/public/app.js +1 -0
- package/lib/public/css/diagnostics.css +28 -0
- package/lib/public/css/home-hub.css +12 -0
- package/lib/public/css/icon-strip.css +9 -0
- package/lib/public/css/input.css +93 -0
- package/lib/public/css/menus.css +22 -0
- package/lib/public/css/mobile-nav.css +11 -0
- package/lib/public/css/server-settings.css +24 -0
- package/lib/public/css/sidebar.css +24 -0
- package/lib/public/index.html +6 -0
- package/lib/public/modules/activity-state.js +20 -4
- package/lib/public/modules/app-connection.js +22 -5
- package/lib/public/modules/app-header.js +2 -0
- package/lib/public/modules/app-messages.js +6 -2
- package/lib/public/modules/app-notifications.js +65 -40
- package/lib/public/modules/app-projects.js +3 -1
- package/lib/public/modules/app-rate-limit.js +12 -6
- package/lib/public/modules/app-rendering.js +26 -3
- package/lib/public/modules/build-update-sessions.js +81 -0
- package/lib/public/modules/collapsible-text.js +77 -0
- package/lib/public/modules/diagnostics.js +9 -2
- package/lib/public/modules/env-shadow-notice.js +34 -0
- package/lib/public/modules/keep-alive.js +66 -0
- package/lib/public/modules/notification-prefs.js +151 -0
- package/lib/public/modules/notify-client.js +153 -0
- package/lib/public/modules/project-settings.js +5 -0
- package/lib/public/modules/prompt-reminders-setting.js +13 -0
- package/lib/public/modules/prompt-state.js +3 -3
- package/lib/public/modules/prompts.js +1 -1
- package/lib/public/modules/server-settings.js +3 -0
- package/lib/public/modules/sidebar-mobile.js +8 -0
- package/lib/public/modules/sidebar-sessions.js +27 -0
- package/lib/public/modules/terminal-links.js +175 -0
- package/lib/public/modules/terminal.js +19 -103
- package/lib/public/notify-sw-logic.js +300 -0
- package/lib/public/notify-target.js +97 -0
- package/lib/public/sw.js +15 -62
- package/lib/push-audience.js +84 -0
- package/lib/push.js +87 -20
- package/lib/runtime-env.js +1 -0
- package/lib/sdk-bridge.js +83 -36
- package/lib/sdk-message-processor.js +148 -49
- package/lib/sender-ref.js +3 -0
- package/lib/server.js +80 -4
- package/lib/session-directory.js +6 -4
- package/lib/session-input-ipc.js +11 -1
- package/lib/session-input.js +95 -14
- package/lib/session-liveness.js +53 -0
- package/lib/session-reclaim.js +37 -2
- package/lib/sessions.js +58 -4
- package/lib/usage-store.js +403 -0
- package/lib/vendor-auth.js +33 -2
- package/lib/ws-schema.js +13 -2
- package/lib/yoke/adapters/claude-vendor.js +11 -1
- package/lib/yoke/adapters/claude.js +17 -0
- package/lib/yoke/adapters/codex.js +5 -1
- package/lib/yoke/auth-checks.js +17 -2
- package/lib/yoke/index.js +21 -3
- package/lib/yoke/provider-credentials.js +24 -0
- package/lib/yoke/registry.js +8 -1
- package/package.json +2 -2
- package/scripts/check-test-count.js +14 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
// usage-store.js — last-seen account usage per (vendor, bucket).
|
|
2
|
+
//
|
|
3
|
+
// Vendor-neutral: a bucket is whatever string the adapter reports as
|
|
4
|
+
// rateLimitType, kept verbatim. Records live in memory and, when a file is
|
|
5
|
+
// configured (the daemon's shared instance), are persisted to JSON and reloaded
|
|
6
|
+
// at start. Freshness is computed at read time and never stored, so a reloaded
|
|
7
|
+
// record reads stale/expired honestly and is never re-stamped as fresh.
|
|
8
|
+
//
|
|
9
|
+
// Two timestamps per bucket: observedAt (the last reported event, i.e. the last
|
|
10
|
+
// time the value changed) and confirmedAt (the last evidence the value still
|
|
11
|
+
// holds). Some adapters report only on change, so a steady value goes silent
|
|
12
|
+
// while sessions keep running; confirm() lets the caller say "a session whose
|
|
13
|
+
// process has already reported just completed a turn without a change". Age and
|
|
14
|
+
// state are computed from the newer of the two.
|
|
15
|
+
|
|
16
|
+
var fsDefault = require("fs");
|
|
17
|
+
var pathMod = require("path");
|
|
18
|
+
var { readConsoleEnv } = require("./env-compat");
|
|
19
|
+
|
|
20
|
+
var DEFAULT_STALE_SECONDS = 30 * 60;
|
|
21
|
+
// Buckets listed as "unknown" for every registered vendor even when unseen.
|
|
22
|
+
var ALWAYS_LISTED_BUCKETS = ["five_hour", "seven_day"];
|
|
23
|
+
var DEFAULT_THROTTLE_MS = 5000;
|
|
24
|
+
var STORE_FILE_NAME = "usage-store.json";
|
|
25
|
+
var STORE_FILE_VERSION = 1;
|
|
26
|
+
|
|
27
|
+
function staleAfterSeconds(env) {
|
|
28
|
+
var raw = readConsoleEnv("CLAGENTIC_CONSOLE_USAGE_STALE_SECONDS", { env: env });
|
|
29
|
+
var n = raw === undefined ? NaN : Number(raw);
|
|
30
|
+
return isFinite(n) && n > 0 ? n : DEFAULT_STALE_SECONDS;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function toIso(ms) {
|
|
34
|
+
return new Date(ms).toISOString();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isIsoOrNull(v) {
|
|
38
|
+
return v === null || (typeof v === "string" && isFinite(Date.parse(v)));
|
|
39
|
+
}
|
|
40
|
+
function isStrOrNull(v) {
|
|
41
|
+
return v === null || typeof v === "string";
|
|
42
|
+
}
|
|
43
|
+
// Session ids arrive as numbers from the session layer and as strings from
|
|
44
|
+
// older files; both are stored as strings, which is also how confirm() and
|
|
45
|
+
// endProcess() key them. Anything else is not an id.
|
|
46
|
+
function idOrNull(v) {
|
|
47
|
+
if (typeof v === "string") return v;
|
|
48
|
+
if (typeof v === "number" && isFinite(v)) return String(v);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function strOrNull(v) {
|
|
52
|
+
return typeof v === "string" ? v : null;
|
|
53
|
+
}
|
|
54
|
+
function finiteOrNull(v) {
|
|
55
|
+
return typeof v === "number" && isFinite(v) ? v : null;
|
|
56
|
+
}
|
|
57
|
+
// Epoch seconds to ISO, or null when the value is not a representable time.
|
|
58
|
+
function epochSecondsToIsoOrNull(sec) {
|
|
59
|
+
if (typeof sec !== "number" || !isFinite(sec) || sec === 0) return null;
|
|
60
|
+
var ms = sec * 1000;
|
|
61
|
+
return isFinite(new Date(ms).getTime()) ? toIso(ms) : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Vendor and bucket names come from persisted JSON and CLI output, so they are
|
|
65
|
+
// untrusted. Internal maps have no prototype (a name like "constructor" or
|
|
66
|
+
// "toString" cannot resolve to an inherited member) and "__proto__" is refused
|
|
67
|
+
// outright because the snapshot output objects are plain.
|
|
68
|
+
function newMap() {
|
|
69
|
+
return Object.create(null);
|
|
70
|
+
}
|
|
71
|
+
function isUnsafeKey(k) {
|
|
72
|
+
return k === "__proto__";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Returns a normalised record, or null when the stored one is malformed.
|
|
76
|
+
function validRecord(r) {
|
|
77
|
+
if (!r || typeof r !== "object" || Array.isArray(r)) return null;
|
|
78
|
+
if (typeof r.observedAt !== "string" || !isFinite(Date.parse(r.observedAt))) return null;
|
|
79
|
+
if (!(r.utilization === null || (typeof r.utilization === "number" && isFinite(r.utilization)))) return null;
|
|
80
|
+
if (!isIsoOrNull(r.utilizationObservedAt) || !isIsoOrNull(r.resetsAt)) return null;
|
|
81
|
+
if (!isStrOrNull(r.status) || !isStrOrNull(r.source)) return null;
|
|
82
|
+
var sessionLocalId = r.sessionLocalId === undefined ? null : r.sessionLocalId;
|
|
83
|
+
if (sessionLocalId !== null && idOrNull(sessionLocalId) === null) return null;
|
|
84
|
+
// confirmedAt is absent in files written before confirmation existed.
|
|
85
|
+
var confirmedAt = r.confirmedAt === undefined ? null : r.confirmedAt;
|
|
86
|
+
if (!isIsoOrNull(confirmedAt)) return null;
|
|
87
|
+
return {
|
|
88
|
+
utilization: r.utilization,
|
|
89
|
+
utilizationObservedAt: r.utilizationObservedAt,
|
|
90
|
+
resetsAt: r.resetsAt,
|
|
91
|
+
status: r.status,
|
|
92
|
+
observedAt: r.observedAt,
|
|
93
|
+
confirmedAt: confirmedAt,
|
|
94
|
+
source: r.source,
|
|
95
|
+
sessionLocalId: idOrNull(sessionLocalId),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function newestMs(rec) {
|
|
100
|
+
var o = Date.parse(rec.observedAt);
|
|
101
|
+
var c = rec.confirmedAt ? Date.parse(rec.confirmedAt) : -Infinity;
|
|
102
|
+
return Math.max(o, c);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// opts (all optional; no file means no I/O):
|
|
106
|
+
// file persistence path
|
|
107
|
+
// fs fs implementation (tests)
|
|
108
|
+
// log function(message), defaults to console.log
|
|
109
|
+
// throttleMs minimum spacing between writes
|
|
110
|
+
function createUsageStore(opts) {
|
|
111
|
+
opts = opts || {};
|
|
112
|
+
var file = opts.file || null;
|
|
113
|
+
var fsImpl = opts.fs || fsDefault;
|
|
114
|
+
var log = opts.log || function (m) { console.log(m); };
|
|
115
|
+
var throttleMs = opts.throttleMs !== undefined ? opts.throttleMs : DEFAULT_THROTTLE_MS;
|
|
116
|
+
var timer = null;
|
|
117
|
+
var dirty = false;
|
|
118
|
+
// vendor -> bucket -> record
|
|
119
|
+
var records = newMap();
|
|
120
|
+
// vendor -> session id -> { proc, bucket }: the bucket the session's current
|
|
121
|
+
// process last reported. In memory only; a process never outlives the daemon.
|
|
122
|
+
var emitters = newMap();
|
|
123
|
+
// vendors that produced any evidence since this store was created (not
|
|
124
|
+
// counting records loaded from the file)
|
|
125
|
+
var seenThisRun = newMap();
|
|
126
|
+
|
|
127
|
+
// dirty is cleared only once both the tmp write and the rename succeed, so a
|
|
128
|
+
// transient failure (ENOSPC, EACCES) leaves the change pending. A failed
|
|
129
|
+
// write schedules a retry through the same throttle timer, which bounds
|
|
130
|
+
// retries to one per throttle interval.
|
|
131
|
+
function writeNow() {
|
|
132
|
+
if (!file) return;
|
|
133
|
+
var tmp = file + ".tmp";
|
|
134
|
+
try {
|
|
135
|
+
fsImpl.mkdirSync(pathMod.dirname(file), { recursive: true, mode: 0o700 });
|
|
136
|
+
fsImpl.writeFileSync(tmp, JSON.stringify({ version: STORE_FILE_VERSION, vendors: records }), { mode: 0o600 });
|
|
137
|
+
fsImpl.renameSync(tmp, file);
|
|
138
|
+
dirty = false;
|
|
139
|
+
} catch (e) {
|
|
140
|
+
log("[usage-store] Clagentic: Console could not persist usage to " + file + ": " + (e && e.message ? e.message : e));
|
|
141
|
+
try {
|
|
142
|
+
if (typeof fsImpl.unlinkSync === "function") fsImpl.unlinkSync(tmp);
|
|
143
|
+
} catch (u) {
|
|
144
|
+
if (!u || u.code !== "ENOENT") {
|
|
145
|
+
log("[usage-store] Clagentic: Console could not remove " + tmp + ": " + (u && u.message ? u.message : u));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
armTimer();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function armTimer() {
|
|
153
|
+
if (timer) return;
|
|
154
|
+
timer = setTimeout(function () {
|
|
155
|
+
timer = null;
|
|
156
|
+
if (dirty) writeNow();
|
|
157
|
+
}, throttleMs);
|
|
158
|
+
if (timer && typeof timer.unref === "function") timer.unref();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function schedulePersist() {
|
|
162
|
+
if (!file) return;
|
|
163
|
+
dirty = true;
|
|
164
|
+
armTimer();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Write any pending change immediately (daemon shutdown, tests).
|
|
168
|
+
function flush() {
|
|
169
|
+
if (timer) { clearTimeout(timer); timer = null; }
|
|
170
|
+
if (dirty) writeNow();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Replace in-memory records from the file. A missing file is quiet; an
|
|
174
|
+
// unparseable or wrong-shape file is logged and set aside as <file>.corrupt.
|
|
175
|
+
function load() {
|
|
176
|
+
if (!file) return;
|
|
177
|
+
var raw;
|
|
178
|
+
try {
|
|
179
|
+
raw = fsImpl.readFileSync(file, "utf8");
|
|
180
|
+
} catch (e) {
|
|
181
|
+
if (e && e.code === "ENOENT") return;
|
|
182
|
+
log("[usage-store] Clagentic: Console could not read " + file + ", starting empty: " + (e && e.message ? e.message : e));
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
var parsed;
|
|
186
|
+
try { parsed = JSON.parse(raw); } catch (e) { parsed = undefined; }
|
|
187
|
+
var ok = parsed && typeof parsed === "object" && !Array.isArray(parsed) &&
|
|
188
|
+
parsed.vendors && typeof parsed.vendors === "object" && !Array.isArray(parsed.vendors);
|
|
189
|
+
if (!ok) {
|
|
190
|
+
var aside = file + ".corrupt";
|
|
191
|
+
var note = "";
|
|
192
|
+
try { fsImpl.renameSync(file, aside); note = "; kept as " + aside; } catch (e) { note = "; could not move it aside"; }
|
|
193
|
+
log("[usage-store] Clagentic: Console usage file " + file + " is unreadable or has the wrong shape, starting empty" + note);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
var loaded = newMap();
|
|
197
|
+
var dropped = 0;
|
|
198
|
+
Object.keys(parsed.vendors).forEach(function (vendor) {
|
|
199
|
+
var buckets = parsed.vendors[vendor];
|
|
200
|
+
if (isUnsafeKey(vendor)) { dropped++; return; }
|
|
201
|
+
if (!buckets || typeof buckets !== "object" || Array.isArray(buckets)) { dropped++; return; }
|
|
202
|
+
Object.keys(buckets).forEach(function (b) {
|
|
203
|
+
var rec = isUnsafeKey(b) ? null : validRecord(buckets[b]);
|
|
204
|
+
if (!rec) { dropped++; return; }
|
|
205
|
+
(loaded[vendor] || (loaded[vendor] = newMap()))[b] = rec;
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
records = loaded;
|
|
209
|
+
if (dropped > 0) log("[usage-store] Clagentic: Console dropped " + dropped + " malformed usage record(s) from " + file);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// info.resetsAt is epoch seconds, as the adapters report it.
|
|
213
|
+
//
|
|
214
|
+
// meta.processKey (optional) identifies the session's current process; with
|
|
215
|
+
// meta.sessionLocalId it registers the session as an emitter that confirm()
|
|
216
|
+
// may later act for.
|
|
217
|
+
function record(vendor, info, meta) {
|
|
218
|
+
if (!vendor || !info) return;
|
|
219
|
+
if (!info.rateLimitType) {
|
|
220
|
+
log("[usage-store] Clagentic: Console dropped a rate-limit event with no rateLimitType (vendor=" + vendor + " status=" + (info.status || "none") + ")");
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (isUnsafeKey(vendor) || isUnsafeKey(info.rateLimitType)) return;
|
|
224
|
+
meta = meta || {};
|
|
225
|
+
var now = meta.now !== undefined ? meta.now : Date.now();
|
|
226
|
+
var util = finiteOrNull(info.utilization);
|
|
227
|
+
var resetsAt = epochSecondsToIsoOrNull(info.resetsAt);
|
|
228
|
+
var byBucket = records[vendor] || (records[vendor] = newMap());
|
|
229
|
+
var prev = byBucket[info.rateLimitType];
|
|
230
|
+
var utilizationObservedAt = util !== null ? toIso(now) : null;
|
|
231
|
+
|
|
232
|
+
// An event without a utilization must not erase a known one for the same
|
|
233
|
+
// reset window; the old value keeps its own observation time.
|
|
234
|
+
if (util === null && prev && prev.utilization !== null && prev.resetsAt === resetsAt) {
|
|
235
|
+
util = prev.utilization;
|
|
236
|
+
utilizationObservedAt = prev.utilizationObservedAt;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
byBucket[info.rateLimitType] = {
|
|
240
|
+
utilization: util,
|
|
241
|
+
utilizationObservedAt: utilizationObservedAt,
|
|
242
|
+
resetsAt: resetsAt,
|
|
243
|
+
status: strOrNull(info.status) || null,
|
|
244
|
+
observedAt: toIso(now),
|
|
245
|
+
confirmedAt: null,
|
|
246
|
+
source: strOrNull(meta.source) || null,
|
|
247
|
+
sessionLocalId: idOrNull(meta.sessionLocalId) || null,
|
|
248
|
+
};
|
|
249
|
+
seenThisRun[vendor] = true;
|
|
250
|
+
if (meta.processKey && meta.sessionLocalId && !isUnsafeKey(String(meta.sessionLocalId))) {
|
|
251
|
+
var bySession = emitters[vendor] || (emitters[vendor] = newMap());
|
|
252
|
+
bySession[String(meta.sessionLocalId)] = { proc: meta.processKey, bucket: info.rateLimitType };
|
|
253
|
+
}
|
|
254
|
+
schedulePersist();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// A session whose current process has reported at least once completed a
|
|
258
|
+
// turn: the bucket that process last reported still holds. Returns true when
|
|
259
|
+
// a bucket was confirmed. A session that has not reported, or whose process
|
|
260
|
+
// changed, confirms nothing.
|
|
261
|
+
function confirm(vendor, who, meta) {
|
|
262
|
+
if (!vendor || !who || !who.sessionLocalId || isUnsafeKey(vendor) || isUnsafeKey(String(who.sessionLocalId))) return false;
|
|
263
|
+
var entry = emitters[vendor] && emitters[vendor][String(who.sessionLocalId)];
|
|
264
|
+
if (!entry || entry.proc !== who.processKey) return false;
|
|
265
|
+
var rec = records[vendor] && records[vendor][entry.bucket];
|
|
266
|
+
if (!rec) return false;
|
|
267
|
+
var now = meta && meta.now !== undefined ? meta.now : Date.now();
|
|
268
|
+
rec.confirmedAt = toIso(now);
|
|
269
|
+
seenThisRun[vendor] = true;
|
|
270
|
+
schedulePersist();
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// The session's process ended or restarted. With processKey, only that
|
|
275
|
+
// process's entry is cleared, so a newer process of the same session keeps its own.
|
|
276
|
+
function endProcess(vendor, sessionLocalId, processKey) {
|
|
277
|
+
var by = emitters[vendor];
|
|
278
|
+
if (!by || sessionLocalId === undefined || sessionLocalId === null) return;
|
|
279
|
+
var id = String(sessionLocalId);
|
|
280
|
+
if (!by[id]) return;
|
|
281
|
+
if (processKey !== undefined && by[id].proc !== processKey) return;
|
|
282
|
+
delete by[id];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function view(rec, now, staleSec) {
|
|
286
|
+
if (!rec) {
|
|
287
|
+
return { utilization: null, resetsAt: null, status: null, observedAt: null, confirmedAt: null, ageSeconds: null, state: "unknown", source: null, utilizationConfirmed: false };
|
|
288
|
+
}
|
|
289
|
+
var newest = newestMs(rec);
|
|
290
|
+
var ageSeconds = Math.max(0, Math.round((now - newest) / 1000));
|
|
291
|
+
var state = "fresh";
|
|
292
|
+
if (rec.resetsAt && Date.parse(rec.resetsAt) <= now) state = "expired";
|
|
293
|
+
else if (ageSeconds > staleSec) state = "stale";
|
|
294
|
+
// The adapter's change test covers utilization, so a confirmation also
|
|
295
|
+
// confirms it, but only when the latest event itself carried the value.
|
|
296
|
+
var utilizationConfirmed = rec.utilization !== null && rec.confirmedAt !== null &&
|
|
297
|
+
rec.utilizationObservedAt === rec.observedAt;
|
|
298
|
+
var out = {
|
|
299
|
+
utilization: rec.utilization,
|
|
300
|
+
utilizationObservedAt: rec.utilizationObservedAt,
|
|
301
|
+
utilizationConfirmed: utilizationConfirmed,
|
|
302
|
+
resetsAt: rec.resetsAt,
|
|
303
|
+
status: rec.status,
|
|
304
|
+
observedAt: rec.observedAt,
|
|
305
|
+
confirmedAt: rec.confirmedAt,
|
|
306
|
+
ageSeconds: ageSeconds,
|
|
307
|
+
state: state,
|
|
308
|
+
source: rec.source,
|
|
309
|
+
};
|
|
310
|
+
if (state === "stale") {
|
|
311
|
+
out.staleReason = "no rate-limit change reported and no confirming session result since " + toIso(newest);
|
|
312
|
+
}
|
|
313
|
+
return out;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function freshness(vendor, seen, now, staleSec) {
|
|
317
|
+
var lastEvent = null;
|
|
318
|
+
var lastConfirmed = null;
|
|
319
|
+
Object.keys(seen).forEach(function (b) {
|
|
320
|
+
var o = Date.parse(seen[b].observedAt);
|
|
321
|
+
if (lastEvent === null || o > lastEvent) lastEvent = o;
|
|
322
|
+
if (seen[b].confirmedAt) {
|
|
323
|
+
var c = Date.parse(seen[b].confirmedAt);
|
|
324
|
+
if (lastConfirmed === null || c > lastConfirmed) lastConfirmed = c;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
var active = emitters[vendor] ? Object.keys(emitters[vendor]).length : 0;
|
|
328
|
+
var newest = lastEvent === null ? null : Math.max(lastEvent, lastConfirmed === null ? -Infinity : lastConfirmed);
|
|
329
|
+
var reason;
|
|
330
|
+
if (!seenThisRun[vendor]) reason = "no_event_since_start";
|
|
331
|
+
else if (newest !== null && (now - newest) / 1000 > staleSec && active === 0) reason = "no_active_session";
|
|
332
|
+
else if (lastConfirmed !== null && lastConfirmed > lastEvent) reason = "confirmed_by_result";
|
|
333
|
+
else reason = "event";
|
|
334
|
+
return {
|
|
335
|
+
lastEventAt: lastEvent === null ? null : toIso(lastEvent),
|
|
336
|
+
lastConfirmedAt: lastConfirmed === null ? null : toIso(lastConfirmed),
|
|
337
|
+
activeSessions: active,
|
|
338
|
+
reason: reason,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// opts.vendorIds: registered vendors, always listed with the standard buckets.
|
|
343
|
+
function snapshot(opts) {
|
|
344
|
+
opts = opts || {};
|
|
345
|
+
var now = opts.now !== undefined ? opts.now : Date.now();
|
|
346
|
+
var staleSec = opts.staleSeconds !== undefined ? opts.staleSeconds : staleAfterSeconds(opts.env);
|
|
347
|
+
var ids = Object.keys(records);
|
|
348
|
+
(opts.vendorIds || []).forEach(function (id) { if (ids.indexOf(id) === -1) ids.push(id); });
|
|
349
|
+
var vendors = {};
|
|
350
|
+
ids.forEach(function (vendor) {
|
|
351
|
+
var seen = records[vendor] || newMap();
|
|
352
|
+
var names = ALWAYS_LISTED_BUCKETS.slice();
|
|
353
|
+
Object.keys(seen).forEach(function (b) { if (names.indexOf(b) === -1) names.push(b); });
|
|
354
|
+
var buckets = {};
|
|
355
|
+
names.forEach(function (b) { buckets[b] = view(seen[b], now, staleSec); });
|
|
356
|
+
vendors[vendor] = { freshness: freshness(vendor, seen, now, staleSec), buckets: buckets };
|
|
357
|
+
});
|
|
358
|
+
return { generatedAt: toIso(now), staleAfterSeconds: staleSec, vendors: vendors };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function reset() { records = newMap(); emitters = newMap(); seenThisRun = newMap(); }
|
|
362
|
+
|
|
363
|
+
return { record: record, confirm: confirm, endProcess: endProcess, snapshot: snapshot, reset: reset, load: load, flush: flush };
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// The shared instance does no file I/O until the daemon gives it a path.
|
|
367
|
+
var sharedOpts = {};
|
|
368
|
+
var shared = createUsageStore(sharedOpts);
|
|
369
|
+
|
|
370
|
+
// Returns a persistent store bound to `file`, loaded from it, and installs it
|
|
371
|
+
// as the shared instance's backend.
|
|
372
|
+
function enablePersistence(file, extra) {
|
|
373
|
+
var store = createUsageStore(Object.assign({ file: file }, extra || {}));
|
|
374
|
+
store.load();
|
|
375
|
+
shared = store;
|
|
376
|
+
module.exports.record = store.record;
|
|
377
|
+
module.exports.confirm = store.confirm;
|
|
378
|
+
module.exports.endProcess = store.endProcess;
|
|
379
|
+
module.exports.snapshot = store.snapshot;
|
|
380
|
+
module.exports.reset = store.reset;
|
|
381
|
+
module.exports.flush = store.flush;
|
|
382
|
+
return store;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// The vendor a session's usage is keyed under. One definition so record,
|
|
386
|
+
// confirm and endProcess can never disagree about it.
|
|
387
|
+
function usageVendorFor(session, adapter) {
|
|
388
|
+
return session.vendor || (adapter && adapter.vendor) || "claude";
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
module.exports = {
|
|
392
|
+
createUsageStore: createUsageStore,
|
|
393
|
+
usageVendorFor: usageVendorFor,
|
|
394
|
+
record: shared.record,
|
|
395
|
+
confirm: shared.confirm,
|
|
396
|
+
endProcess: shared.endProcess,
|
|
397
|
+
snapshot: shared.snapshot,
|
|
398
|
+
reset: shared.reset,
|
|
399
|
+
flush: shared.flush,
|
|
400
|
+
enablePersistence: enablePersistence,
|
|
401
|
+
STORE_FILE_NAME: STORE_FILE_NAME,
|
|
402
|
+
DEFAULT_STALE_SECONDS: DEFAULT_STALE_SECONDS,
|
|
403
|
+
};
|
package/lib/vendor-auth.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// registry so the title and the login command are written once and every
|
|
3
3
|
// surface (chat message, notification, terminal launcher) agrees.
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var yoke = require("./yoke");
|
|
6
|
+
var registry = yoke.registry;
|
|
7
|
+
var providerCredentials = yoke.providerCredentials;
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* @param {string} vendor a registered vendor id
|
|
@@ -19,4 +21,33 @@ function authRequiredFacts(vendor) {
|
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
/**
|
|
25
|
+
* When the agent talks to a cloud provider (Bedrock, Vertex, Foundry) the
|
|
26
|
+
* session's environment selects, an auth-like error is that provider's
|
|
27
|
+
* credentials failing, not a missing sign-in: there is no login to offer.
|
|
28
|
+
* Only an agent that owns the provider's credential group is attributed to it.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} vendor a registered vendor id
|
|
31
|
+
* @param {?object} env the composed environment the session runs with
|
|
32
|
+
* @param {boolean} [osUsers] os-users mode: no settings file is read
|
|
33
|
+
* @returns {?{provider: string, label: string, message: string}}
|
|
34
|
+
*/
|
|
35
|
+
function providerAuthFailure(vendor, env, osUsers) {
|
|
36
|
+
if (!registry.isKnown(vendor)) return null;
|
|
37
|
+
var descriptor = registry.get(vendor);
|
|
38
|
+
var seen = typeof descriptor.effectiveRuntimeEnv === "function" ? descriptor.effectiveRuntimeEnv(env, osUsers) : env;
|
|
39
|
+
var provider = providerCredentials.configuredProvider(seen);
|
|
40
|
+
if (!provider) return null;
|
|
41
|
+
var groups = descriptor.credentialGroups || [];
|
|
42
|
+
var owns = groups.some(function (g) { return g.id === provider; });
|
|
43
|
+
if (!owns) return null;
|
|
44
|
+
var label = providerCredentials.PROVIDER_LABELS[provider];
|
|
45
|
+
return {
|
|
46
|
+
provider: provider,
|
|
47
|
+
label: label,
|
|
48
|
+
message: label + " is configured for " + registry.get(vendor).displayName + " on this host, and its credentials failed. " +
|
|
49
|
+
"Check them in Settings (environment) or on the host. Signing in is not the fix.",
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { authRequiredFacts: authRequiredFacts, providerAuthFailure: providerAuthFailure };
|
package/lib/ws-schema.js
CHANGED
|
@@ -21,6 +21,7 @@ var schema = {
|
|
|
21
21
|
"delete_session": { direction: "c2s", handler: "lib/project-sessions.js", description: "Delete a session by ID" },
|
|
22
22
|
"rename_session": { direction: "c2s", handler: "lib/project-sessions.js", description: "Rename a session" },
|
|
23
23
|
"set_session_bookmark": { direction: "c2s", handler: "lib/project-sessions.js", description: "Bookmark or unbookmark a session in the sidebar" },
|
|
24
|
+
"set_session_keep_alive": { direction: "c2s", handler: "lib/project-sessions.js", description: "Pin or unpin a session so the idle reaper does not end it (memory pressure still can)" },
|
|
24
25
|
"reorder_session_bookmarks": { direction: "c2s", handler: "lib/project-sessions.js", description: "Reorder favorited sessions within the favorites area" },
|
|
25
26
|
"bulk_delete_sessions": { direction: "c2s", handler: "lib/project-sessions.js", description: "Delete a group of sessions at once" },
|
|
26
27
|
"mark_cross_project_read": { direction: "c2s", handler: "lib/project-sessions.js", description: "Clear the cross-project unread badge for a project slug without switching to it (lr-13c047)" },
|
|
@@ -77,6 +78,7 @@ var schema = {
|
|
|
77
78
|
// every real sendAndRecord(session, { type: "..." }) call site — these 4
|
|
78
79
|
// were live, sent types with no documentation entry.
|
|
79
80
|
"plan_content": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Plan-mode content for the plan card" },
|
|
81
|
+
"system_info": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Plain system notice in the timeline (e.g. a context compaction marker)" },
|
|
80
82
|
"sdk_notification": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Informational notification surfaced from the vendor SDK" },
|
|
81
83
|
"diagnostic": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Session-scoped diagnostic toast (settings preflight, memory shedding, adapter warnings). A message with refresh:true updates the entry the client already holds for the same source and action, and is ignored when the client holds none. A message with persistent:true is a state, not a notice: its toast has no timer and a repeat replaces the earlier card of the same source" },
|
|
82
84
|
|
|
@@ -129,7 +131,7 @@ var schema = {
|
|
|
129
131
|
"prompt_pending": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt still awaiting the operator, re-presented on connect and session switch; same fields as prompt_request" },
|
|
130
132
|
"prompt_response": { direction: "c2s", handler: "lib/project-prompt-responses.js", description: "The operator's answer: {requestId, kind, ...} with decision (+ feedback, planContent) for permission/plan, answers or decision:\"skip\" for ask_user (answers keyed by question index; each a label or text, or for a multi-select question the list of chosen labels), action (+ content, held to the requested schema) for elicitation. The kind is required and must match the prompt's. Decision allow_always grants the whole tool (Skill: the one skill) for the rest of the session, and to a permission prompt that carries suppressAlwaysAllowRule settles nothing: the prompt is sent again as prompt_pending. A prompt of the extension kind is never answered this way" },
|
|
131
133
|
"prompt_resolved": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt was answered: {requestId, kind, decision|answers|skipped|action, source?}; a permission prompt forced by a user ask rule also carries matchedAskRule. source says who answered, as {kind:\"ws\", clientId, user} for a browser connection (clientId is a per-connection label, user the user id or null) or {kind:\"push\", action, user} for a push notification answer; it is absent when the answering path named none. The same source is written to the journal line the settle logs. Prompt content is never part of a source" },
|
|
132
|
-
"prompt_cancel": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt ended without an answer: {requestId, kind, reason}; reason is aborted, expired, turn_ended, query_ended, rewind, cleared or shutdown. Reason \"stale\" is sent only to a client whose prompt_response named a prompt the server no longer holds, and is not recorded in history" },
|
|
134
|
+
"prompt_cancel": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt ended without an answer: {requestId, kind, reason, source}; reason is aborted, expired, turn_ended, query_ended, rewind, cleared or shutdown; source says who or what ended it: user, timeout, session_end, daemon_restart, worker, caller:<name> or unspecified (a replayed ending recorded before cancels carried a source). promptState on a replayed request carries the same source for a cancelled prompt. Reason \"stale\" is sent only to a client whose prompt_response named a prompt the server no longer holds, and is not recorded in history" },
|
|
133
135
|
|
|
134
136
|
// Aliases kept for compatibility: the s2c types appear in history recorded
|
|
135
137
|
// before prompts had one shape (the client maps them onto the prompt_*
|
|
@@ -236,7 +238,16 @@ var schema = {
|
|
|
236
238
|
|
|
237
239
|
// -----------------------------------------------------------------------
|
|
238
240
|
// Push notifications
|
|
239
|
-
//
|
|
241
|
+
// notification_created, notification_dismissed and notifications_state carry
|
|
242
|
+
// each banner notification with the fields the notification core sets
|
|
243
|
+
// (lib/notify/): key (the collapse identity), collapse ("request"|"session"),
|
|
244
|
+
// persistent (not auto-dismissed) and liveInState (checkable against the
|
|
245
|
+
// live prompts). notifications_state also carries livePrompts. All additive.
|
|
246
|
+
// -----------------------------------------------------------------------
|
|
247
|
+
"set_session_prompt_reminders": { direction: "c2s", handler: "lib/project-sessions.js", description: "Turn reminders for a session's unanswered prompts on or off: {sessionId, enabled}" },
|
|
248
|
+
"notification_prefs": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "The user's per-type notification preferences ({prefs: {banner|sound|push: {category: boolean}}, preset, known, categories, presets}); sent on connect and to every connection of the user after a change" },
|
|
249
|
+
"notification_prefs_set": { direction: "c2s", handler: "lib/project-notifications.js", description: "Change the user's notification preferences by preset name or per-cell patch: {preset?, surfaces?}" },
|
|
250
|
+
"notification_prefs_migrate": { direction: "c2s", handler: "lib/project-notifications.js", description: "Seed the user's server-side preferences from what the browser held, once: {legacy: {sound}}" },
|
|
240
251
|
"push_subscribe": { direction: "c2s", handler: "lib/project-sessions.js", description: "Register a push notification subscription" },
|
|
241
252
|
|
|
242
253
|
// -----------------------------------------------------------------------
|
|
@@ -8,8 +8,17 @@
|
|
|
8
8
|
var registry = require("../registry");
|
|
9
9
|
var authChecks = require("../auth-checks");
|
|
10
10
|
var providerCredentials = require("../provider-credentials");
|
|
11
|
+
var claudeSettingsEnv = require("../../claude-settings-env");
|
|
11
12
|
var claudeCapabilities = require("./claude-capabilities").claudeCapabilities;
|
|
12
13
|
|
|
14
|
+
// The provider variables are Claude Code's, read after its settings file's env
|
|
15
|
+
// block is applied; so the classification is declared here, by the agent that
|
|
16
|
+
// reads them.
|
|
17
|
+
// osUsers: the daemon reads no settings file for another account's session.
|
|
18
|
+
function effectiveRuntimeEnv(env, osUsers) {
|
|
19
|
+
return claudeSettingsEnv.applyUserSettingsEnv(env || {}, { osUsers: !!osUsers });
|
|
20
|
+
}
|
|
21
|
+
|
|
13
22
|
registry.register({
|
|
14
23
|
id: "claude",
|
|
15
24
|
displayName: "Claude Code",
|
|
@@ -18,8 +27,9 @@ registry.register({
|
|
|
18
27
|
binaryNames: ["claude"],
|
|
19
28
|
probeInstalled: function(ctx) { return ctx.lookupBinary("claude"); },
|
|
20
29
|
checkAuth: authChecks.checkClaudeAuth,
|
|
30
|
+
effectiveRuntimeEnv: effectiveRuntimeEnv,
|
|
21
31
|
installHint: "Install Claude Code (npm install -g @anthropic-ai/claude-code), then sign in.",
|
|
22
|
-
loginCommand: "claude login",
|
|
32
|
+
loginCommand: "claude auth login",
|
|
23
33
|
osUsersSupported: true,
|
|
24
34
|
needsRuntimeEnv: false,
|
|
25
35
|
perProjectRuntime: false,
|
|
@@ -178,6 +178,15 @@ function flattenEvent(raw) {
|
|
|
178
178
|
base.status = raw.status;
|
|
179
179
|
return base;
|
|
180
180
|
}
|
|
181
|
+
if (raw.subtype === "compact_boundary") {
|
|
182
|
+
var cm = raw.compact_metadata || {};
|
|
183
|
+
base.yokeType = "compact_boundary";
|
|
184
|
+
base.trigger = cm.trigger === "manual" ? "manual" : "auto";
|
|
185
|
+
base.preTokens = typeof cm.pre_tokens === "number" ? cm.pre_tokens : null;
|
|
186
|
+
base.postTokens = typeof cm.post_tokens === "number" ? cm.post_tokens : null;
|
|
187
|
+
base.durationMs = typeof cm.duration_ms === "number" ? cm.duration_ms : null;
|
|
188
|
+
return base;
|
|
189
|
+
}
|
|
181
190
|
if (raw.subtype === "task_started") {
|
|
182
191
|
base.yokeType = "task_started";
|
|
183
192
|
base.parentToolId = raw.tool_use_id;
|
|
@@ -272,6 +281,13 @@ function flattenEvent(raw) {
|
|
|
272
281
|
base.yokeType = "message";
|
|
273
282
|
base.messageRole = raw.type;
|
|
274
283
|
base.content = raw.message ? raw.message.content : null;
|
|
284
|
+
// The immediate acknowledgement of a run_in_background Agent call is a
|
|
285
|
+
// launch, not an end: the SDK marks it with the structured tool output
|
|
286
|
+
// (status "async_launched"), so the host never has to read the result text.
|
|
287
|
+
var launch = raw.type === "user" ? raw.tool_use_result : null;
|
|
288
|
+
if (launch && typeof launch === "object" && launch.status === "async_launched") {
|
|
289
|
+
base.asyncLaunch = { agentId: typeof launch.agentId === "string" ? launch.agentId : null };
|
|
290
|
+
}
|
|
275
291
|
return base;
|
|
276
292
|
}
|
|
277
293
|
|
|
@@ -279,6 +295,7 @@ function flattenEvent(raw) {
|
|
|
279
295
|
if (raw.type === "rate_limit_event" && raw.rate_limit_info) {
|
|
280
296
|
base.yokeType = "rate_limit";
|
|
281
297
|
base.rateLimitInfo = raw.rate_limit_info;
|
|
298
|
+
base.rateLimitSource = "claude-cli:rate_limit_event";
|
|
282
299
|
return base;
|
|
283
300
|
}
|
|
284
301
|
|
|
@@ -296,12 +296,16 @@ function flattenEvent(notification, state) {
|
|
|
296
296
|
for (var wi = 0; wi < windows.length; wi++) {
|
|
297
297
|
var w = rl[windows[wi].key];
|
|
298
298
|
if (!w) continue;
|
|
299
|
-
|
|
299
|
+
// An absent usedPercent is unknown, not 0%: a fabricated zero would
|
|
300
|
+
// read as "plenty of headroom" to every consumer.
|
|
301
|
+
var hasUsed = typeof w.usedPercent === "number";
|
|
302
|
+
var utilization = hasUsed ? w.usedPercent / 100 : null;
|
|
300
303
|
var status = "allowed";
|
|
301
304
|
if (w.usedPercent >= 100) status = "rejected";
|
|
302
305
|
else if (w.usedPercent >= 80) status = "allowed_warning";
|
|
303
306
|
events.push({
|
|
304
307
|
yokeType: "rate_limit",
|
|
308
|
+
rateLimitSource: "codex:rateLimits",
|
|
305
309
|
rateLimitInfo: {
|
|
306
310
|
status: status,
|
|
307
311
|
resetsAt: w.resetsAt || null,
|
package/lib/yoke/auth-checks.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
var execSync = require("child_process").execSync;
|
|
5
5
|
var codexCommand = require("./codex-command");
|
|
6
6
|
var providerCredentials = require("./provider-credentials");
|
|
7
|
+
var runtimeEnv = require("../runtime-env");
|
|
8
|
+
var claudeSettingsEnv = require("../claude-settings-env");
|
|
7
9
|
|
|
8
10
|
function parseClaudeAuthStatusJson(out) {
|
|
9
11
|
if (!out) return null;
|
|
@@ -35,8 +37,21 @@ function hasThirdPartyProviderAuth(env) {
|
|
|
35
37
|
return null;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
/**
|
|
41
|
+
* @param {?object} overlay the Settings variables a Claude runtime is started
|
|
42
|
+
* with (sdk-bridge getRuntimeEnvOverlay), or null. The probe reads the same
|
|
43
|
+
* composed environment the spawn gets, never the daemon's alone.
|
|
44
|
+
* @param {boolean} [osUsers] os-users mode: no settings file is read
|
|
45
|
+
*/
|
|
46
|
+
function checkClaudeAuth(overlay, osUsers) {
|
|
47
|
+
var env = runtimeEnv.composeRuntimeEnv(process.env, overlay);
|
|
48
|
+
// Claude applies the user settings file's env block over the environment it
|
|
49
|
+
// is handed, so the provider is decided from that, not from the composed
|
|
50
|
+
// environment alone. The probe below runs with the daemon's own environment
|
|
51
|
+
// as before: it only reports whether the daemon user is signed in, and
|
|
52
|
+
// handing it project or shared text would let that text steer which account
|
|
53
|
+
// it asks about.
|
|
54
|
+
var provider = hasThirdPartyProviderAuth(claudeSettingsEnv.applyUserSettingsEnv(env, { osUsers: !!osUsers }));
|
|
40
55
|
if (provider) {
|
|
41
56
|
console.log("[yoke] Claude auth via third-party provider: " + provider);
|
|
42
57
|
return true;
|
package/lib/yoke/index.js
CHANGED
|
@@ -6,6 +6,9 @@ var instructions = require("./instructions");
|
|
|
6
6
|
var registry = require("./registry");
|
|
7
7
|
var installProbe = require("./install-probe");
|
|
8
8
|
var capabilities = require("./capabilities");
|
|
9
|
+
var providerCredentials = require("./provider-credentials");
|
|
10
|
+
var runtimeEnv = require("../runtime-env");
|
|
11
|
+
var claudeSettingsEnv = require("../claude-settings-env");
|
|
9
12
|
// Requiring the vendor modules registers the shipped agents. They are light on
|
|
10
13
|
// purpose: the adapters themselves are loaded when one is created.
|
|
11
14
|
require("./adapters/claude-vendor");
|
|
@@ -86,14 +89,28 @@ function logAuthCheck(auth) {
|
|
|
86
89
|
console.log("[yoke] Auth check: " + Object.keys(auth).map(function(id) { return id + "=" + auth[id]; }).join(" "));
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
// The answer depends on the Settings environment a runtime starts with, so the
|
|
93
|
+
// cache holds one answer for one overlay and a different overlay recomputes.
|
|
94
|
+
var _authCacheSig = null;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {?object} [overlay] the Settings variables of the runtime the answer
|
|
98
|
+
* is for (null: the daemon's own environment)
|
|
99
|
+
* @param {boolean} [osUsers] os-users mode: no settings file is read for it
|
|
100
|
+
*/
|
|
101
|
+
function checkAuth(overlay, osUsers) {
|
|
102
|
+
// The same overlay answers differently when the settings file is not read,
|
|
103
|
+
// and when the file the classification reads is edited.
|
|
104
|
+
var sig = runtimeEnv.envSignature(overlay) + "\0" + (osUsers ? "os" : "") +
|
|
105
|
+
"\0" + claudeSettingsEnv.settingsFileStamp({ osUsers: !!osUsers });
|
|
106
|
+
if (_authCache && _authCacheSig === sig) return _authCache;
|
|
91
107
|
|
|
92
108
|
var result = {};
|
|
93
109
|
registry.list().forEach(function(vendor) {
|
|
94
|
-
result[vendor.id] = !!vendor.checkAuth();
|
|
110
|
+
result[vendor.id] = !!vendor.checkAuth(overlay || null, !!osUsers);
|
|
95
111
|
});
|
|
96
112
|
_authCache = result;
|
|
113
|
+
_authCacheSig = sig;
|
|
97
114
|
logAuthCheck(_authCache);
|
|
98
115
|
return _authCache;
|
|
99
116
|
}
|
|
@@ -212,6 +229,7 @@ async function lazyCreateAdapter(adapters, vendor, opts, onInit) {
|
|
|
212
229
|
module.exports = {
|
|
213
230
|
isKnownVendor: isKnownVendor,
|
|
214
231
|
registry: registry,
|
|
232
|
+
providerCredentials: providerCredentials,
|
|
215
233
|
resolveCapabilities: capabilities.resolveCapabilities,
|
|
216
234
|
completeCapabilities: iface.completeCapabilities,
|
|
217
235
|
detectInstalledVendors: installProbe.detectInstalledVendors,
|