@sideboard-ai/core 0.1.312 → 0.1.313

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.
@@ -46,7 +46,7 @@ import {
46
46
  resolveCursorSdkRoot,
47
47
  resolveQuotaFallbackAgent,
48
48
  turnCostUsdFromCursorUsage
49
- } from "./chunk-2P2HYXA2.js";
49
+ } from "./chunk-2JOBQUUS.js";
50
50
  import {
51
51
  getAgentSetupInfo,
52
52
  installAgent,
@@ -59,8 +59,8 @@ import {
59
59
  resolveLoginCommand,
60
60
  whichOnPath
61
61
  } from "./chunk-EGTCXNQM.js";
62
- import "./chunk-42JGPPVS.js";
63
- import "./chunk-PXMLMBMI.js";
62
+ import "./chunk-V5BTGQ6M.js";
63
+ import "./chunk-E63AM3PW.js";
64
64
  import "./chunk-2GPQZZLY.js";
65
65
  import "./chunk-I5TESHDN.js";
66
66
  import "./chunk-X3FSWWW2.js";
@@ -37,8 +37,8 @@ import {
37
37
  planModeTurnInstruction,
38
38
  resolveCursorModelId,
39
39
  resolveQuotaFallbackAgent
40
- } from "./chunk-4FZUUH6W.js";
41
- import "./chunk-VEVFHO6K.js";
40
+ } from "./chunk-TDXORDN6.js";
41
+ import "./chunk-HH3VVTEC.js";
42
42
  import "./chunk-7Q327QF2.js";
43
43
  import {
44
44
  getAgentSetupInfo,
@@ -56,7 +56,7 @@ import "./chunk-5QX2NYXL.js";
56
56
  import "./chunk-BIPXOHZI.js";
57
57
  import "./chunk-HG25AYBV.js";
58
58
  import "./chunk-2P4XKWV2.js";
59
- import "./chunk-33KDPEK4.js";
59
+ import "./chunk-RSA47QYR.js";
60
60
  import "./chunk-JAT3JFOS.js";
61
61
  import "./chunk-F2PVRF3B.js";
62
62
  import {
@@ -5,10 +5,10 @@ import {
5
5
  brightsyMcpServerName,
6
6
  ensureCliTeamTracked,
7
7
  ensureConnectedBrightsyTeamTokens
8
- } from "./chunk-42JGPPVS.js";
8
+ } from "./chunk-V5BTGQ6M.js";
9
9
  import {
10
10
  loadBrightsyConfig
11
- } from "./chunk-PXMLMBMI.js";
11
+ } from "./chunk-E63AM3PW.js";
12
12
  import {
13
13
  httpFetch
14
14
  } from "./chunk-2GPQZZLY.js";
@@ -27,7 +27,7 @@ import {
27
27
  parseSessionQuotaResetAt,
28
28
  planModeTurnInstruction,
29
29
  resolveQuotaFallbackAgent
30
- } from "./chunk-2P2HYXA2.js";
30
+ } from "./chunk-2JOBQUUS.js";
31
31
  import {
32
32
  REVIEW_TAB_TITLE,
33
33
  applyWorktreePkgCacheEnv,
@@ -6438,7 +6438,7 @@ function formatScheduledPrompt(name, prompt) {
6438
6438
  ${prompt}`;
6439
6439
  }
6440
6440
  async function defaultDeps() {
6441
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-S44BMNN7.js");
6441
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-RRHB7RNN.js");
6442
6442
  const orch = getOrchestrator2();
6443
6443
  return {
6444
6444
  findThread: (id) => findThreadByRef(id),
@@ -5,27 +5,50 @@ import {
5
5
  } from "./chunk-2GPQZZLY.js";
6
6
 
7
7
  // src/brightsy/config.ts
8
- import { existsSync, readFileSync, writeFileSync } from "fs";
8
+ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
9
9
  import { homedir } from "os";
10
- import { join } from "path";
10
+ import { dirname, join } from "path";
11
+ function resolveBrightsyConfigFile(path) {
12
+ try {
13
+ if (existsSync(path) && statSync(path).isDirectory()) {
14
+ return join(path, "config.json");
15
+ }
16
+ } catch {
17
+ }
18
+ return path;
19
+ }
11
20
  function brightsyConfigPath() {
12
21
  const override = process.env.BRIGHTSY_CONFIG?.trim();
13
- if (override) return override;
14
- return join(homedir(), ".brightsy", "config.json");
22
+ const raw = override || join(homedir(), ".brightsy", "config.json");
23
+ return resolveBrightsyConfigFile(raw);
15
24
  }
16
25
  function loadBrightsyConfig() {
17
26
  const path = brightsyConfigPath();
18
27
  if (!existsSync(path)) {
19
28
  throw new Error("Brightsy not logged in \u2014 run `brightsy login` first");
20
29
  }
21
- const raw = JSON.parse(readFileSync(path, "utf8"));
30
+ let text;
31
+ try {
32
+ text = readFileSync(path, "utf8");
33
+ } catch (err) {
34
+ const code = err && typeof err === "object" && "code" in err ? String(err.code) : "";
35
+ if (code === "EISDIR") {
36
+ throw new Error(
37
+ `Brightsy config is a directory (${path}) \u2014 expected ~/.brightsy/config.json`
38
+ );
39
+ }
40
+ throw err;
41
+ }
42
+ const raw = JSON.parse(text);
22
43
  if (!raw.access_token || !raw.account_id) {
23
44
  throw new Error("Brightsy config incomplete \u2014 run `brightsy login`");
24
45
  }
25
46
  return raw;
26
47
  }
27
48
  function saveBrightsyConfig(cfg) {
28
- writeFileSync(brightsyConfigPath(), `${JSON.stringify(cfg, null, 2)}
49
+ const path = brightsyConfigPath();
50
+ mkdirSync(dirname(path), { recursive: true });
51
+ writeFileSync(path, `${JSON.stringify(cfg, null, 2)}
29
52
  `, {
30
53
  mode: 384
31
54
  });
@@ -5,7 +5,7 @@ import {
5
5
  loadBrightsyConfig,
6
6
  refreshBrightsyAccessToken,
7
7
  saveBrightsyConfig
8
- } from "./chunk-33KDPEK4.js";
8
+ } from "./chunk-RSA47QYR.js";
9
9
  import {
10
10
  run
11
11
  } from "./chunk-QVN2WOKJ.js";
@@ -19,7 +19,7 @@ import { join } from "path";
19
19
 
20
20
  // src/brightsy/accounts.ts
21
21
  async function loadConnectedTeams() {
22
- const { listConnectedBrightsyTeams: listConnectedBrightsyTeams2 } = await import("./connected-teams-BBNYTR3I.js");
22
+ const { listConnectedBrightsyTeams: listConnectedBrightsyTeams2 } = await import("./connected-teams-IHK2WXUI.js");
23
23
  return listConnectedBrightsyTeams2();
24
24
  }
25
25
  async function runBrightsyTeamsJson(args) {
@@ -47,15 +47,15 @@ async function listBrightsyAccounts() {
47
47
  }
48
48
  async function getBrightsySession() {
49
49
  try {
50
- const { ensureBrightsyLocalConfigFresh: ensureBrightsyLocalConfigFresh2 } = await import("./oauth-DP4ZV2M2.js");
51
- const { ensureConnectedBrightsyTeamTokens: ensureConnectedBrightsyTeamTokens2 } = await import("./connected-teams-BBNYTR3I.js");
50
+ const { ensureBrightsyLocalConfigFresh: ensureBrightsyLocalConfigFresh2 } = await import("./oauth-CR5FY4CJ.js");
51
+ const { ensureConnectedBrightsyTeamTokens: ensureConnectedBrightsyTeamTokens2 } = await import("./connected-teams-IHK2WXUI.js");
52
52
  await ensureBrightsyLocalConfigFresh2();
53
53
  await ensureConnectedBrightsyTeamTokens2();
54
54
  loadBrightsyConfig();
55
55
  const data = await runBrightsyTeamsJson([]);
56
56
  const accounts = Array.isArray(data.teams) ? data.teams : [];
57
57
  const active = data.active ?? accounts.find((a) => a.active) ?? null;
58
- const { ensureCliTeamTracked: ensureCliTeamTracked2 } = await import("./connected-teams-BBNYTR3I.js");
58
+ const { ensureCliTeamTracked: ensureCliTeamTracked2 } = await import("./connected-teams-IHK2WXUI.js");
59
59
  const connectedTeams = ensureCliTeamTracked2(
60
60
  active ? { id: active.id, slug: active.slug, name: active.name } : void 0
61
61
  );
@@ -95,7 +95,7 @@ async function performBrightsyAccountSwitch(accountIdOrSlug) {
95
95
  return { cfg, target: data.active };
96
96
  }
97
97
  async function switchBrightsyAccount(accountIdOrSlug) {
98
- const { connectBrightsyTeam: connectBrightsyTeam2 } = await import("./connected-teams-BBNYTR3I.js");
98
+ const { connectBrightsyTeam: connectBrightsyTeam2 } = await import("./connected-teams-IHK2WXUI.js");
99
99
  await connectBrightsyTeam2(accountIdOrSlug);
100
100
  return getBrightsySession();
101
101
  }
@@ -134,6 +134,25 @@ function listConnectedBrightsyTeams() {
134
134
  function getConnectedBrightsyTeamsRaw() {
135
135
  return readStore();
136
136
  }
137
+ function teamFromCliSession(cfg, current) {
138
+ return {
139
+ ...current,
140
+ access_token: cfg.access_token,
141
+ refresh_token: cfg.refresh_token ?? current.refresh_token,
142
+ expires_at: cfg.expires_at ?? current.expires_at,
143
+ endpoint: cfg.endpoint ?? current.endpoint,
144
+ oauth_client_id: cfg.oauth_client_id ?? current.oauth_client_id,
145
+ slug: cfg.account_slug || current.slug
146
+ };
147
+ }
148
+ function brightsySessionShouldReplace(a, b) {
149
+ if (!a.access_token) return false;
150
+ const aStale = brightsyAccessTokenNeedsRefresh(a.expires_at);
151
+ const bStale = !b.access_token || brightsyAccessTokenNeedsRefresh(b.expires_at);
152
+ if (!aStale && bStale) return true;
153
+ if (aStale) return false;
154
+ return (a.expires_at ?? 0) > (b.expires_at ?? 0);
155
+ }
137
156
  function applyConnectedTeamToCli(team) {
138
157
  let base = {};
139
158
  try {
@@ -220,22 +239,34 @@ async function ensureConnectedBrightsyTeamTokens(opts) {
220
239
  }
221
240
  next.push(refreshed);
222
241
  }
223
- if (changed) writeStore(next);
224
242
  try {
225
243
  const cfg2 = loadBrightsyConfig();
226
- const active = next.find((t) => t.id === cfg2.account_id);
227
- if (active && active.access_token !== cfg2.access_token) {
228
- applyConnectedTeamToCli(active);
244
+ const idx = next.findIndex((t) => t.id === cfg2.account_id);
245
+ if (idx >= 0) {
246
+ const active = next[idx];
247
+ if (brightsySessionShouldReplace(cfg2, active)) {
248
+ next[idx] = teamFromCliSession(cfg2, active);
249
+ changed = true;
250
+ } else if (active.access_token !== cfg2.access_token) {
251
+ applyConnectedTeamToCli(active);
252
+ }
229
253
  }
230
254
  } catch {
231
255
  }
256
+ if (changed) writeStore(next);
232
257
  return next;
233
258
  }
234
259
  function ensureCliTeamTracked(meta) {
235
260
  try {
236
261
  const cfg = loadBrightsyConfig();
237
262
  const existing = readStore();
238
- if (existing.some((t) => t.id === cfg.account_id)) {
263
+ const idx = existing.findIndex((t) => t.id === cfg.account_id);
264
+ if (idx >= 0) {
265
+ const current = existing[idx];
266
+ if (brightsySessionShouldReplace(cfg, current)) {
267
+ existing[idx] = teamFromCliSession(cfg, current);
268
+ writeStore(existing);
269
+ }
239
270
  return listConnectedBrightsyTeams();
240
271
  }
241
272
  const team = {
@@ -312,6 +343,7 @@ export {
312
343
  switchBrightsyAccount,
313
344
  listConnectedBrightsyTeams,
314
345
  getConnectedBrightsyTeamsRaw,
346
+ brightsySessionShouldReplace,
315
347
  applyConnectedTeamToCli,
316
348
  ensureConnectedBrightsyTeamTokens,
317
349
  ensureCliTeamTracked,
@@ -3,27 +3,50 @@ import {
3
3
  } from "./chunk-JAT3JFOS.js";
4
4
 
5
5
  // src/brightsy/config.ts
6
- import { existsSync, readFileSync, writeFileSync } from "fs";
6
+ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
7
7
  import { homedir } from "os";
8
- import { join } from "path";
8
+ import { dirname, join } from "path";
9
+ function resolveBrightsyConfigFile(path) {
10
+ try {
11
+ if (existsSync(path) && statSync(path).isDirectory()) {
12
+ return join(path, "config.json");
13
+ }
14
+ } catch {
15
+ }
16
+ return path;
17
+ }
9
18
  function brightsyConfigPath() {
10
19
  const override = process.env.BRIGHTSY_CONFIG?.trim();
11
- if (override) return override;
12
- return join(homedir(), ".brightsy", "config.json");
20
+ const raw = override || join(homedir(), ".brightsy", "config.json");
21
+ return resolveBrightsyConfigFile(raw);
13
22
  }
14
23
  function loadBrightsyConfig() {
15
24
  const path = brightsyConfigPath();
16
25
  if (!existsSync(path)) {
17
26
  throw new Error("Brightsy not logged in \u2014 run `brightsy login` first");
18
27
  }
19
- const raw = JSON.parse(readFileSync(path, "utf8"));
28
+ let text;
29
+ try {
30
+ text = readFileSync(path, "utf8");
31
+ } catch (err) {
32
+ const code = err && typeof err === "object" && "code" in err ? String(err.code) : "";
33
+ if (code === "EISDIR") {
34
+ throw new Error(
35
+ `Brightsy config is a directory (${path}) \u2014 expected ~/.brightsy/config.json`
36
+ );
37
+ }
38
+ throw err;
39
+ }
40
+ const raw = JSON.parse(text);
20
41
  if (!raw.access_token || !raw.account_id) {
21
42
  throw new Error("Brightsy config incomplete \u2014 run `brightsy login`");
22
43
  }
23
44
  return raw;
24
45
  }
25
46
  function saveBrightsyConfig(cfg) {
26
- writeFileSync(brightsyConfigPath(), `${JSON.stringify(cfg, null, 2)}
47
+ const path = brightsyConfigPath();
48
+ mkdirSync(dirname(path), { recursive: true });
49
+ writeFileSync(path, `${JSON.stringify(cfg, null, 2)}
27
50
  `, {
28
51
  mode: 384
29
52
  });
@@ -3,7 +3,7 @@ import {
3
3
  brightsyMcpServerName,
4
4
  ensureCliTeamTracked,
5
5
  ensureConnectedBrightsyTeamTokens
6
- } from "./chunk-VEVFHO6K.js";
6
+ } from "./chunk-HH3VVTEC.js";
7
7
  import {
8
8
  looksLikeConversationSummary,
9
9
  looksLikeSkillBody,
@@ -21,7 +21,7 @@ import {
21
21
  } from "./chunk-BIPXOHZI.js";
22
22
  import {
23
23
  loadBrightsyConfig
24
- } from "./chunk-33KDPEK4.js";
24
+ } from "./chunk-RSA47QYR.js";
25
25
  import {
26
26
  httpFetch
27
27
  } from "./chunk-JAT3JFOS.js";
@@ -14,7 +14,7 @@ import {
14
14
  parseSessionQuotaResetAt,
15
15
  planModeTurnInstruction,
16
16
  resolveQuotaFallbackAgent
17
- } from "./chunk-4FZUUH6W.js";
17
+ } from "./chunk-TDXORDN6.js";
18
18
  import {
19
19
  REVIEW_TAB_TITLE,
20
20
  applyWorktreePkgCacheEnv,
@@ -3080,7 +3080,7 @@ async function createThread(input, _onSetupLine) {
3080
3080
  return readThread(thread.id) ?? thread;
3081
3081
  }
3082
3082
  async function listLinearIssues(agent, repoPath) {
3083
- const { getAdapter: getAdapter2 } = await import("./agents-IOJRGGK3.js");
3083
+ const { getAdapter: getAdapter2 } = await import("./agents-PSNWJMEC.js");
3084
3084
  await requireAgent(agent, { requireLinear: true });
3085
3085
  const adapter = getAdapter2(agent);
3086
3086
  if (!adapter.listLinearIssues) {
@@ -6795,7 +6795,7 @@ function formatScheduledPrompt(name, prompt) {
6795
6795
  ${prompt}`;
6796
6796
  }
6797
6797
  async function defaultDeps() {
6798
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-BYTSILLH.js");
6798
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-BF7TKSA2.js");
6799
6799
  const orch = getOrchestrator2();
6800
6800
  return {
6801
6801
  findThread: (id) => findThreadByRef(id),
@@ -7,7 +7,7 @@ import {
7
7
  loadBrightsyConfig,
8
8
  refreshBrightsyAccessToken,
9
9
  saveBrightsyConfig
10
- } from "./chunk-PXMLMBMI.js";
10
+ } from "./chunk-E63AM3PW.js";
11
11
  import {
12
12
  run
13
13
  } from "./chunk-2UG25RMK.js";
@@ -93,6 +93,25 @@ function listConnectedBrightsyTeams() {
93
93
  function getConnectedBrightsyTeamsRaw() {
94
94
  return readStore();
95
95
  }
96
+ function teamFromCliSession(cfg, current) {
97
+ return {
98
+ ...current,
99
+ access_token: cfg.access_token,
100
+ refresh_token: cfg.refresh_token ?? current.refresh_token,
101
+ expires_at: cfg.expires_at ?? current.expires_at,
102
+ endpoint: cfg.endpoint ?? current.endpoint,
103
+ oauth_client_id: cfg.oauth_client_id ?? current.oauth_client_id,
104
+ slug: cfg.account_slug || current.slug
105
+ };
106
+ }
107
+ function brightsySessionShouldReplace(a, b) {
108
+ if (!a.access_token) return false;
109
+ const aStale = brightsyAccessTokenNeedsRefresh(a.expires_at);
110
+ const bStale = !b.access_token || brightsyAccessTokenNeedsRefresh(b.expires_at);
111
+ if (!aStale && bStale) return true;
112
+ if (aStale) return false;
113
+ return (a.expires_at ?? 0) > (b.expires_at ?? 0);
114
+ }
96
115
  function applyConnectedTeamToCli(team) {
97
116
  let base = {};
98
117
  try {
@@ -179,22 +198,34 @@ async function ensureConnectedBrightsyTeamTokens(opts) {
179
198
  }
180
199
  next.push(refreshed);
181
200
  }
182
- if (changed) writeStore(next);
183
201
  try {
184
202
  const cfg2 = loadBrightsyConfig();
185
- const active = next.find((t) => t.id === cfg2.account_id);
186
- if (active && active.access_token !== cfg2.access_token) {
187
- applyConnectedTeamToCli(active);
203
+ const idx = next.findIndex((t) => t.id === cfg2.account_id);
204
+ if (idx >= 0) {
205
+ const active = next[idx];
206
+ if (brightsySessionShouldReplace(cfg2, active)) {
207
+ next[idx] = teamFromCliSession(cfg2, active);
208
+ changed = true;
209
+ } else if (active.access_token !== cfg2.access_token) {
210
+ applyConnectedTeamToCli(active);
211
+ }
188
212
  }
189
213
  } catch {
190
214
  }
215
+ if (changed) writeStore(next);
191
216
  return next;
192
217
  }
193
218
  function ensureCliTeamTracked(meta) {
194
219
  try {
195
220
  const cfg = loadBrightsyConfig();
196
221
  const existing = readStore();
197
- if (existing.some((t) => t.id === cfg.account_id)) {
222
+ const idx = existing.findIndex((t) => t.id === cfg.account_id);
223
+ if (idx >= 0) {
224
+ const current = existing[idx];
225
+ if (brightsySessionShouldReplace(cfg, current)) {
226
+ existing[idx] = teamFromCliSession(cfg, current);
227
+ writeStore(existing);
228
+ }
198
229
  return listConnectedBrightsyTeams();
199
230
  }
200
231
  const team = {
@@ -268,6 +299,7 @@ function brightsyMcpServerName(slug) {
268
299
  export {
269
300
  listConnectedBrightsyTeams,
270
301
  getConnectedBrightsyTeamsRaw,
302
+ brightsySessionShouldReplace,
271
303
  applyConnectedTeamToCli,
272
304
  ensureConnectedBrightsyTeamTokens,
273
305
  ensureCliTeamTracked,
@@ -3,14 +3,15 @@
3
3
  import {
4
4
  applyConnectedTeamToCli,
5
5
  brightsyMcpServerName,
6
+ brightsySessionShouldReplace,
6
7
  connectBrightsyTeam,
7
8
  disconnectBrightsyTeam,
8
9
  ensureCliTeamTracked,
9
10
  ensureConnectedBrightsyTeamTokens,
10
11
  getConnectedBrightsyTeamsRaw,
11
12
  listConnectedBrightsyTeams
12
- } from "./chunk-42JGPPVS.js";
13
- import "./chunk-PXMLMBMI.js";
13
+ } from "./chunk-V5BTGQ6M.js";
14
+ import "./chunk-E63AM3PW.js";
14
15
  import "./chunk-2GPQZZLY.js";
15
16
  import "./chunk-2UG25RMK.js";
16
17
  import "./chunk-WWUABK6B.js";
@@ -18,6 +19,7 @@ import "./chunk-WOU343SI.js";
18
19
  export {
19
20
  applyConnectedTeamToCli,
20
21
  brightsyMcpServerName,
22
+ brightsySessionShouldReplace,
21
23
  connectBrightsyTeam,
22
24
  disconnectBrightsyTeam,
23
25
  ensureCliTeamTracked,
@@ -1,14 +1,15 @@
1
1
  import {
2
2
  applyConnectedTeamToCli,
3
3
  brightsyMcpServerName,
4
+ brightsySessionShouldReplace,
4
5
  connectBrightsyTeam,
5
6
  disconnectBrightsyTeam,
6
7
  ensureCliTeamTracked,
7
8
  ensureConnectedBrightsyTeamTokens,
8
9
  getConnectedBrightsyTeamsRaw,
9
10
  listConnectedBrightsyTeams
10
- } from "./chunk-VEVFHO6K.js";
11
- import "./chunk-33KDPEK4.js";
11
+ } from "./chunk-HH3VVTEC.js";
12
+ import "./chunk-RSA47QYR.js";
12
13
  import "./chunk-JAT3JFOS.js";
13
14
  import "./chunk-QVN2WOKJ.js";
14
15
  import "./chunk-4TR3HZFT.js";
@@ -16,6 +17,7 @@ import "./chunk-H4UEFJRI.js";
16
17
  export {
17
18
  applyConnectedTeamToCli,
18
19
  brightsyMcpServerName,
20
+ brightsySessionShouldReplace,
19
21
  connectBrightsyTeam,
20
22
  disconnectBrightsyTeam,
21
23
  ensureCliTeamTracked,
package/dist/index.cjs CHANGED
@@ -12769,24 +12769,47 @@ var init_turn_trace = __esm({
12769
12769
  });
12770
12770
 
12771
12771
  // src/brightsy/config.ts
12772
+ function resolveBrightsyConfigFile(path2) {
12773
+ try {
12774
+ if ((0, import_node_fs27.existsSync)(path2) && (0, import_node_fs27.statSync)(path2).isDirectory()) {
12775
+ return (0, import_node_path31.join)(path2, "config.json");
12776
+ }
12777
+ } catch {
12778
+ }
12779
+ return path2;
12780
+ }
12772
12781
  function brightsyConfigPath() {
12773
12782
  const override = process.env.BRIGHTSY_CONFIG?.trim();
12774
- if (override) return override;
12775
- return (0, import_node_path31.join)((0, import_node_os10.homedir)(), ".brightsy", "config.json");
12783
+ const raw = override || (0, import_node_path31.join)((0, import_node_os10.homedir)(), ".brightsy", "config.json");
12784
+ return resolveBrightsyConfigFile(raw);
12776
12785
  }
12777
12786
  function loadBrightsyConfig() {
12778
12787
  const path2 = brightsyConfigPath();
12779
12788
  if (!(0, import_node_fs27.existsSync)(path2)) {
12780
12789
  throw new Error("Brightsy not logged in \u2014 run `brightsy login` first");
12781
12790
  }
12782
- const raw = JSON.parse((0, import_node_fs27.readFileSync)(path2, "utf8"));
12791
+ let text7;
12792
+ try {
12793
+ text7 = (0, import_node_fs27.readFileSync)(path2, "utf8");
12794
+ } catch (err) {
12795
+ const code = err && typeof err === "object" && "code" in err ? String(err.code) : "";
12796
+ if (code === "EISDIR") {
12797
+ throw new Error(
12798
+ `Brightsy config is a directory (${path2}) \u2014 expected ~/.brightsy/config.json`
12799
+ );
12800
+ }
12801
+ throw err;
12802
+ }
12803
+ const raw = JSON.parse(text7);
12783
12804
  if (!raw.access_token || !raw.account_id) {
12784
12805
  throw new Error("Brightsy config incomplete \u2014 run `brightsy login`");
12785
12806
  }
12786
12807
  return raw;
12787
12808
  }
12788
12809
  function saveBrightsyConfig(cfg) {
12789
- (0, import_node_fs27.writeFileSync)(brightsyConfigPath(), `${JSON.stringify(cfg, null, 2)}
12810
+ const path2 = brightsyConfigPath();
12811
+ (0, import_node_fs27.mkdirSync)((0, import_node_path31.dirname)(path2), { recursive: true });
12812
+ (0, import_node_fs27.writeFileSync)(path2, `${JSON.stringify(cfg, null, 2)}
12790
12813
  `, {
12791
12814
  mode: 384
12792
12815
  });
@@ -13110,6 +13133,7 @@ var connected_teams_exports = {};
13110
13133
  __export(connected_teams_exports, {
13111
13134
  applyConnectedTeamToCli: () => applyConnectedTeamToCli,
13112
13135
  brightsyMcpServerName: () => brightsyMcpServerName,
13136
+ brightsySessionShouldReplace: () => brightsySessionShouldReplace,
13113
13137
  connectBrightsyTeam: () => connectBrightsyTeam,
13114
13138
  disconnectBrightsyTeam: () => disconnectBrightsyTeam,
13115
13139
  ensureCliTeamTracked: () => ensureCliTeamTracked,
@@ -13150,6 +13174,25 @@ function listConnectedBrightsyTeams() {
13150
13174
  function getConnectedBrightsyTeamsRaw() {
13151
13175
  return readStore();
13152
13176
  }
13177
+ function teamFromCliSession(cfg, current) {
13178
+ return {
13179
+ ...current,
13180
+ access_token: cfg.access_token,
13181
+ refresh_token: cfg.refresh_token ?? current.refresh_token,
13182
+ expires_at: cfg.expires_at ?? current.expires_at,
13183
+ endpoint: cfg.endpoint ?? current.endpoint,
13184
+ oauth_client_id: cfg.oauth_client_id ?? current.oauth_client_id,
13185
+ slug: cfg.account_slug || current.slug
13186
+ };
13187
+ }
13188
+ function brightsySessionShouldReplace(a, b) {
13189
+ if (!a.access_token) return false;
13190
+ const aStale = brightsyAccessTokenNeedsRefresh(a.expires_at);
13191
+ const bStale = !b.access_token || brightsyAccessTokenNeedsRefresh(b.expires_at);
13192
+ if (!aStale && bStale) return true;
13193
+ if (aStale) return false;
13194
+ return (a.expires_at ?? 0) > (b.expires_at ?? 0);
13195
+ }
13153
13196
  function applyConnectedTeamToCli(team) {
13154
13197
  let base = {};
13155
13198
  try {
@@ -13236,22 +13279,34 @@ async function ensureConnectedBrightsyTeamTokens(opts) {
13236
13279
  }
13237
13280
  next.push(refreshed);
13238
13281
  }
13239
- if (changed) writeStore(next);
13240
13282
  try {
13241
13283
  const cfg2 = loadBrightsyConfig();
13242
- const active = next.find((t) => t.id === cfg2.account_id);
13243
- if (active && active.access_token !== cfg2.access_token) {
13244
- applyConnectedTeamToCli(active);
13284
+ const idx = next.findIndex((t) => t.id === cfg2.account_id);
13285
+ if (idx >= 0) {
13286
+ const active = next[idx];
13287
+ if (brightsySessionShouldReplace(cfg2, active)) {
13288
+ next[idx] = teamFromCliSession(cfg2, active);
13289
+ changed = true;
13290
+ } else if (active.access_token !== cfg2.access_token) {
13291
+ applyConnectedTeamToCli(active);
13292
+ }
13245
13293
  }
13246
13294
  } catch {
13247
13295
  }
13296
+ if (changed) writeStore(next);
13248
13297
  return next;
13249
13298
  }
13250
13299
  function ensureCliTeamTracked(meta) {
13251
13300
  try {
13252
13301
  const cfg = loadBrightsyConfig();
13253
13302
  const existing = readStore();
13254
- if (existing.some((t) => t.id === cfg.account_id)) {
13303
+ const idx = existing.findIndex((t) => t.id === cfg.account_id);
13304
+ if (idx >= 0) {
13305
+ const current = existing[idx];
13306
+ if (brightsySessionShouldReplace(cfg, current)) {
13307
+ existing[idx] = teamFromCliSession(cfg, current);
13308
+ writeStore(existing);
13309
+ }
13255
13310
  return listConnectedBrightsyTeams();
13256
13311
  }
13257
13312
  const team = {
package/dist/index.js CHANGED
@@ -202,7 +202,7 @@ import {
202
202
  worktreeCleanupSettings,
203
203
  writeAgentBlock,
204
204
  writeWorktreeFile
205
- } from "./chunk-VIVXKN5N.js";
205
+ } from "./chunk-U3J2YY4T.js";
206
206
  import {
207
207
  LEGACY_PLAN_FILE_REL,
208
208
  PLAN_FILE_NAME,
@@ -292,7 +292,7 @@ import {
292
292
  userMcpNamesToDisable,
293
293
  worktreeMcpToolNames,
294
294
  writeInjectedMcpConfig
295
- } from "./chunk-4FZUUH6W.js";
295
+ } from "./chunk-TDXORDN6.js";
296
296
  import {
297
297
  brightsyMcpServerName,
298
298
  connectBrightsyTeam,
@@ -302,7 +302,7 @@ import {
302
302
  listBrightsyAccounts,
303
303
  listConnectedBrightsyTeams,
304
304
  switchBrightsyAccount
305
- } from "./chunk-VEVFHO6K.js";
305
+ } from "./chunk-HH3VVTEC.js";
306
306
  import {
307
307
  BRIGHTSY_SUMMARIZE_CONTEXT_TOOL,
308
308
  CHARS_PER_CONTEXT_TOKEN,
@@ -758,7 +758,7 @@ import {
758
758
  refreshBrightsyAccessToken,
759
759
  registerBrightsyOAuthClient,
760
760
  saveBrightsyConfig
761
- } from "./chunk-33KDPEK4.js";
761
+ } from "./chunk-RSA47QYR.js";
762
762
  import {
763
763
  currentHttpFetch,
764
764
  formatFetchError,
@@ -8727,7 +8727,7 @@ async function startHeadlessHost(opts) {
8727
8727
  };
8728
8728
  const refreshRunning = async () => {
8729
8729
  try {
8730
- const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-BYTSILLH.js");
8730
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-BF7TKSA2.js");
8731
8731
  agentsRunning = getOrchestrator2().getRuntime().running;
8732
8732
  } catch {
8733
8733
  agentsRunning = 0;
@@ -10659,7 +10659,7 @@ async function handleJobStop(params, _ctx) {
10659
10659
  return stopDetachedJob(jobCwd(rec), id, reason ? { reason } : void 0);
10660
10660
  }
10661
10661
  async function defaultTurnWait(ref, timeoutMs) {
10662
- const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-BYTSILLH.js");
10662
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-BF7TKSA2.js");
10663
10663
  const orch = getOrchestrator2();
10664
10664
  const thread = await orch.waitForTurn(ref, timeoutMs, {
10665
10665
  resolveIfStillRunning: true
@@ -14035,7 +14035,7 @@ async function continueSourceThread(threadId, prompt) {
14035
14035
  await continueOnReply(threadId, prompt);
14036
14036
  return;
14037
14037
  }
14038
- const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-BYTSILLH.js");
14038
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-BF7TKSA2.js");
14039
14039
  await getOrchestrator2().send(threadId, prompt);
14040
14040
  } catch {
14041
14041
  }
@@ -10516,24 +10516,47 @@ var init_turn_trace = __esm({
10516
10516
  });
10517
10517
 
10518
10518
  // src/brightsy/config.ts
10519
+ function resolveBrightsyConfigFile(path) {
10520
+ try {
10521
+ if ((0, import_node_fs23.existsSync)(path) && (0, import_node_fs23.statSync)(path).isDirectory()) {
10522
+ return (0, import_node_path26.join)(path, "config.json");
10523
+ }
10524
+ } catch {
10525
+ }
10526
+ return path;
10527
+ }
10519
10528
  function brightsyConfigPath() {
10520
10529
  const override = process.env.BRIGHTSY_CONFIG?.trim();
10521
- if (override) return override;
10522
- return (0, import_node_path26.join)((0, import_node_os9.homedir)(), ".brightsy", "config.json");
10530
+ const raw = override || (0, import_node_path26.join)((0, import_node_os9.homedir)(), ".brightsy", "config.json");
10531
+ return resolveBrightsyConfigFile(raw);
10523
10532
  }
10524
10533
  function loadBrightsyConfig() {
10525
10534
  const path = brightsyConfigPath();
10526
10535
  if (!(0, import_node_fs23.existsSync)(path)) {
10527
10536
  throw new Error("Brightsy not logged in \u2014 run `brightsy login` first");
10528
10537
  }
10529
- const raw = JSON.parse((0, import_node_fs23.readFileSync)(path, "utf8"));
10538
+ let text7;
10539
+ try {
10540
+ text7 = (0, import_node_fs23.readFileSync)(path, "utf8");
10541
+ } catch (err) {
10542
+ const code = err && typeof err === "object" && "code" in err ? String(err.code) : "";
10543
+ if (code === "EISDIR") {
10544
+ throw new Error(
10545
+ `Brightsy config is a directory (${path}) \u2014 expected ~/.brightsy/config.json`
10546
+ );
10547
+ }
10548
+ throw err;
10549
+ }
10550
+ const raw = JSON.parse(text7);
10530
10551
  if (!raw.access_token || !raw.account_id) {
10531
10552
  throw new Error("Brightsy config incomplete \u2014 run `brightsy login`");
10532
10553
  }
10533
10554
  return raw;
10534
10555
  }
10535
10556
  function saveBrightsyConfig(cfg) {
10536
- (0, import_node_fs23.writeFileSync)(brightsyConfigPath(), `${JSON.stringify(cfg, null, 2)}
10557
+ const path = brightsyConfigPath();
10558
+ (0, import_node_fs23.mkdirSync)((0, import_node_path26.dirname)(path), { recursive: true });
10559
+ (0, import_node_fs23.writeFileSync)(path, `${JSON.stringify(cfg, null, 2)}
10537
10560
  `, {
10538
10561
  mode: 384
10539
10562
  });
@@ -10788,6 +10811,25 @@ function listConnectedBrightsyTeams() {
10788
10811
  expires_at
10789
10812
  }));
10790
10813
  }
10814
+ function teamFromCliSession(cfg, current) {
10815
+ return {
10816
+ ...current,
10817
+ access_token: cfg.access_token,
10818
+ refresh_token: cfg.refresh_token ?? current.refresh_token,
10819
+ expires_at: cfg.expires_at ?? current.expires_at,
10820
+ endpoint: cfg.endpoint ?? current.endpoint,
10821
+ oauth_client_id: cfg.oauth_client_id ?? current.oauth_client_id,
10822
+ slug: cfg.account_slug || current.slug
10823
+ };
10824
+ }
10825
+ function brightsySessionShouldReplace(a, b) {
10826
+ if (!a.access_token) return false;
10827
+ const aStale = brightsyAccessTokenNeedsRefresh(a.expires_at);
10828
+ const bStale = !b.access_token || brightsyAccessTokenNeedsRefresh(b.expires_at);
10829
+ if (!aStale && bStale) return true;
10830
+ if (aStale) return false;
10831
+ return (a.expires_at ?? 0) > (b.expires_at ?? 0);
10832
+ }
10791
10833
  function applyConnectedTeamToCli(team) {
10792
10834
  let base = {};
10793
10835
  try {
@@ -10874,22 +10916,34 @@ async function ensureConnectedBrightsyTeamTokens(opts) {
10874
10916
  }
10875
10917
  next.push(refreshed);
10876
10918
  }
10877
- if (changed) writeStore(next);
10878
10919
  try {
10879
10920
  const cfg2 = loadBrightsyConfig();
10880
- const active = next.find((t) => t.id === cfg2.account_id);
10881
- if (active && active.access_token !== cfg2.access_token) {
10882
- applyConnectedTeamToCli(active);
10921
+ const idx = next.findIndex((t) => t.id === cfg2.account_id);
10922
+ if (idx >= 0) {
10923
+ const active = next[idx];
10924
+ if (brightsySessionShouldReplace(cfg2, active)) {
10925
+ next[idx] = teamFromCliSession(cfg2, active);
10926
+ changed = true;
10927
+ } else if (active.access_token !== cfg2.access_token) {
10928
+ applyConnectedTeamToCli(active);
10929
+ }
10883
10930
  }
10884
10931
  } catch {
10885
10932
  }
10933
+ if (changed) writeStore(next);
10886
10934
  return next;
10887
10935
  }
10888
10936
  function ensureCliTeamTracked(meta) {
10889
10937
  try {
10890
10938
  const cfg = loadBrightsyConfig();
10891
10939
  const existing = readStore();
10892
- if (existing.some((t) => t.id === cfg.account_id)) {
10940
+ const idx = existing.findIndex((t) => t.id === cfg.account_id);
10941
+ if (idx >= 0) {
10942
+ const current = existing[idx];
10943
+ if (brightsySessionShouldReplace(cfg, current)) {
10944
+ existing[idx] = teamFromCliSession(cfg, current);
10945
+ writeStore(existing);
10946
+ }
10893
10947
  return listConnectedBrightsyTeams();
10894
10948
  }
10895
10949
  const team = {
@@ -56,7 +56,7 @@ import {
56
56
  updateSchedule,
57
57
  workspaceTagTargetRef,
58
58
  writeAgentBlock
59
- } from "../chunk-LLTWP4PK.js";
59
+ } from "../chunk-E2NJ6RH7.js";
60
60
  import "../chunk-LX5R5JOR.js";
61
61
  import {
62
62
  commentAbleTimeTask,
@@ -97,10 +97,10 @@ import {
97
97
  shouldRegisterMcpWaitForTurn,
98
98
  sideboardMcpProfile,
99
99
  worktreeMcpToolNames
100
- } from "../chunk-2P2HYXA2.js";
100
+ } from "../chunk-2JOBQUUS.js";
101
101
  import "../chunk-EGTCXNQM.js";
102
- import "../chunk-42JGPPVS.js";
103
- import "../chunk-PXMLMBMI.js";
102
+ import "../chunk-V5BTGQ6M.js";
103
+ import "../chunk-E63AM3PW.js";
104
104
  import {
105
105
  httpFetch
106
106
  } from "../chunk-2GPQZZLY.js";
@@ -9,7 +9,7 @@ import {
9
9
  normalizeBrightsyEndpoint,
10
10
  refreshBrightsyAccessToken,
11
11
  registerBrightsyOAuthClient
12
- } from "./chunk-PXMLMBMI.js";
12
+ } from "./chunk-E63AM3PW.js";
13
13
  import "./chunk-2GPQZZLY.js";
14
14
  export {
15
15
  BRIGHTSY_OAUTH_CLIENT_ID,
@@ -7,7 +7,7 @@ import {
7
7
  normalizeBrightsyEndpoint,
8
8
  refreshBrightsyAccessToken,
9
9
  registerBrightsyOAuthClient
10
- } from "./chunk-33KDPEK4.js";
10
+ } from "./chunk-RSA47QYR.js";
11
11
  import "./chunk-JAT3JFOS.js";
12
12
  export {
13
13
  BRIGHTSY_OAUTH_CLIENT_ID,
@@ -9,10 +9,10 @@ import {
9
9
  resolveSendFollowUp,
10
10
  startOrchestration,
11
11
  waitForPidExit
12
- } from "./chunk-VIVXKN5N.js";
12
+ } from "./chunk-U3J2YY4T.js";
13
13
  import "./chunk-PGPSIEMW.js";
14
- import "./chunk-4FZUUH6W.js";
15
- import "./chunk-VEVFHO6K.js";
14
+ import "./chunk-TDXORDN6.js";
15
+ import "./chunk-HH3VVTEC.js";
16
16
  import "./chunk-QC2TQMPJ.js";
17
17
  import "./chunk-7Q327QF2.js";
18
18
  import "./chunk-7H655NEW.js";
@@ -22,7 +22,7 @@ import "./chunk-5QX2NYXL.js";
22
22
  import "./chunk-BIPXOHZI.js";
23
23
  import "./chunk-HG25AYBV.js";
24
24
  import "./chunk-2P4XKWV2.js";
25
- import "./chunk-33KDPEK4.js";
25
+ import "./chunk-RSA47QYR.js";
26
26
  import "./chunk-JAT3JFOS.js";
27
27
  import "./chunk-F2PVRF3B.js";
28
28
  import "./chunk-AXQ4ZWHK.js";
@@ -11,15 +11,15 @@ import {
11
11
  resolveSendFollowUp,
12
12
  startOrchestration,
13
13
  waitForPidExit
14
- } from "./chunk-LLTWP4PK.js";
14
+ } from "./chunk-E2NJ6RH7.js";
15
15
  import "./chunk-LX5R5JOR.js";
16
16
  import "./chunk-62ESCTJ4.js";
17
17
  import "./chunk-4GK32AYX.js";
18
18
  import "./chunk-DC3VZXMA.js";
19
- import "./chunk-2P2HYXA2.js";
19
+ import "./chunk-2JOBQUUS.js";
20
20
  import "./chunk-EGTCXNQM.js";
21
- import "./chunk-42JGPPVS.js";
22
- import "./chunk-PXMLMBMI.js";
21
+ import "./chunk-V5BTGQ6M.js";
22
+ import "./chunk-E63AM3PW.js";
23
23
  import "./chunk-2GPQZZLY.js";
24
24
  import "./chunk-ZW7RSQHY.js";
25
25
  import "./chunk-I5TESHDN.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sideboard-ai/core",
3
- "version": "0.1.312",
3
+ "version": "0.1.313",
4
4
  "description": "Sideboard core — orchestration, agents, git worktrees, MCP server",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",