@sideboard-ai/core 0.1.77 → 0.1.81

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 (31) hide show
  1. package/dist/{agents-LKUHPPEQ.js → agents-EBKJ55PN.js} +5 -5
  2. package/dist/{agents-XJV6J3K2.js → agents-UQ7D6U6L.js} +6 -6
  3. package/dist/{app-settings-3TLA2EJ7.js → app-settings-6IOQYGBK.js} +7 -1
  4. package/dist/{app-settings-P42Z3VOB.js → app-settings-NILNWNNQ.js} +7 -1
  5. package/dist/{chunk-2FJI5JXX.js → chunk-4AVU4QXO.js} +54 -20
  6. package/dist/{chunk-XJNCWYFR.js → chunk-4HJK57XU.js} +8 -14
  7. package/dist/{chunk-VERLUKN2.js → chunk-6F2TQFJE.js} +6 -6
  8. package/dist/{chunk-EEKSZTMU.js → chunk-CQBQWX73.js} +10 -16
  9. package/dist/{chunk-OE7YBB5X.js → chunk-FUUVPN4A.js} +108 -3
  10. package/dist/{chunk-W7YOTDVO.js → chunk-IFPN6TER.js} +47 -2
  11. package/dist/{chunk-75U65MBE.js → chunk-K553XK7M.js} +2 -2
  12. package/dist/{chunk-GWTLKXXP.js → chunk-P5VDPGAN.js} +3 -3
  13. package/dist/{chunk-2ZIPJRJE.js → chunk-TDJ43HUD.js} +2 -2
  14. package/dist/{chunk-PTJJIQK7.js → chunk-XKNBSYA7.js} +47 -2
  15. package/dist/{chunk-QD37IILI.js → chunk-XNECBC6T.js} +66 -20
  16. package/dist/{chunk-MF2YMEGD.js → chunk-YVVXWWCC.js} +110 -3
  17. package/dist/{coordinator-prompt-LLFJUO2R.js → coordinator-prompt-JQF72JKX.js} +4 -4
  18. package/dist/{coordinator-prompt-MRCMMRSF.js → coordinator-prompt-NYNEFKIV.js} +3 -3
  19. package/dist/{global-workspace-YNMNO4CL.js → global-workspace-DZM4ZFGU.js} +5 -5
  20. package/dist/{global-workspace-TWHMYLTZ.js → global-workspace-NUMUJRWG.js} +4 -4
  21. package/dist/index.cjs +585 -251
  22. package/dist/index.d.cts +97 -8
  23. package/dist/index.d.ts +97 -8
  24. package/dist/index.js +363 -222
  25. package/dist/mcp/run-stdio.cjs +2502 -2286
  26. package/dist/mcp/run-stdio.js +162 -133
  27. package/dist/{workspaces-O3U5BENH.js → workspaces-QLRCOXAY.js} +6 -6
  28. package/dist/{workspaces-GQ4XKBD3.js → workspaces-SUU2GO3A.js} +5 -5
  29. package/dist/{worktree-VOCH3WS3.js → worktree-5VLLFI5W.js} +5 -1
  30. package/dist/{worktree-KWXHMKRN.js → worktree-UNSOCYZU.js} +5 -1
  31. package/package.json +1 -1
@@ -187,6 +187,9 @@ function normalizeVault(raw) {
187
187
  if (typeof raw.slackAppToken === "string" && raw.slackAppToken.trim()) {
188
188
  out.slackAppToken = raw.slackAppToken.trim();
189
189
  }
190
+ if (typeof raw.githubPat === "string" && raw.githubPat.trim()) {
191
+ out.githubPat = raw.githubPat.trim();
192
+ }
190
193
  if (raw.environment && typeof raw.environment === "object") {
191
194
  const environment = {};
192
195
  for (const [key, value] of Object.entries(raw.environment)) {
@@ -214,6 +217,7 @@ var DEFAULT_AGENTS = /* @__PURE__ */ new Set([
214
217
  "brightsy",
215
218
  "cursor"
216
219
  ]);
220
+ var GITHUB_GIT_AUTH_MODES = ["auto", "gh", "ssh", "token"];
217
221
  function hasLinearOAuth(integrations) {
218
222
  return Boolean(
219
223
  integrations.linearAccessToken?.trim() || integrations.linearRefreshToken?.trim()
@@ -230,12 +234,14 @@ function toPublicAppSettings(settings) {
230
234
  const integrations = { ...settings.integrations };
231
235
  const slackClientSecret = integrations.slackClientSecret;
232
236
  const slackAppToken = integrations.slackAppToken;
237
+ const githubPat = integrations.githubPat;
233
238
  delete integrations.linearApiKey;
234
239
  delete integrations.linearAccessToken;
235
240
  delete integrations.linearRefreshToken;
236
241
  delete integrations.linearClientSecret;
237
242
  delete integrations.slackClientSecret;
238
243
  delete integrations.slackAppToken;
244
+ delete integrations.githubPat;
239
245
  return {
240
246
  ...settings,
241
247
  environment,
@@ -244,7 +250,8 @@ function toPublicAppSettings(settings) {
244
250
  hasLinearApiKey: hasLinearCredentials(settings.integrations),
245
251
  hasLinearOAuth: hasLinearOAuth(settings.integrations),
246
252
  hasSlackClientSecret: Boolean(slackClientSecret?.trim()),
247
- hasSlackAppToken: Boolean(slackAppToken?.trim())
253
+ hasSlackAppToken: Boolean(slackAppToken?.trim()),
254
+ hasGithubPat: Boolean(githubPat?.trim())
248
255
  }
249
256
  };
250
257
  }
@@ -303,6 +310,7 @@ function normalizeBrightsy(raw) {
303
310
  return out;
304
311
  }
305
312
  var ISSUE_SOURCES = /* @__PURE__ */ new Set(["linear", "github"]);
313
+ var GIT_AUTH_MODES = new Set(GITHUB_GIT_AUTH_MODES);
306
314
  function normalizeIntegrations(raw) {
307
315
  if (!raw || typeof raw !== "object") return {};
308
316
  const source = raw;
@@ -367,6 +375,13 @@ function normalizeIntegrations(raw) {
367
375
  const label = source.slackDeviceLabel.trim().slice(0, 64);
368
376
  if (label) out.slackDeviceLabel = label;
369
377
  }
378
+ if (typeof source.githubGitAuthMode === "string" && GIT_AUTH_MODES.has(source.githubGitAuthMode)) {
379
+ out.githubGitAuthMode = source.githubGitAuthMode;
380
+ }
381
+ if (typeof source.githubPat === "string") {
382
+ const pat = source.githubPat.trim();
383
+ if (pat) out.githubPat = pat;
384
+ }
370
385
  return out;
371
386
  }
372
387
  function normalizeDefaults(raw) {
@@ -516,7 +531,7 @@ function readSettingsFile() {
516
531
  }
517
532
  function diskHoldsSecrets(disk) {
518
533
  return Boolean(
519
- disk.integrations.linearApiKey || disk.integrations.linearAccessToken || disk.integrations.linearRefreshToken || disk.integrations.linearClientSecret || disk.integrations.slackClientSecret || disk.integrations.slackAppToken || Object.keys(disk.environment).length > 0
534
+ disk.integrations.linearApiKey || disk.integrations.linearAccessToken || disk.integrations.linearRefreshToken || disk.integrations.linearClientSecret || disk.integrations.slackClientSecret || disk.integrations.slackAppToken || disk.integrations.githubPat || Object.keys(disk.environment).length > 0
520
535
  );
521
536
  }
522
537
  function mergeVault(disk) {
@@ -541,6 +556,9 @@ function mergeVault(disk) {
541
556
  if (vault.slackAppToken && !integrations.slackAppToken) {
542
557
  integrations.slackAppToken = vault.slackAppToken;
543
558
  }
559
+ if (vault.githubPat && !integrations.githubPat) {
560
+ integrations.githubPat = vault.githubPat;
561
+ }
544
562
  return { ...disk, environment, integrations };
545
563
  }
546
564
  function persistSplit(settings) {
@@ -551,12 +569,14 @@ function persistSplit(settings) {
551
569
  const linearClientSecret = integrations.linearClientSecret;
552
570
  const slackClientSecret = integrations.slackClientSecret;
553
571
  const slackAppToken = integrations.slackAppToken;
572
+ const githubPat = integrations.githubPat;
554
573
  delete integrations.linearApiKey;
555
574
  delete integrations.linearAccessToken;
556
575
  delete integrations.linearRefreshToken;
557
576
  delete integrations.linearClientSecret;
558
577
  delete integrations.slackClientSecret;
559
578
  delete integrations.slackAppToken;
579
+ delete integrations.githubPat;
560
580
  writePrivateFile(
561
581
  appSettingsPath(),
562
582
  `${JSON.stringify({ ...settings, environment: {}, integrations }, null, 2)}
@@ -569,6 +589,7 @@ function persistSplit(settings) {
569
589
  linearClientSecret,
570
590
  slackClientSecret,
571
591
  slackAppToken,
592
+ githubPat,
572
593
  environment: settings.environment
573
594
  });
574
595
  }
@@ -734,6 +755,20 @@ function updateIntegrationsSettings(patch) {
734
755
  integrations.slackDeviceLabel = patch.slackDeviceLabel.trim().slice(0, 64);
735
756
  }
736
757
  }
758
+ if ("githubGitAuthMode" in patch) {
759
+ if (patch.githubGitAuthMode == null) {
760
+ delete integrations.githubGitAuthMode;
761
+ } else if (GIT_AUTH_MODES.has(patch.githubGitAuthMode)) {
762
+ integrations.githubGitAuthMode = patch.githubGitAuthMode;
763
+ }
764
+ }
765
+ if ("githubPat" in patch) {
766
+ if (patch.githubPat == null || patch.githubPat.trim() === "") {
767
+ delete integrations.githubPat;
768
+ } else {
769
+ integrations.githubPat = patch.githubPat.trim();
770
+ }
771
+ }
737
772
  return saveAppSettings({ ...current, integrations });
738
773
  }
739
774
  function updateDefaultsSettings(patch) {
@@ -841,6 +876,13 @@ function disconnectLinearConnection() {
841
876
  function getIssueSource(settings = loadAppSettings()) {
842
877
  return settings.integrations.issueSource ?? "github";
843
878
  }
879
+ function getGithubGitAuthMode(settings = loadAppSettings()) {
880
+ return settings.integrations.githubGitAuthMode ?? "auto";
881
+ }
882
+ function getGithubPat(settings = loadAppSettings()) {
883
+ const pat = settings.integrations.githubPat?.trim();
884
+ return pat || null;
885
+ }
844
886
  function resolveEffectiveIssueSource(settings = loadAppSettings()) {
845
887
  const preferred = getIssueSource(settings);
846
888
  if (preferred === "linear" && !isLinearConnected(settings)) return "github";
@@ -1058,6 +1100,7 @@ export {
1058
1100
  isSecureFileEncrypted,
1059
1101
  secureFileUnlocksWith,
1060
1102
  HARNESS_ENV_KEYS,
1103
+ GITHUB_GIT_AUTH_MODES,
1061
1104
  toPublicAppSettings,
1062
1105
  appSettingsPath,
1063
1106
  claudeUserSettingsPath,
@@ -1080,6 +1123,8 @@ export {
1080
1123
  saveLinearOAuth,
1081
1124
  disconnectLinearConnection,
1082
1125
  getIssueSource,
1126
+ getGithubGitAuthMode,
1127
+ getGithubPat,
1083
1128
  resolveEffectiveIssueSource,
1084
1129
  getLinearApiKey,
1085
1130
  brightsyCloudConnectEnabled,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  isGlobalRepoPath
3
- } from "./chunk-VERLUKN2.js";
3
+ } from "./chunk-6F2TQFJE.js";
4
4
  import {
5
5
  ensureGhPreferOrigin,
6
6
  resolveRepoRoot
7
- } from "./chunk-MF2YMEGD.js";
7
+ } from "./chunk-YVVXWWCC.js";
8
8
  import {
9
9
  appDataDir
10
10
  } from "./chunk-M37RITA6.js";
@@ -2,12 +2,12 @@
2
2
 
3
3
  import {
4
4
  ensureGlobalCoordinatorCwd
5
- } from "./chunk-XJNCWYFR.js";
5
+ } from "./chunk-4HJK57XU.js";
6
6
  import {
7
7
  allocateTeamName,
8
8
  takenSlugsFromThread,
9
9
  teamSlugFromName
10
- } from "./chunk-OE7YBB5X.js";
10
+ } from "./chunk-FUUVPN4A.js";
11
11
  import {
12
12
  createEmptyThread,
13
13
  listThreads,
@@ -17,7 +17,7 @@ import {
17
17
  import {
18
18
  resolveNewThreadOptions,
19
19
  resolveThreadDefaults
20
- } from "./chunk-PTJJIQK7.js";
20
+ } from "./chunk-XKNBSYA7.js";
21
21
  import {
22
22
  globalAgentCwd
23
23
  } from "./chunk-7MV3RXSC.js";
@@ -2,11 +2,11 @@
2
2
 
3
3
  import {
4
4
  isGlobalRepoPath
5
- } from "./chunk-GWTLKXXP.js";
5
+ } from "./chunk-P5VDPGAN.js";
6
6
  import {
7
7
  ensureGhPreferOrigin,
8
8
  resolveRepoRoot
9
- } from "./chunk-OE7YBB5X.js";
9
+ } from "./chunk-FUUVPN4A.js";
10
10
  import {
11
11
  appDataDir
12
12
  } from "./chunk-7MV3RXSC.js";
@@ -172,6 +172,9 @@ function normalizeVault(raw) {
172
172
  if (typeof raw.slackAppToken === "string" && raw.slackAppToken.trim()) {
173
173
  out.slackAppToken = raw.slackAppToken.trim();
174
174
  }
175
+ if (typeof raw.githubPat === "string" && raw.githubPat.trim()) {
176
+ out.githubPat = raw.githubPat.trim();
177
+ }
175
178
  if (raw.environment && typeof raw.environment === "object") {
176
179
  const environment = {};
177
180
  for (const [key, value] of Object.entries(raw.environment)) {
@@ -199,6 +202,7 @@ var DEFAULT_AGENTS = /* @__PURE__ */ new Set([
199
202
  "brightsy",
200
203
  "cursor"
201
204
  ]);
205
+ var GITHUB_GIT_AUTH_MODES = ["auto", "gh", "ssh", "token"];
202
206
  function hasLinearOAuth(integrations) {
203
207
  return Boolean(
204
208
  integrations.linearAccessToken?.trim() || integrations.linearRefreshToken?.trim()
@@ -215,12 +219,14 @@ function toPublicAppSettings(settings) {
215
219
  const integrations = { ...settings.integrations };
216
220
  const slackClientSecret = integrations.slackClientSecret;
217
221
  const slackAppToken = integrations.slackAppToken;
222
+ const githubPat = integrations.githubPat;
218
223
  delete integrations.linearApiKey;
219
224
  delete integrations.linearAccessToken;
220
225
  delete integrations.linearRefreshToken;
221
226
  delete integrations.linearClientSecret;
222
227
  delete integrations.slackClientSecret;
223
228
  delete integrations.slackAppToken;
229
+ delete integrations.githubPat;
224
230
  return {
225
231
  ...settings,
226
232
  environment,
@@ -229,7 +235,8 @@ function toPublicAppSettings(settings) {
229
235
  hasLinearApiKey: hasLinearCredentials(settings.integrations),
230
236
  hasLinearOAuth: hasLinearOAuth(settings.integrations),
231
237
  hasSlackClientSecret: Boolean(slackClientSecret?.trim()),
232
- hasSlackAppToken: Boolean(slackAppToken?.trim())
238
+ hasSlackAppToken: Boolean(slackAppToken?.trim()),
239
+ hasGithubPat: Boolean(githubPat?.trim())
233
240
  }
234
241
  };
235
242
  }
@@ -288,6 +295,7 @@ function normalizeBrightsy(raw) {
288
295
  return out;
289
296
  }
290
297
  var ISSUE_SOURCES = /* @__PURE__ */ new Set(["linear", "github"]);
298
+ var GIT_AUTH_MODES = new Set(GITHUB_GIT_AUTH_MODES);
291
299
  function normalizeIntegrations(raw) {
292
300
  if (!raw || typeof raw !== "object") return {};
293
301
  const source = raw;
@@ -352,6 +360,13 @@ function normalizeIntegrations(raw) {
352
360
  const label = source.slackDeviceLabel.trim().slice(0, 64);
353
361
  if (label) out.slackDeviceLabel = label;
354
362
  }
363
+ if (typeof source.githubGitAuthMode === "string" && GIT_AUTH_MODES.has(source.githubGitAuthMode)) {
364
+ out.githubGitAuthMode = source.githubGitAuthMode;
365
+ }
366
+ if (typeof source.githubPat === "string") {
367
+ const pat = source.githubPat.trim();
368
+ if (pat) out.githubPat = pat;
369
+ }
355
370
  return out;
356
371
  }
357
372
  function normalizeDefaults(raw) {
@@ -501,7 +516,7 @@ function readSettingsFile() {
501
516
  }
502
517
  function diskHoldsSecrets(disk) {
503
518
  return Boolean(
504
- disk.integrations.linearApiKey || disk.integrations.linearAccessToken || disk.integrations.linearRefreshToken || disk.integrations.linearClientSecret || disk.integrations.slackClientSecret || disk.integrations.slackAppToken || Object.keys(disk.environment).length > 0
519
+ disk.integrations.linearApiKey || disk.integrations.linearAccessToken || disk.integrations.linearRefreshToken || disk.integrations.linearClientSecret || disk.integrations.slackClientSecret || disk.integrations.slackAppToken || disk.integrations.githubPat || Object.keys(disk.environment).length > 0
505
520
  );
506
521
  }
507
522
  function mergeVault(disk) {
@@ -526,6 +541,9 @@ function mergeVault(disk) {
526
541
  if (vault.slackAppToken && !integrations.slackAppToken) {
527
542
  integrations.slackAppToken = vault.slackAppToken;
528
543
  }
544
+ if (vault.githubPat && !integrations.githubPat) {
545
+ integrations.githubPat = vault.githubPat;
546
+ }
529
547
  return { ...disk, environment, integrations };
530
548
  }
531
549
  function persistSplit(settings) {
@@ -536,12 +554,14 @@ function persistSplit(settings) {
536
554
  const linearClientSecret = integrations.linearClientSecret;
537
555
  const slackClientSecret = integrations.slackClientSecret;
538
556
  const slackAppToken = integrations.slackAppToken;
557
+ const githubPat = integrations.githubPat;
539
558
  delete integrations.linearApiKey;
540
559
  delete integrations.linearAccessToken;
541
560
  delete integrations.linearRefreshToken;
542
561
  delete integrations.linearClientSecret;
543
562
  delete integrations.slackClientSecret;
544
563
  delete integrations.slackAppToken;
564
+ delete integrations.githubPat;
545
565
  writePrivateFile(
546
566
  appSettingsPath(),
547
567
  `${JSON.stringify({ ...settings, environment: {}, integrations }, null, 2)}
@@ -554,6 +574,7 @@ function persistSplit(settings) {
554
574
  linearClientSecret,
555
575
  slackClientSecret,
556
576
  slackAppToken,
577
+ githubPat,
557
578
  environment: settings.environment
558
579
  });
559
580
  }
@@ -719,6 +740,20 @@ function updateIntegrationsSettings(patch) {
719
740
  integrations.slackDeviceLabel = patch.slackDeviceLabel.trim().slice(0, 64);
720
741
  }
721
742
  }
743
+ if ("githubGitAuthMode" in patch) {
744
+ if (patch.githubGitAuthMode == null) {
745
+ delete integrations.githubGitAuthMode;
746
+ } else if (GIT_AUTH_MODES.has(patch.githubGitAuthMode)) {
747
+ integrations.githubGitAuthMode = patch.githubGitAuthMode;
748
+ }
749
+ }
750
+ if ("githubPat" in patch) {
751
+ if (patch.githubPat == null || patch.githubPat.trim() === "") {
752
+ delete integrations.githubPat;
753
+ } else {
754
+ integrations.githubPat = patch.githubPat.trim();
755
+ }
756
+ }
722
757
  return saveAppSettings({ ...current, integrations });
723
758
  }
724
759
  function updateDefaultsSettings(patch) {
@@ -826,6 +861,13 @@ function disconnectLinearConnection() {
826
861
  function getIssueSource(settings = loadAppSettings()) {
827
862
  return settings.integrations.issueSource ?? "github";
828
863
  }
864
+ function getGithubGitAuthMode(settings = loadAppSettings()) {
865
+ return settings.integrations.githubGitAuthMode ?? "auto";
866
+ }
867
+ function getGithubPat(settings = loadAppSettings()) {
868
+ const pat = settings.integrations.githubPat?.trim();
869
+ return pat || null;
870
+ }
829
871
  function resolveEffectiveIssueSource(settings = loadAppSettings()) {
830
872
  const preferred = getIssueSource(settings);
831
873
  if (preferred === "linear" && !isLinearConnected(settings)) return "github";
@@ -1039,6 +1081,7 @@ export {
1039
1081
  writeSecureJson,
1040
1082
  isSecureFileEncrypted,
1041
1083
  HARNESS_ENV_KEYS,
1084
+ GITHUB_GIT_AUTH_MODES,
1042
1085
  toPublicAppSettings,
1043
1086
  appSettingsPath,
1044
1087
  claudeUserSettingsPath,
@@ -1061,6 +1104,8 @@ export {
1061
1104
  saveLinearOAuth,
1062
1105
  disconnectLinearConnection,
1063
1106
  getIssueSource,
1107
+ getGithubGitAuthMode,
1108
+ getGithubPat,
1064
1109
  resolveEffectiveIssueSource,
1065
1110
  getLinearApiKey,
1066
1111
  brightsyCloudConnectEnabled,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isOrchestratorThread
3
- } from "./chunk-VERLUKN2.js";
3
+ } from "./chunk-6F2TQFJE.js";
4
4
  import {
5
5
  applyConnectedTeamToCli,
6
6
  brightsyMcpServerName,
@@ -19,7 +19,7 @@ import {
19
19
  loadAppSettings,
20
20
  resolveAgentExecutable,
21
21
  resolveClaudeExecutable
22
- } from "./chunk-W7YOTDVO.js";
22
+ } from "./chunk-IFPN6TER.js";
23
23
  import {
24
24
  appDataDir
25
25
  } from "./chunk-M37RITA6.js";
@@ -34,6 +34,53 @@ import {
34
34
  // src/agents/brightsy.ts
35
35
  import { existsSync } from "fs";
36
36
 
37
+ // src/agents/usage.ts
38
+ function sumOptional(a, b) {
39
+ if (a == null && b == null) return void 0;
40
+ return (a ?? 0) + (b ?? 0);
41
+ }
42
+ function fromInclusiveInputUsage(opts) {
43
+ const totalInput = Number(opts.inputTokens) || 0;
44
+ const outputTokens = Number(opts.outputTokens) || 0;
45
+ const cached = Number(opts.cachedInputTokens) || 0;
46
+ if (!totalInput && !outputTokens) return null;
47
+ const cacheReadTokens = cached > 0 ? Math.min(cached, totalInput) : 0;
48
+ return {
49
+ inputTokens: Math.max(0, totalInput - cacheReadTokens),
50
+ outputTokens,
51
+ cacheReadTokens: cacheReadTokens || void 0
52
+ };
53
+ }
54
+ function requestOccupancy(u) {
55
+ return u.inputTokens + (u.cacheReadTokens ?? 0) + (u.cacheWriteTokens ?? 0);
56
+ }
57
+ function mergeUsage(a, b) {
58
+ return {
59
+ inputTokens: (a?.inputTokens ?? 0) + b.inputTokens,
60
+ outputTokens: (a?.outputTokens ?? 0) + b.outputTokens,
61
+ cacheReadTokens: sumOptional(a?.cacheReadTokens, b.cacheReadTokens),
62
+ cacheWriteTokens: sumOptional(a?.cacheWriteTokens, b.cacheWriteTokens),
63
+ lastRequestTokens: b.lastRequestTokens ?? a?.lastRequestTokens
64
+ };
65
+ }
66
+ function applyTurnUsage(current, incoming, scope = "request") {
67
+ if (scope === "turn") {
68
+ return {
69
+ ...incoming,
70
+ lastRequestTokens: current?.lastRequestTokens ?? requestOccupancy(incoming)
71
+ };
72
+ }
73
+ const merged = mergeUsage(current, incoming);
74
+ return { ...merged, lastRequestTokens: requestOccupancy(incoming) };
75
+ }
76
+ function totalTokens(u) {
77
+ return u.inputTokens + u.outputTokens + (u.cacheReadTokens ?? 0) + (u.cacheWriteTokens ?? 0);
78
+ }
79
+ function contextTokens(u) {
80
+ if (u.lastRequestTokens != null && u.lastRequestTokens > 0) return u.lastRequestTokens;
81
+ return requestOccupancy(u);
82
+ }
83
+
37
84
  // src/agents/brightsy-targets.ts
38
85
  function encodeBrightsyTarget(type, id, accountId) {
39
86
  if (accountId) return `team:${accountId}:${type}:${id}`;
@@ -131,15 +178,11 @@ var MAX_ANTHROPIC_CACHE_CONTROL_BLOCKS = 4;
131
178
  // src/agents/brightsy.ts
132
179
  function usageFromBrightsy(usage) {
133
180
  if (!usage) return null;
134
- const inputTokens = Number(usage.prompt_tokens ?? 0);
135
- const outputTokens = Number(usage.completion_tokens ?? 0);
136
- if (!inputTokens && !outputTokens) return null;
137
- const cached = Number(usage.prompt_tokens_details?.cached_tokens ?? 0);
138
- return {
139
- inputTokens,
140
- outputTokens,
141
- cacheReadTokens: cached || void 0
142
- };
181
+ return fromInclusiveInputUsage({
182
+ inputTokens: Number(usage.prompt_tokens ?? 0),
183
+ outputTokens: Number(usage.completion_tokens ?? 0),
184
+ cachedInputTokens: Number(usage.prompt_tokens_details?.cached_tokens ?? 0)
185
+ });
143
186
  }
144
187
  function parseBrightsyCliLine(line) {
145
188
  const trimmed = line.trim();
@@ -949,7 +992,7 @@ var claudeAdapter = {
949
992
  );
950
993
  }
951
994
  const mode = permissionMode(thread);
952
- const { isOrchestratorThread: isOrchestratorThread2 } = await import("./global-workspace-YNMNO4CL.js");
995
+ const { isOrchestratorThread: isOrchestratorThread2 } = await import("./global-workspace-DZM4ZFGU.js");
953
996
  const isOrchestrator = isOrchestratorThread2(thread);
954
997
  const injectedServers = await buildInjectedMcpServers({
955
998
  includeSideboard: true,
@@ -1200,14 +1243,11 @@ async function listCodexModels() {
1200
1243
  }
1201
1244
  function usageFromCodex(usage) {
1202
1245
  if (!usage) return null;
1203
- const inputTokens = Number(usage.input_tokens ?? 0);
1204
- const outputTokens = Number(usage.output_tokens ?? 0) + Number(usage.reasoning_output_tokens ?? 0);
1205
- if (!inputTokens && !outputTokens) return null;
1206
- return {
1207
- inputTokens,
1208
- outputTokens,
1209
- cacheReadTokens: usage.cached_input_tokens ? Number(usage.cached_input_tokens) : void 0
1210
- };
1246
+ return fromInclusiveInputUsage({
1247
+ inputTokens: Number(usage.input_tokens ?? 0),
1248
+ outputTokens: Number(usage.output_tokens ?? 0),
1249
+ cachedInputTokens: Number(usage.cached_input_tokens ?? 0)
1250
+ });
1211
1251
  }
1212
1252
  function codexConfigHasNetworkAccess() {
1213
1253
  const candidates = [
@@ -2339,6 +2379,12 @@ function allAdapters() {
2339
2379
  }
2340
2380
 
2341
2381
  export {
2382
+ fromInclusiveInputUsage,
2383
+ requestOccupancy,
2384
+ mergeUsage,
2385
+ applyTurnUsage,
2386
+ totalTokens,
2387
+ contextTokens,
2342
2388
  encodeBrightsyTarget,
2343
2389
  decodeBrightsyTarget,
2344
2390
  normalizeTurnInput,
@@ -1,6 +1,10 @@
1
1
  import {
2
2
  isWorkspaceScratchPath
3
3
  } from "./chunk-FKOIHGKV.js";
4
+ import {
5
+ getGithubGitAuthMode,
6
+ getGithubPat
7
+ } from "./chunk-IFPN6TER.js";
4
8
  import {
5
9
  listThreads
6
10
  } from "./chunk-FWJYLBO6.js";
@@ -886,6 +890,74 @@ function formatIpcInvokeError(err) {
886
890
  return formatGhLandError(msg);
887
891
  }
888
892
 
893
+ // src/git/git-auth-mode.ts
894
+ var HTTPS_REWRITE = [
895
+ { key: "url.https://github.com/.insteadOf", value: "git@github.com:" },
896
+ { key: "url.https://github.com/.insteadOf", value: "ssh://git@github.com/" },
897
+ { key: "credential.https://github.com.helper", value: "!gh auth git-credential" }
898
+ ];
899
+ function appendIndexedGitConfig(existing, entries) {
900
+ const start = Number.parseInt(String(existing?.GIT_CONFIG_COUNT ?? "0"), 10);
901
+ const count = Number.isFinite(start) && start > 0 ? start : 0;
902
+ const out = {};
903
+ entries.forEach((entry, i) => {
904
+ const n = count + i;
905
+ out[`GIT_CONFIG_KEY_${n}`] = entry.key;
906
+ out[`GIT_CONFIG_VALUE_${n}`] = entry.value;
907
+ });
908
+ out.GIT_CONFIG_COUNT = String(count + entries.length);
909
+ return out;
910
+ }
911
+ function githubAgentGitEnv(existing) {
912
+ return appendIndexedGitConfig(existing, HTTPS_REWRITE);
913
+ }
914
+ function applyGithubGitAuthEnv(existing, opts) {
915
+ const out = {};
916
+ if (opts.mode === "gh" || opts.mode === "token") {
917
+ Object.assign(out, githubAgentGitEnv(existing));
918
+ }
919
+ if (opts.mode === "token") {
920
+ const token = opts.token?.trim();
921
+ if (token && !existing?.GH_TOKEN?.trim()) {
922
+ out.GH_TOKEN = token;
923
+ }
924
+ }
925
+ return out;
926
+ }
927
+ function formatGitAuthModeDirective(mode) {
928
+ switch (mode) {
929
+ case "gh":
930
+ return [
931
+ "Git authentication (Account \u2192 GitHub mode: gh CLI):",
932
+ "- This process rewrites `git@github.com:` and `ssh://git@github.com/` to HTTPS.",
933
+ "- `gh` supplies credentials (`gh auth git-credential`). Do not switch remotes to SSH.",
934
+ "- Push with `git push -u origin HEAD`. Create/update PRs with `gh` as below."
935
+ ].join("\n");
936
+ case "ssh":
937
+ return [
938
+ "Git authentication (Account \u2192 GitHub mode: SSH):",
939
+ "- Keep SSH remotes (`git@github.com:\u2026`). Do not rewrite them to HTTPS.",
940
+ "- Use this Mac\u2019s SSH agent / keys. If push fails with `Permission denied (publickey)`, tell the user to start ssh-agent or switch Account \u2192 GitHub to Auto / gh CLI \u2014 do not rewrite remotes yourself.",
941
+ "- Push with `git push -u origin HEAD`. Create/update PRs with `gh` as below (API still uses `gh`)."
942
+ ].join("\n");
943
+ case "token":
944
+ return [
945
+ "Git authentication (Account \u2192 GitHub mode: personal access token):",
946
+ "- This process rewrites GitHub SSH remotes to HTTPS.",
947
+ "- `GH_TOKEN` is set in the environment. Use HTTPS git and `gh`; do not paste the token into commands or chat.",
948
+ "- Push with `git push -u origin HEAD`. Create/update PRs with `gh` as below."
949
+ ].join("\n");
950
+ case "auto":
951
+ default:
952
+ return [
953
+ "Git authentication (Account \u2192 GitHub mode: auto):",
954
+ "- Prefer the existing remote URL (SSH or HTTPS). Do not rewrite remotes unless a push/fetch fails.",
955
+ '- If `git push` fails with `Permission denied (publickey)`, this shell has no ssh-agent. Retry over HTTPS (do not stop): `git -c url.https://github.com/.insteadOf=git@github.com: -c http.extraHeader="AUTHORIZATION: bearer $(gh auth token)" push -u origin HEAD`.',
956
+ "- Then create/update the PR with `gh` as below."
957
+ ].join("\n");
958
+ }
959
+ }
960
+
889
961
  // src/git/pr-gates.ts
890
962
  function prIsInMergeQueue(gate) {
891
963
  if (gate.isInMergeQueue) return true;
@@ -1286,10 +1358,15 @@ ${view.stderr}`;
1286
1358
  timeoutMs: 15e3
1287
1359
  });
1288
1360
  }
1289
- async function originGhRepoEnv(cwd) {
1361
+ async function originGhRepoEnv(cwd, opts) {
1290
1362
  await ensureGhPreferOrigin(cwd);
1291
1363
  const slug = await resolveGithubRepoSlug(cwd);
1292
- return slug ? { GH_REPO: slug } : {};
1364
+ const mode = opts?.mode ?? getGithubGitAuthMode();
1365
+ const token = mode === "token" ? getGithubPat() : null;
1366
+ return {
1367
+ ...applyGithubGitAuthEnv(opts?.env, { mode, token }),
1368
+ ...slug ? { GH_REPO: slug } : {}
1369
+ };
1293
1370
  }
1294
1371
  async function resolveDefaultBranch(repoPath, opts) {
1295
1372
  const viaOrigin = await git(
@@ -2038,7 +2115,33 @@ async function commitAll(worktreePath, message) {
2038
2115
  return true;
2039
2116
  }
2040
2117
  async function pushBranch(worktreePath, branchName) {
2041
- await git(["push", "-u", "origin", branchName], worktreePath);
2118
+ const ssh = await git(["push", "-u", "origin", branchName], worktreePath, {
2119
+ reject: false
2120
+ });
2121
+ if (ssh.exitCode === 0) return;
2122
+ const sshErr = (ssh.stderr || ssh.stdout).trim();
2123
+ const slug = await resolveGithubRepoSlug(worktreePath);
2124
+ const token = await resolveGhAuthToken(worktreePath);
2125
+ if (!slug || !token) {
2126
+ throw new Error(
2127
+ sshErr || `git push origin ${branchName} failed` + (!token ? " (no SSH agent and gh auth token unavailable \u2014 run: gh auth login)" : "")
2128
+ );
2129
+ }
2130
+ const tryHttps = async (header) => git(["push", "-u", "origin", branchName], worktreePath, {
2131
+ reject: false,
2132
+ env: { GIT_TERMINAL_PROMPT: "0" },
2133
+ config: {
2134
+ "url.https://github.com/.insteadOf": "git@github.com:",
2135
+ "http.extraHeader": header
2136
+ }
2137
+ });
2138
+ const bearer = await tryHttps(`AUTHORIZATION: bearer ${token}`);
2139
+ if (bearer.exitCode === 0) return;
2140
+ const basic = Buffer.from(`x-access-token:${token}`, "utf8").toString("base64");
2141
+ const basicPush = await tryHttps(`Authorization: Basic ${basic}`);
2142
+ if (basicPush.exitCode === 0) return;
2143
+ const httpsErr = (basicPush.stderr || bearer.stderr || bearer.stdout).trim();
2144
+ throw new Error(httpsErr || sshErr || `git push origin ${branchName} failed`);
2042
2145
  }
2043
2146
  async function mergePr(cwd, selector, opts) {
2044
2147
  const slug = await resolveGithubRepoSlug(cwd);
@@ -2251,6 +2354,10 @@ export {
2251
2354
  extractGhErrorDetail,
2252
2355
  formatGhLandError,
2253
2356
  formatIpcInvokeError,
2357
+ appendIndexedGitConfig,
2358
+ githubAgentGitEnv,
2359
+ applyGithubGitAuthEnv,
2360
+ formatGitAuthModeDirective,
2254
2361
  detectGhStack,
2255
2362
  resetGhStackDetectCache,
2256
2363
  parseGhStackViewJson,
@@ -7,11 +7,11 @@ import {
7
7
  enrichWorkspacesWithGithub,
8
8
  ensureGlobalCoordinatorCwd,
9
9
  formatWorkspaceInventory
10
- } from "./chunk-EEKSZTMU.js";
11
- import "./chunk-W7YOTDVO.js";
12
- import "./chunk-JT7R45JB.js";
13
- import "./chunk-MF2YMEGD.js";
10
+ } from "./chunk-CQBQWX73.js";
11
+ import "./chunk-YVVXWWCC.js";
14
12
  import "./chunk-FKOIHGKV.js";
13
+ import "./chunk-IFPN6TER.js";
14
+ import "./chunk-JT7R45JB.js";
15
15
  import "./chunk-FWJYLBO6.js";
16
16
  import "./chunk-77WWLBCI.js";
17
17
  import "./chunk-M37RITA6.js";
@@ -9,12 +9,12 @@ import {
9
9
  enrichWorkspacesWithGithub,
10
10
  ensureGlobalCoordinatorCwd,
11
11
  formatWorkspaceInventory
12
- } from "./chunk-XJNCWYFR.js";
13
- import "./chunk-OE7YBB5X.js";
12
+ } from "./chunk-4HJK57XU.js";
13
+ import "./chunk-FUUVPN4A.js";
14
14
  import "./chunk-B3SJXYIJ.js";
15
15
  import "./chunk-7FD7COKE.js";
16
16
  import "./chunk-AE5VBOFE.js";
17
- import "./chunk-PTJJIQK7.js";
17
+ import "./chunk-XKNBSYA7.js";
18
18
  import "./chunk-NSTQ6QKD.js";
19
19
  import "./chunk-KGZBYWZ3.js";
20
20
  import "./chunk-7MV3RXSC.js";