@sideboard-ai/core 0.1.198 → 0.1.200

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.
Files changed (35) hide show
  1. package/dist/{abletime-JINF5KJV.js → abletime-345SE3B4.js} +2 -2
  2. package/dist/{abletime-HR6P4GJH.js → abletime-KGPD3UUJ.js} +2 -2
  3. package/dist/{agents-5TZY6LLX.js → agents-N7WXOGN6.js} +28 -4
  4. package/dist/{agents-AQQKPD46.js → agents-ZRIFDXCB.js} +28 -4
  5. package/dist/{app-settings-5KHVKJKO.js → app-settings-AXCURTZJ.js} +11 -1
  6. package/dist/{app-settings-J775CYOO.js → app-settings-V6IHESEQ.js} +11 -1
  7. package/dist/{chunk-SYXSSU7G.js → chunk-5XSDGJMP.js} +369 -4
  8. package/dist/{chunk-DROELG52.js → chunk-62IMZIIZ.js} +58 -41
  9. package/dist/{chunk-E37JHCO3.js → chunk-7AHAABKN.js} +1 -1
  10. package/dist/{chunk-S5GLSRLP.js → chunk-CXFW5LIH.js} +48 -1
  11. package/dist/{chunk-6YTI2HBG.js → chunk-EWDE54OI.js} +2 -2
  12. package/dist/{chunk-AH6WIBLY.js → chunk-ISV5IFH3.js} +48 -1
  13. package/dist/{chunk-DP4TKAMZ.js → chunk-NXM45OS3.js} +1 -1
  14. package/dist/{chunk-6YS5IKD2.js → chunk-O2DRYD2B.js} +59 -42
  15. package/dist/{chunk-S4QCBBXS.js → chunk-OSPE25A7.js} +1 -1
  16. package/dist/{chunk-HZTHWU6A.js → chunk-PDMNYCPL.js} +2 -2
  17. package/dist/{chunk-KTHRWHA3.js → chunk-PGQGP4FD.js} +1 -1
  18. package/dist/{chunk-EA67VQM2.js → chunk-PKUPOVKP.js} +369 -4
  19. package/dist/{coordinator-prompt-IX66YUJ2.js → coordinator-prompt-2RWBH6W7.js} +3 -3
  20. package/dist/{coordinator-prompt-LYKS3YNG.js → coordinator-prompt-AL62H73U.js} +3 -3
  21. package/dist/{global-workspace-SNJ2Z6SL.js → global-workspace-VAO3BQP5.js} +3 -3
  22. package/dist/{global-workspace-4QX6UEOY.js → global-workspace-Y5KKGXN7.js} +3 -3
  23. package/dist/index.cjs +766 -280
  24. package/dist/index.d.cts +116 -11
  25. package/dist/index.d.ts +116 -11
  26. package/dist/index.js +42 -8
  27. package/dist/mcp/run-stdio.cjs +374 -276
  28. package/dist/mcp/run-stdio.js +8 -8
  29. package/dist/{orchestrator-L2H42HPW.js → orchestrator-D2EJ4Z7Z.js} +5 -5
  30. package/dist/{orchestrator-6ZNKCPNL.js → orchestrator-DPHIMK44.js} +5 -5
  31. package/dist/{workspaces-URMUVGAQ.js → workspaces-DZZQM745.js} +3 -3
  32. package/dist/{workspaces-UTOYGBYB.js → workspaces-HEKFQP4B.js} +3 -3
  33. package/dist/{worktree-R43JOR4V.js → worktree-ENRMJUI3.js} +2 -2
  34. package/dist/{worktree-RM6UWNGZ.js → worktree-IEUSQ63V.js} +2 -2
  35. package/package.json +1 -1
@@ -2,7 +2,7 @@
2
2
 
3
3
  import {
4
4
  isOrchestratorThread
5
- } from "./chunk-6YTI2HBG.js";
5
+ } from "./chunk-EWDE54OI.js";
6
6
  import {
7
7
  applyConnectedTeamToCli,
8
8
  brightsyMcpServerName,
@@ -12,12 +12,15 @@ import {
12
12
  import {
13
13
  loadBrightsyConfig
14
14
  } from "./chunk-Y4MIXGPA.js";
15
+ import {
16
+ httpFetch
17
+ } from "./chunk-VKQGAWHY.js";
15
18
  import {
16
19
  codexUnattendedGitConfigArgs,
17
20
  mergeAgentGitAuthEnv,
18
21
  resolveAgentGitAuthEnv,
19
22
  resolveCodexGitWritableRoots
20
- } from "./chunk-DP4TKAMZ.js";
23
+ } from "./chunk-NXM45OS3.js";
21
24
  import {
22
25
  enrichPathWithNpmGlobalBin,
23
26
  isConductorBundledCli,
@@ -35,7 +38,7 @@ import {
35
38
  resolveClaudeExecutable,
36
39
  unwrapStrippedElectronLaunch,
37
40
  wrapElectronAsNodeLaunch
38
- } from "./chunk-AH6WIBLY.js";
41
+ } from "./chunk-ISV5IFH3.js";
39
42
  import {
40
43
  appDataDir
41
44
  } from "./chunk-EQNRWDLN.js";
@@ -2420,7 +2423,7 @@ var claudeAdapter = {
2420
2423
  );
2421
2424
  }
2422
2425
  const mode = permissionMode(thread);
2423
- const { isOrchestratorThread: isOrchestratorThread2 } = await import("./global-workspace-SNJ2Z6SL.js");
2426
+ const { isOrchestratorThread: isOrchestratorThread2 } = await import("./global-workspace-VAO3BQP5.js");
2424
2427
  const isOrchestrator = isOrchestratorThread2(thread);
2425
2428
  const injectedServers = await buildInjectedMcpServers({
2426
2429
  includeSideboard: true,
@@ -4122,6 +4125,356 @@ function resolveQuotaFallbackAgent(current, preferred) {
4122
4125
  return ordered.find((a) => a !== current) ?? (current === "cursor" ? "codex" : "cursor");
4123
4126
  }
4124
4127
 
4128
+ // src/agents/claude-usage.ts
4129
+ var WINDOW_META = {
4130
+ five_hour: {
4131
+ label: "5-hour session",
4132
+ shortLabel: "5h",
4133
+ detail: "Rolling 5-hour limit across all models"
4134
+ },
4135
+ seven_day: {
4136
+ label: "Weekly",
4137
+ shortLabel: "wk",
4138
+ detail: "7-day cap across all models"
4139
+ },
4140
+ seven_day_opus: {
4141
+ label: "Opus",
4142
+ shortLabel: "Opus",
4143
+ detail: "Weekly Opus-only cap"
4144
+ },
4145
+ seven_day_sonnet: {
4146
+ label: "Sonnet",
4147
+ shortLabel: "Sonnet",
4148
+ detail: "Weekly Sonnet-only cap"
4149
+ }
4150
+ };
4151
+ var WINDOW_ORDER = [
4152
+ "five_hour",
4153
+ "seven_day",
4154
+ "seven_day_opus",
4155
+ "seven_day_sonnet"
4156
+ ];
4157
+ function parseClaudeResetsAt(value) {
4158
+ if (typeof value === "number" && Number.isFinite(value)) {
4159
+ const ms = value > 1e12 ? value : value * 1e3;
4160
+ const d = new Date(ms);
4161
+ return Number.isNaN(d.getTime()) ? null : d.toISOString();
4162
+ }
4163
+ if (typeof value === "string") {
4164
+ const trimmed = value.trim();
4165
+ if (!trimmed) return null;
4166
+ if (/^\d+(\.\d+)?$/.test(trimmed)) {
4167
+ return parseClaudeResetsAt(Number(trimmed));
4168
+ }
4169
+ const d = new Date(trimmed);
4170
+ return Number.isNaN(d.getTime()) ? null : d.toISOString();
4171
+ }
4172
+ return null;
4173
+ }
4174
+ function parseClaudeUtilization(value) {
4175
+ if (typeof value !== "number" || !Number.isFinite(value)) return null;
4176
+ return Math.max(0, Math.min(100, value));
4177
+ }
4178
+ function windowFromRaw(id, raw) {
4179
+ if (!raw || typeof raw !== "object") return null;
4180
+ const row = raw;
4181
+ const used = parseClaudeUtilization(row.utilization ?? row.used_percentage);
4182
+ if (used == null) return null;
4183
+ const meta = WINDOW_META[id];
4184
+ return {
4185
+ id,
4186
+ label: meta.label,
4187
+ shortLabel: meta.shortLabel,
4188
+ detail: meta.detail,
4189
+ usedPercent: used,
4190
+ remainingPercent: Math.max(0, Math.min(100, 100 - used)),
4191
+ resetsAt: parseClaudeResetsAt(row.resets_at)
4192
+ };
4193
+ }
4194
+ function extraUsageFromRaw(raw) {
4195
+ if (!raw || typeof raw !== "object") return void 0;
4196
+ const row = raw;
4197
+ const enabled = row.is_enabled === true || row.enabled === true;
4198
+ if (!enabled && row.is_enabled !== false && row.enabled !== false) return void 0;
4199
+ const usedCredits = numberOrUndef(row.used_credits ?? row.used);
4200
+ const monthlyLimit = numberOrUndef(row.monthly_limit);
4201
+ const usedPercent = parseClaudeUtilization(row.utilization) ?? void 0;
4202
+ return {
4203
+ enabled,
4204
+ ...usedCredits != null ? { usedCredits } : {},
4205
+ ...monthlyLimit != null ? { monthlyLimit } : {},
4206
+ ...usedPercent != null ? { usedPercent } : {}
4207
+ };
4208
+ }
4209
+ function numberOrUndef(value) {
4210
+ if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
4211
+ return value;
4212
+ }
4213
+ function parseClaudeUsagePayload(raw, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
4214
+ if (!raw || typeof raw !== "object") return null;
4215
+ const obj = raw;
4216
+ const source = obj.rate_limits && typeof obj.rate_limits === "object" ? obj.rate_limits : obj;
4217
+ const windows = [];
4218
+ for (const id of WINDOW_ORDER) {
4219
+ const parsed = windowFromRaw(id, source[id]);
4220
+ if (parsed) windows.push(parsed);
4221
+ }
4222
+ if (windows.length === 0) return null;
4223
+ const extra = extraUsageFromRaw(obj.extra_usage ?? source.extra_usage);
4224
+ return {
4225
+ windows,
4226
+ ...extra ? { extraUsage: extra } : {},
4227
+ fetchedAt
4228
+ };
4229
+ }
4230
+ function hottestClaudeWindow(usage) {
4231
+ if (usage.windows.length === 0) return null;
4232
+ return usage.windows.reduce((a, b) => b.usedPercent > a.usedPercent ? b : a);
4233
+ }
4234
+ function formatClaudeUsageReset(resetsAt, now = /* @__PURE__ */ new Date()) {
4235
+ if (!resetsAt) return "";
4236
+ const at = new Date(resetsAt);
4237
+ if (Number.isNaN(at.getTime())) return "";
4238
+ const ms = at.getTime() - now.getTime();
4239
+ if (ms <= 0) return "resets soon";
4240
+ const minutes = Math.round(ms / 6e4);
4241
+ if (minutes < 60) return `resets in ${Math.max(1, minutes)}m`;
4242
+ const hours = Math.round(minutes / 60);
4243
+ if (hours < 36) return `resets in ${hours}h`;
4244
+ try {
4245
+ return `resets ${at.toLocaleString(void 0, {
4246
+ weekday: "short",
4247
+ hour: "numeric",
4248
+ minute: "2-digit"
4249
+ })}`;
4250
+ } catch {
4251
+ return `resets ${at.toISOString()}`;
4252
+ }
4253
+ }
4254
+ function formatClaudeUsageResetClock(resetsAt) {
4255
+ if (!resetsAt) return "";
4256
+ const at = new Date(resetsAt);
4257
+ if (Number.isNaN(at.getTime())) return "";
4258
+ try {
4259
+ return at.toLocaleString(void 0, {
4260
+ weekday: "short",
4261
+ month: "short",
4262
+ day: "numeric",
4263
+ hour: "numeric",
4264
+ minute: "2-digit"
4265
+ });
4266
+ } catch {
4267
+ return at.toISOString();
4268
+ }
4269
+ }
4270
+ function formatClaudeUsageFetchedAt(fetchedAt, now = /* @__PURE__ */ new Date()) {
4271
+ const at = new Date(fetchedAt);
4272
+ if (Number.isNaN(at.getTime())) return "";
4273
+ const minutes = Math.max(0, Math.round((now.getTime() - at.getTime()) / 6e4));
4274
+ if (minutes < 1) return "Updated just now";
4275
+ if (minutes < 60) return `Updated ${minutes}m ago`;
4276
+ const hours = Math.round(minutes / 60);
4277
+ if (hours < 36) return `Updated ${hours}h ago`;
4278
+ return `Updated ${formatClaudeUsageResetClock(fetchedAt)}`;
4279
+ }
4280
+ function formatClaudeExtraUsageDetail(extra) {
4281
+ if (!extra.enabled) return "Extra usage off";
4282
+ const bits = ["Extra usage on"];
4283
+ if (extra.usedCredits != null && extra.monthlyLimit != null) {
4284
+ bits.push(`${extra.usedCredits} / ${extra.monthlyLimit} credits this month`);
4285
+ } else if (extra.usedCredits != null) {
4286
+ bits.push(`${extra.usedCredits} credits used`);
4287
+ }
4288
+ if (extra.usedPercent != null) {
4289
+ bits.push(`${Math.round(extra.usedPercent)}% of extra pool`);
4290
+ }
4291
+ return bits.join(" \xB7 ");
4292
+ }
4293
+ function formatClaudeUsageWindowLine(window, now = /* @__PURE__ */ new Date()) {
4294
+ const reset = formatClaudeUsageReset(window.resetsAt, now);
4295
+ const clock = formatClaudeUsageResetClock(window.resetsAt);
4296
+ const left = `${Math.round(window.remainingPercent)}% left`;
4297
+ const used = `${Math.round(window.usedPercent)}% used`;
4298
+ const resetBit = reset ? clock && !reset.includes(clock) ? `${reset} (${clock})` : reset : "";
4299
+ return resetBit ? `${window.label} \u2014 ${window.detail}. ${left} \xB7 ${used} \xB7 ${resetBit}` : `${window.label} \u2014 ${window.detail}. ${left} \xB7 ${used}`;
4300
+ }
4301
+ function formatClaudeUsageTooltip(usage, now = /* @__PURE__ */ new Date()) {
4302
+ const lines = [
4303
+ "Claude Code plan",
4304
+ ...usage.windows.map((w) => formatClaudeUsageWindowLine(w, now))
4305
+ ];
4306
+ if (usage.extraUsage) {
4307
+ lines.push(formatClaudeExtraUsageDetail(usage.extraUsage));
4308
+ }
4309
+ const fetched = formatClaudeUsageFetchedAt(usage.fetchedAt, now);
4310
+ if (fetched) lines.push(fetched);
4311
+ return lines.join("\n");
4312
+ }
4313
+ function formatClaudeUsageCompact(window) {
4314
+ return `${window.shortLabel} ${Math.round(window.remainingPercent)}%`;
4315
+ }
4316
+ function claudeUsageWindowOverLimit(window) {
4317
+ return window.remainingPercent <= 0 || window.usedPercent >= 100;
4318
+ }
4319
+ function claudeUsageOverLimitWindows(usage) {
4320
+ if (!usage) return [];
4321
+ return usage.windows.filter(claudeUsageWindowOverLimit);
4322
+ }
4323
+ function formatOverLimitWindowList(windows, now) {
4324
+ const parts = windows.map((w) => {
4325
+ const reset = formatClaudeUsageReset(w.resetsAt, now);
4326
+ return reset ? `${w.label} (${reset})` : w.label;
4327
+ });
4328
+ return {
4329
+ list: parts.join(", "),
4330
+ verb: windows.length === 1 ? "is" : "are"
4331
+ };
4332
+ }
4333
+ function formatClaudeUsageOverLimitConfirm(windows, now = /* @__PURE__ */ new Date()) {
4334
+ if (windows.length === 0) return "";
4335
+ const { list, verb } = formatOverLimitWindowList(windows, now);
4336
+ return `Claude Code ${list} ${verb} at or over the plan limit. Send this message anyway?`;
4337
+ }
4338
+ function formatClaudeUsageOverLimitWait(windows, now = /* @__PURE__ */ new Date()) {
4339
+ if (windows.length === 0) return "";
4340
+ const { list, verb } = formatOverLimitWindowList(windows, now);
4341
+ return `Claude Code ${list} ${verb} at or over the plan limit. Sending is paused until the window resets.`;
4342
+ }
4343
+
4344
+ // src/agents/claude-usage-client.ts
4345
+ import { existsSync as existsSync13, readFileSync as readFileSync5 } from "fs";
4346
+ import { homedir as homedir5 } from "os";
4347
+ import { join as join10 } from "path";
4348
+ var CLAUDE_OAUTH_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
4349
+ var CLAUDE_USAGE_TTL_MS = 9e4;
4350
+ var CLAUDE_USAGE_ERROR_TTL_MS = 5 * 6e4;
4351
+ var CLAUDE_USAGE_STALE_OK_MS = 30 * 6e4;
4352
+ var KEYCHAIN_SERVICES = ["Claude Code-credentials", "Claude Code"];
4353
+ var cache = null;
4354
+ var errorUntil = 0;
4355
+ var inflight = null;
4356
+ var lastGood = null;
4357
+ var claudeVersion = null;
4358
+ function accessTokenFromCredentialsJson(raw) {
4359
+ const trimmed = raw.trim();
4360
+ if (!trimmed) return null;
4361
+ if (trimmed.startsWith("sk-ant-")) {
4362
+ const token = trimmed.split(/\s+/)[0];
4363
+ return token || null;
4364
+ }
4365
+ try {
4366
+ const parsed = JSON.parse(trimmed);
4367
+ const oauth = parsed.claudeAiOauth && typeof parsed.claudeAiOauth === "object" ? parsed.claudeAiOauth : parsed;
4368
+ const token = oauth.accessToken ?? oauth.access_token;
4369
+ return typeof token === "string" && token.trim() ? token.trim() : null;
4370
+ } catch {
4371
+ return null;
4372
+ }
4373
+ }
4374
+ function claudeCredentialsPath() {
4375
+ const root = process.env.CLAUDE_CONFIG_DIR?.trim() || join10(homedir5(), ".claude");
4376
+ return join10(root, ".credentials.json");
4377
+ }
4378
+ async function readFileAccessToken() {
4379
+ const path = claudeCredentialsPath();
4380
+ if (!existsSync13(path)) return null;
4381
+ try {
4382
+ return accessTokenFromCredentialsJson(readFileSync5(path, "utf8"));
4383
+ } catch {
4384
+ return null;
4385
+ }
4386
+ }
4387
+ async function readKeychainAccessToken() {
4388
+ if (process.platform !== "darwin") return null;
4389
+ for (const service of KEYCHAIN_SERVICES) {
4390
+ const result = await run("security", ["find-generic-password", "-s", service, "-w"], {
4391
+ reject: false,
4392
+ timeoutMs: 4e3
4393
+ });
4394
+ if (result.exitCode !== 0 || !result.stdout.trim()) continue;
4395
+ const token = accessTokenFromCredentialsJson(result.stdout);
4396
+ if (token) return token;
4397
+ }
4398
+ return null;
4399
+ }
4400
+ async function readClaudeAccessToken() {
4401
+ const envToken = process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim();
4402
+ if (envToken) return envToken;
4403
+ const fromFile = await readFileAccessToken();
4404
+ if (fromFile) return fromFile;
4405
+ return readKeychainAccessToken();
4406
+ }
4407
+ async function resolveClaudeUserAgent() {
4408
+ if (claudeVersion) return `claude-code/${claudeVersion}`;
4409
+ try {
4410
+ const claude = resolveClaudeExecutable();
4411
+ const result = await run(claude, ["--version"], { reject: false, timeoutMs: 4e3 });
4412
+ const match = `${result.stdout}
4413
+ ${result.stderr}`.match(/(\d+\.\d+\.\d+)/);
4414
+ claudeVersion = match?.[1] ?? "2.1.80";
4415
+ } catch {
4416
+ claudeVersion = "2.1.80";
4417
+ }
4418
+ return `claude-code/${claudeVersion}`;
4419
+ }
4420
+ function staleOk(now) {
4421
+ if (!lastGood) return null;
4422
+ if (now - lastGood.at > CLAUDE_USAGE_STALE_OK_MS) return null;
4423
+ return lastGood.value;
4424
+ }
4425
+ async function getClaudePlanUsage(opts = {}) {
4426
+ const now = opts.now ?? Date.now();
4427
+ if (!opts.force) {
4428
+ if (cache && now - cache.at < CLAUDE_USAGE_TTL_MS) return cache.value;
4429
+ if (now < errorUntil) return staleOk(now);
4430
+ }
4431
+ if (inflight) return inflight;
4432
+ inflight = (async () => {
4433
+ try {
4434
+ const token = await (opts.readAccessToken ?? readClaudeAccessToken)();
4435
+ if (!token) {
4436
+ cache = { at: now, value: null };
4437
+ return null;
4438
+ }
4439
+ const fetchFn = opts.fetch ?? httpFetch;
4440
+ const userAgent = opts.userAgent ?? await resolveClaudeUserAgent();
4441
+ const ac = new AbortController();
4442
+ const timer = setTimeout(() => ac.abort(), 8e3);
4443
+ let res;
4444
+ try {
4445
+ res = await fetchFn(CLAUDE_OAUTH_USAGE_URL, {
4446
+ headers: {
4447
+ Authorization: `Bearer ${token}`,
4448
+ "anthropic-beta": "oauth-2025-04-20",
4449
+ "User-Agent": userAgent
4450
+ },
4451
+ signal: ac.signal
4452
+ });
4453
+ } finally {
4454
+ clearTimeout(timer);
4455
+ }
4456
+ if (res.status === 401 || res.status === 403) {
4457
+ cache = { at: now, value: null };
4458
+ return null;
4459
+ }
4460
+ if (!res.ok) {
4461
+ errorUntil = now + CLAUDE_USAGE_ERROR_TTL_MS;
4462
+ return staleOk(now);
4463
+ }
4464
+ const usage = parseClaudeUsagePayload(await res.json(), new Date(now).toISOString());
4465
+ cache = { at: now, value: usage };
4466
+ if (usage) lastGood = { at: now, value: usage };
4467
+ return usage;
4468
+ } catch {
4469
+ errorUntil = now + CLAUDE_USAGE_ERROR_TTL_MS;
4470
+ return staleOk(now);
4471
+ } finally {
4472
+ inflight = null;
4473
+ }
4474
+ })();
4475
+ return inflight;
4476
+ }
4477
+
4125
4478
  // src/agents/install.ts
4126
4479
  var SETUP = {
4127
4480
  claude: {
@@ -4426,6 +4779,18 @@ export {
4426
4779
  isSessionQuotaLimit,
4427
4780
  parseSessionQuotaResetAt,
4428
4781
  resolveQuotaFallbackAgent,
4782
+ parseClaudeUsagePayload,
4783
+ hottestClaudeWindow,
4784
+ formatClaudeUsageReset,
4785
+ formatClaudeUsageResetClock,
4786
+ formatClaudeUsageFetchedAt,
4787
+ formatClaudeExtraUsageDetail,
4788
+ formatClaudeUsageTooltip,
4789
+ formatClaudeUsageCompact,
4790
+ claudeUsageOverLimitWindows,
4791
+ formatClaudeUsageOverLimitConfirm,
4792
+ formatClaudeUsageOverLimitWait,
4793
+ getClaudePlanUsage,
4429
4794
  getAgentSetupInfo,
4430
4795
  listAgentSetupInfo,
4431
4796
  resolveLoginCommand,