@sideboard-ai/core 0.1.207 → 0.1.209

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 (51) hide show
  1. package/dist/{abletime-I4IYZBKU.js → abletime-G3MWSZVM.js} +4 -4
  2. package/dist/{abletime-UWSSLXH3.js → abletime-SQREWITG.js} +4 -4
  3. package/dist/{abletime-oauth-UZHPB3W2.js → abletime-oauth-7AOE4KJL.js} +3 -3
  4. package/dist/{abletime-oauth-C3BQXKW3.js → abletime-oauth-SQD6K47H.js} +3 -3
  5. package/dist/{abletime-rest-5YPPEOKK.js → abletime-rest-BXL7QHCX.js} +3 -3
  6. package/dist/{abletime-rest-HYNYDYK3.js → abletime-rest-QRTJH42S.js} +3 -3
  7. package/dist/agents/cursor-runner.js +3 -3
  8. package/dist/{agents-7MULGRPU.js → agents-KA6HDNNP.js} +6 -5
  9. package/dist/{agents-KCBCFMFW.js → agents-U2NVCYGC.js} +6 -5
  10. package/dist/{app-settings-R2KNCT37.js → app-settings-6SZLZNA7.js} +7 -1
  11. package/dist/{app-settings-GJ6KDYEF.js → app-settings-VBQHGX5Z.js} +7 -1
  12. package/dist/{chunk-6KH4OBEW.js → chunk-22A45QOI.js} +2 -2
  13. package/dist/{chunk-N4A4NWFO.js → chunk-42VGWRSE.js} +2 -2
  14. package/dist/{chunk-X45BV4VX.js → chunk-5LFD3KCJ.js} +5 -5
  15. package/dist/{chunk-F4LZUEIO.js → chunk-B2RPIHNJ.js} +2 -2
  16. package/dist/{chunk-6YZLSZLK.js → chunk-CQZCXRVG.js} +3 -3
  17. package/dist/{chunk-4EGK47WV.js → chunk-FUC3XFE2.js} +215 -0
  18. package/dist/{chunk-5UQTT4S7.js → chunk-HBL7ILQA.js} +154 -31
  19. package/dist/{chunk-TEDEVD4O.js → chunk-IIENQFJ6.js} +2 -2
  20. package/dist/{chunk-6J4OQ6TF.js → chunk-IOOL3T7Q.js} +3 -3
  21. package/dist/{chunk-A2BRWIEM.js → chunk-KJAHVQL6.js} +51 -94
  22. package/dist/{chunk-ZU7R35NY.js → chunk-MS2P5GXL.js} +49 -87
  23. package/dist/{chunk-2GPZ4BAU.js → chunk-MZP2C4KE.js} +158 -31
  24. package/dist/{chunk-ARR4OGLY.js → chunk-OY7THBLG.js} +12 -2
  25. package/dist/{chunk-QOJB5PC7.js → chunk-PTOIWKDU.js} +3 -3
  26. package/dist/{chunk-W6X4GZJG.js → chunk-QVVJO4GN.js} +3 -3
  27. package/dist/{chunk-DWGEBZ3C.js → chunk-RPZFNKND.js} +12 -2
  28. package/dist/{chunk-PAQPT3JO.js → chunk-TZCWNRMC.js} +3 -3
  29. package/dist/{chunk-Y4CF7LHH.js → chunk-VJQDUD24.js} +230 -0
  30. package/dist/chunk-X5B3OS5I.js +34 -0
  31. package/dist/{chunk-WXWJ5MJ4.js → chunk-XRIF6M5H.js} +5 -5
  32. package/dist/{coordinator-prompt-6NV2IHEX.js → coordinator-prompt-2YCOE5R4.js} +5 -4
  33. package/dist/{coordinator-prompt-6A3D7BV3.js → coordinator-prompt-EO2X2EYW.js} +5 -4
  34. package/dist/{cursor-recover-TXVTLAMA.js → cursor-recover-4PQAADAU.js} +3 -28
  35. package/dist/{global-workspace-I2X6UQMX.js → global-workspace-H2ANUSGR.js} +5 -4
  36. package/dist/{global-workspace-VS6HZF2I.js → global-workspace-JEKMVE42.js} +5 -4
  37. package/dist/index.cjs +752 -391
  38. package/dist/index.d.cts +127 -5
  39. package/dist/index.d.ts +127 -5
  40. package/dist/index.js +63 -19
  41. package/dist/mcp/run-stdio.cjs +706 -391
  42. package/dist/mcp/run-stdio.js +12 -11
  43. package/dist/{orchestrator-CXQY5YRG.js → orchestrator-N7LLTK5O.js} +7 -6
  44. package/dist/{orchestrator-7WF32ZXJ.js → orchestrator-RUQXDYM7.js} +7 -6
  45. package/dist/{thread-store-XGYWXR2P.js → thread-store-55X2JYDT.js} +2 -1
  46. package/dist/{thread-store-LS2T6RVH.js → thread-store-CMZWM5NY.js} +2 -1
  47. package/dist/{workspaces-CEU25ANO.js → workspaces-2YNYLSPV.js} +5 -4
  48. package/dist/{workspaces-7PM7UGLG.js → workspaces-SVDORZEI.js} +5 -4
  49. package/dist/{worktree-YD7Y6NRY.js → worktree-5CPGB4D2.js} +4 -3
  50. package/dist/{worktree-T6PCOIHZ.js → worktree-YQ6XUSR2.js} +4 -3
  51. package/package.json +1 -1
@@ -15,11 +15,11 @@ import {
15
15
  toAbleTimeIssueInfo,
16
16
  updateAbleTimeTask,
17
17
  verifyAbleTimeConnection
18
- } from "./chunk-W6X4GZJG.js";
19
- import "./chunk-F4LZUEIO.js";
20
- import "./chunk-X45BV4VX.js";
18
+ } from "./chunk-QVVJO4GN.js";
19
+ import "./chunk-B2RPIHNJ.js";
20
+ import "./chunk-5LFD3KCJ.js";
21
21
  import "./chunk-N7WZ6NIN.js";
22
- import "./chunk-Y4CF7LHH.js";
22
+ import "./chunk-VJQDUD24.js";
23
23
  import "./chunk-4TR3HZFT.js";
24
24
  import "./chunk-WDRMZKVB.js";
25
25
  import "./chunk-JT7R45JB.js";
@@ -17,11 +17,11 @@ import {
17
17
  toAbleTimeIssueInfo,
18
18
  updateAbleTimeTask,
19
19
  verifyAbleTimeConnection
20
- } from "./chunk-6YZLSZLK.js";
21
- import "./chunk-TEDEVD4O.js";
22
- import "./chunk-WXWJ5MJ4.js";
20
+ } from "./chunk-CQZCXRVG.js";
21
+ import "./chunk-IIENQFJ6.js";
22
+ import "./chunk-XRIF6M5H.js";
23
23
  import "./chunk-VKQGAWHY.js";
24
- import "./chunk-4EGK47WV.js";
24
+ import "./chunk-FUC3XFE2.js";
25
25
  import "./chunk-NSTQ6QKD.js";
26
26
  import "./chunk-KGZBYWZ3.js";
27
27
  import "./chunk-EQNRWDLN.js";
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  DEFAULT_ABLETIME_HOST,
5
5
  normalizeAbleTimeHost
6
- } from "./chunk-WXWJ5MJ4.js";
6
+ } from "./chunk-XRIF6M5H.js";
7
7
  import {
8
8
  httpFetch
9
9
  } from "./chunk-VKQGAWHY.js";
@@ -12,7 +12,7 @@ import {
12
12
  getAbleTimeHost,
13
13
  loadAppSettings,
14
14
  saveAbleTimeConnection
15
- } from "./chunk-4EGK47WV.js";
15
+ } from "./chunk-FUC3XFE2.js";
16
16
  import "./chunk-NSTQ6QKD.js";
17
17
  import "./chunk-KGZBYWZ3.js";
18
18
  import "./chunk-EQNRWDLN.js";
@@ -286,7 +286,7 @@ async function startAbleTimeOAuth(opts) {
286
286
  persistAbleTimeTokens(data, { host });
287
287
  const token = data.access_token.trim();
288
288
  try {
289
- const { getAbleTimeOrientation } = await import("./abletime-UWSSLXH3.js");
289
+ const { getAbleTimeOrientation } = await import("./abletime-SQREWITG.js");
290
290
  const orientation = await getAbleTimeOrientation({ token, host });
291
291
  return saveAbleTimeConnection({
292
292
  accessToken: token,
@@ -20,10 +20,10 @@ import {
20
20
  parseAbleTimeOAuthCallbackUrl,
21
21
  resolveAbleTimeOAuthHost,
22
22
  startAbleTimeOAuth
23
- } from "./chunk-6J4OQ6TF.js";
24
- import "./chunk-X45BV4VX.js";
23
+ } from "./chunk-IOOL3T7Q.js";
24
+ import "./chunk-5LFD3KCJ.js";
25
25
  import "./chunk-N7WZ6NIN.js";
26
- import "./chunk-Y4CF7LHH.js";
26
+ import "./chunk-VJQDUD24.js";
27
27
  import "./chunk-4TR3HZFT.js";
28
28
  import "./chunk-WDRMZKVB.js";
29
29
  import "./chunk-JT7R45JB.js";
@@ -5,10 +5,10 @@ import {
5
5
  callAbleTimeRestTool,
6
6
  looksLikeAbleTimeUlid,
7
7
  textFromAbleTimeDoc
8
- } from "./chunk-F4LZUEIO.js";
9
- import "./chunk-X45BV4VX.js";
8
+ } from "./chunk-B2RPIHNJ.js";
9
+ import "./chunk-5LFD3KCJ.js";
10
10
  import "./chunk-N7WZ6NIN.js";
11
- import "./chunk-Y4CF7LHH.js";
11
+ import "./chunk-VJQDUD24.js";
12
12
  import "./chunk-4TR3HZFT.js";
13
13
  import "./chunk-WDRMZKVB.js";
14
14
  import "./chunk-JT7R45JB.js";
@@ -7,10 +7,10 @@ import {
7
7
  callAbleTimeRestTool,
8
8
  looksLikeAbleTimeUlid,
9
9
  textFromAbleTimeDoc
10
- } from "./chunk-TEDEVD4O.js";
11
- import "./chunk-WXWJ5MJ4.js";
10
+ } from "./chunk-IIENQFJ6.js";
11
+ import "./chunk-XRIF6M5H.js";
12
12
  import "./chunk-VKQGAWHY.js";
13
- import "./chunk-4EGK47WV.js";
13
+ import "./chunk-FUC3XFE2.js";
14
14
  import "./chunk-NSTQ6QKD.js";
15
15
  import "./chunk-KGZBYWZ3.js";
16
16
  import "./chunk-EQNRWDLN.js";
@@ -1,7 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- cursorSdkStoreDir
4
- } from "../chunk-7J72QJOM.js";
5
2
  import {
6
3
  createAgentStreamCoalescer
7
4
  } from "../chunk-AXQ4ZWHK.js";
@@ -17,6 +14,9 @@ import {
17
14
  import {
18
15
  dropNestedElectronEnvFromProcess
19
16
  } from "../chunk-4TR3HZFT.js";
17
+ import {
18
+ cursorSdkStoreDir
19
+ } from "../chunk-7J72QJOM.js";
20
20
  import "../chunk-WFUDY6PC.js";
21
21
  import "../chunk-UFHNSFAS.js";
22
22
 
@@ -50,14 +50,15 @@ import {
50
50
  resolveQuotaFallbackAgent,
51
51
  turnCostUsdFromCursorUsage,
52
52
  whichOnPath
53
- } from "./chunk-ZU7R35NY.js";
54
- import "./chunk-QOJB5PC7.js";
53
+ } from "./chunk-MS2P5GXL.js";
54
+ import "./chunk-PTOIWKDU.js";
55
55
  import "./chunk-3OHR73VK.js";
56
56
  import "./chunk-Y4MIXGPA.js";
57
57
  import "./chunk-VKQGAWHY.js";
58
- import "./chunk-N4A4NWFO.js";
58
+ import "./chunk-42VGWRSE.js";
59
59
  import "./chunk-D6JWYJ4P.js";
60
- import "./chunk-DWGEBZ3C.js";
60
+ import "./chunk-RPZFNKND.js";
61
+ import "./chunk-X5B3OS5I.js";
61
62
  import "./chunk-SYFVUF2C.js";
62
63
  import {
63
64
  conductorBundledBinDir,
@@ -73,7 +74,7 @@ import {
73
74
  assertOrchestratorCapableAgent,
74
75
  coerceOrchestratorAgent,
75
76
  isOrchestratorCapableAgent
76
- } from "./chunk-4EGK47WV.js";
77
+ } from "./chunk-FUC3XFE2.js";
77
78
  import "./chunk-NSTQ6QKD.js";
78
79
  import "./chunk-KGZBYWZ3.js";
79
80
  import "./chunk-EQNRWDLN.js";
@@ -44,9 +44,9 @@ import {
44
44
  resolveLoginCommand,
45
45
  resolveQuotaFallbackAgent,
46
46
  whichOnPath
47
- } from "./chunk-A2BRWIEM.js";
48
- import "./chunk-PAQPT3JO.js";
49
- import "./chunk-6KH4OBEW.js";
47
+ } from "./chunk-KJAHVQL6.js";
48
+ import "./chunk-TZCWNRMC.js";
49
+ import "./chunk-22A45QOI.js";
50
50
  import "./chunk-6K64FJDD.js";
51
51
  import "./chunk-QQKDGPUI.js";
52
52
  import "./chunk-SALM35KD.js";
@@ -63,11 +63,12 @@ import {
63
63
  assertOrchestratorCapableAgent,
64
64
  coerceOrchestratorAgent,
65
65
  isOrchestratorCapableAgent
66
- } from "./chunk-Y4CF7LHH.js";
66
+ } from "./chunk-VJQDUD24.js";
67
67
  import "./chunk-4TR3HZFT.js";
68
68
  import "./chunk-WDRMZKVB.js";
69
69
  import "./chunk-JT7R45JB.js";
70
- import "./chunk-ARR4OGLY.js";
70
+ import "./chunk-OY7THBLG.js";
71
+ import "./chunk-7J72QJOM.js";
71
72
  import "./chunk-77WWLBCI.js";
72
73
  import "./chunk-WFUDY6PC.js";
73
74
  import {
@@ -10,6 +10,7 @@ import {
10
10
  appSettingsPath,
11
11
  applyAppEnvironment,
12
12
  autoArchiveOnMergeEnabled,
13
+ autoCleanupHistoryEnabled,
13
14
  autoCleanupOrphansEnabled,
14
15
  autoRenameBranchEnabled,
15
16
  autoRunAfterSetupEnabled,
@@ -50,6 +51,8 @@ import {
50
51
  getLinearApiKey,
51
52
  gitBranchPrefixSetting,
52
53
  harnessEnvKey,
54
+ historyMaxCount,
55
+ historyMaxDays,
53
56
  isAbleTimeConnected,
54
57
  isIssueSourceConnected,
55
58
  isLinearConnected,
@@ -91,7 +94,7 @@ import {
91
94
  updateProjectProfileSettings,
92
95
  usageOnLimit,
93
96
  writeViewerContext
94
- } from "./chunk-4EGK47WV.js";
97
+ } from "./chunk-FUC3XFE2.js";
95
98
  import "./chunk-NSTQ6QKD.js";
96
99
  import "./chunk-KGZBYWZ3.js";
97
100
  import "./chunk-EQNRWDLN.js";
@@ -106,6 +109,7 @@ export {
106
109
  appSettingsPath,
107
110
  applyAppEnvironment,
108
111
  autoArchiveOnMergeEnabled,
112
+ autoCleanupHistoryEnabled,
109
113
  autoCleanupOrphansEnabled,
110
114
  autoRenameBranchEnabled,
111
115
  autoRunAfterSetupEnabled,
@@ -146,6 +150,8 @@ export {
146
150
  getLinearApiKey,
147
151
  gitBranchPrefixSetting,
148
152
  harnessEnvKey,
153
+ historyMaxCount,
154
+ historyMaxDays,
149
155
  isAbleTimeConnected,
150
156
  isIssueSourceConnected,
151
157
  isLinearConnected,
@@ -8,6 +8,7 @@ import {
8
8
  appSettingsPath,
9
9
  applyAppEnvironment,
10
10
  autoArchiveOnMergeEnabled,
11
+ autoCleanupHistoryEnabled,
11
12
  autoCleanupOrphansEnabled,
12
13
  autoRenameBranchEnabled,
13
14
  autoRunAfterSetupEnabled,
@@ -48,6 +49,8 @@ import {
48
49
  getLinearApiKey,
49
50
  gitBranchPrefixSetting,
50
51
  harnessEnvKey,
52
+ historyMaxCount,
53
+ historyMaxDays,
51
54
  isAbleTimeConnected,
52
55
  isIssueSourceConnected,
53
56
  isLinearConnected,
@@ -89,7 +92,7 @@ import {
89
92
  updateProjectProfileSettings,
90
93
  usageOnLimit,
91
94
  writeViewerContext
92
- } from "./chunk-Y4CF7LHH.js";
95
+ } from "./chunk-VJQDUD24.js";
93
96
  import "./chunk-4TR3HZFT.js";
94
97
  import "./chunk-WDRMZKVB.js";
95
98
  import "./chunk-JT7R45JB.js";
@@ -105,6 +108,7 @@ export {
105
108
  appSettingsPath,
106
109
  applyAppEnvironment,
107
110
  autoArchiveOnMergeEnabled,
111
+ autoCleanupHistoryEnabled,
108
112
  autoCleanupOrphansEnabled,
109
113
  autoRenameBranchEnabled,
110
114
  autoRunAfterSetupEnabled,
@@ -145,6 +149,8 @@ export {
145
149
  getLinearApiKey,
146
150
  gitBranchPrefixSetting,
147
151
  harnessEnvKey,
152
+ historyMaxCount,
153
+ historyMaxDays,
148
154
  isAbleTimeConnected,
149
155
  isIssueSourceConnected,
150
156
  isLinearConnected,
@@ -7,10 +7,10 @@ import {
7
7
  import {
8
8
  getGithubGitAuthMode,
9
9
  getGithubPat
10
- } from "./chunk-Y4CF7LHH.js";
10
+ } from "./chunk-VJQDUD24.js";
11
11
  import {
12
12
  listThreads
13
- } from "./chunk-ARR4OGLY.js";
13
+ } from "./chunk-OY7THBLG.js";
14
14
  import {
15
15
  worktreesRoot
16
16
  } from "./chunk-WFUDY6PC.js";
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-D6JWYJ4P.js";
6
6
  import {
7
7
  listThreads
8
- } from "./chunk-DWGEBZ3C.js";
8
+ } from "./chunk-RPZFNKND.js";
9
9
  import {
10
10
  ensureWorktreeSideboardIgnored
11
11
  } from "./chunk-SYFVUF2C.js";
@@ -22,7 +22,7 @@ import {
22
22
  import {
23
23
  getGithubGitAuthMode,
24
24
  getGithubPat
25
- } from "./chunk-4EGK47WV.js";
25
+ } from "./chunk-FUC3XFE2.js";
26
26
  import {
27
27
  worktreesRoot
28
28
  } from "./chunk-EQNRWDLN.js";
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  getAbleTimeHost,
6
6
  isAbleTimeConnected
7
- } from "./chunk-Y4CF7LHH.js";
7
+ } from "./chunk-VJQDUD24.js";
8
8
 
9
9
  // src/integrations/abletime-mcp.ts
10
10
  var DEFAULT_ABLETIME_HOST = "https://track.abletime.com";
@@ -153,7 +153,7 @@ function textsFromUnknown(value) {
153
153
  return "";
154
154
  }
155
155
  async function abletimeMcpRequest(method, params, opts) {
156
- const rawToken = opts?.token ?? await import("./abletime-oauth-C3BQXKW3.js").then((m) => m.ensureAbleTimeAccessToken());
156
+ const rawToken = opts?.token ?? await import("./abletime-oauth-SQD6K47H.js").then((m) => m.ensureAbleTimeAccessToken());
157
157
  if (!rawToken?.trim()) {
158
158
  throw new Error("AbleTime is not connected \u2014 paste a personal access token in Account settings");
159
159
  }
@@ -224,9 +224,9 @@ async function callAbleTimeTool(name, args = {}, opts) {
224
224
  if (!opts?.token && !isAbleTimeConnected()) {
225
225
  throw new Error("AbleTime is not connected \u2014 paste a personal access token in Account settings");
226
226
  }
227
- const rawToken = opts?.token ?? await import("./abletime-oauth-C3BQXKW3.js").then((m) => m.ensureAbleTimeAccessToken());
227
+ const rawToken = opts?.token ?? await import("./abletime-oauth-SQD6K47H.js").then((m) => m.ensureAbleTimeAccessToken());
228
228
  if (rawToken && ableTimeUsesRest(rawToken)) {
229
- const { callAbleTimeRestTool } = await import("./abletime-rest-5YPPEOKK.js");
229
+ const { callAbleTimeRestTool } = await import("./abletime-rest-BXL7QHCX.js");
230
230
  return callAbleTimeRestTool(name, args, { ...opts, token: rawToken });
231
231
  }
232
232
  const requestOpts = { ...opts, pm: opts?.pm ?? abletimeToolUsesPm(name) };
@@ -242,7 +242,7 @@ async function callAbleTimeTool(name, args = {}, opts) {
242
242
  return await call();
243
243
  }
244
244
  if (rawToken && ableTimeUsesRest(rawToken) && isAbleTimeRejectedCredential(message)) {
245
- const { callAbleTimeRestTool } = await import("./abletime-rest-5YPPEOKK.js");
245
+ const { callAbleTimeRestTool } = await import("./abletime-rest-BXL7QHCX.js");
246
246
  return callAbleTimeRestTool(name, args, { ...opts, token: rawToken });
247
247
  }
248
248
  throw err instanceof Error ? new Error(rewriteAbleTimeError(err.message)) : err;
@@ -4,14 +4,14 @@ import {
4
4
  normalizeAbleTimeCredential,
5
5
  normalizeAbleTimeHost,
6
6
  rewriteAbleTimeError
7
- } from "./chunk-X45BV4VX.js";
7
+ } from "./chunk-5LFD3KCJ.js";
8
8
  import {
9
9
  httpFetch
10
10
  } from "./chunk-N7WZ6NIN.js";
11
11
  import {
12
12
  getAbleTimeAccessToken,
13
13
  getAbleTimeHost
14
- } from "./chunk-Y4CF7LHH.js";
14
+ } from "./chunk-VJQDUD24.js";
15
15
 
16
16
  // src/integrations/abletime-rest.ts
17
17
  var ABLETIME_REST_PREFIX = "/api/public/v2";
@@ -2,17 +2,17 @@
2
2
 
3
3
  import {
4
4
  textFromAbleTimeDoc
5
- } from "./chunk-TEDEVD4O.js";
5
+ } from "./chunk-IIENQFJ6.js";
6
6
  import {
7
7
  assertAbleTimeCredential,
8
8
  callAbleTimeTool,
9
9
  normalizeAbleTimeHost,
10
10
  rewriteAbleTimeError
11
- } from "./chunk-WXWJ5MJ4.js";
11
+ } from "./chunk-XRIF6M5H.js";
12
12
  import {
13
13
  isAbleTimeConnected,
14
14
  saveAbleTimeConnection
15
- } from "./chunk-4EGK47WV.js";
15
+ } from "./chunk-FUC3XFE2.js";
16
16
 
17
17
  // src/integrations/abletime.ts
18
18
  var CLOSED_STATES = /* @__PURE__ */ new Set([
@@ -383,6 +383,165 @@ function normalizeVault(raw) {
383
383
  return out;
384
384
  }
385
385
 
386
+ // src/agents/usage.ts
387
+ function sumOptional(a, b) {
388
+ if (a == null && b == null) return void 0;
389
+ return (a ?? 0) + (b ?? 0);
390
+ }
391
+ function fromInclusiveInputUsage(opts) {
392
+ const totalInput = Number(opts.inputTokens) || 0;
393
+ const outputTokens = Number(opts.outputTokens) || 0;
394
+ const cached = Number(opts.cachedInputTokens) || 0;
395
+ if (!totalInput && !outputTokens) return null;
396
+ const cacheReadTokens = cached > 0 ? Math.min(cached, totalInput) : 0;
397
+ return {
398
+ inputTokens: Math.max(0, totalInput - cacheReadTokens),
399
+ outputTokens,
400
+ cacheReadTokens: cacheReadTokens || void 0
401
+ };
402
+ }
403
+ function requestOccupancy(u) {
404
+ return u.inputTokens + (u.cacheReadTokens ?? 0) + (u.cacheWriteTokens ?? 0);
405
+ }
406
+ function mergeUsage(a, b) {
407
+ return {
408
+ inputTokens: (a?.inputTokens ?? 0) + b.inputTokens,
409
+ outputTokens: (a?.outputTokens ?? 0) + b.outputTokens,
410
+ cacheReadTokens: sumOptional(a?.cacheReadTokens, b.cacheReadTokens),
411
+ cacheWriteTokens: sumOptional(a?.cacheWriteTokens, b.cacheWriteTokens),
412
+ costUsd: sumOptional(a?.costUsd, b.costUsd),
413
+ lastRequestTokens: b.lastRequestTokens ?? a?.lastRequestTokens
414
+ };
415
+ }
416
+ function sumUsageList(list) {
417
+ let acc = null;
418
+ for (const u of list) {
419
+ if (!u) continue;
420
+ acc = mergeUsage(acc, {
421
+ inputTokens: u.inputTokens,
422
+ outputTokens: u.outputTokens,
423
+ cacheReadTokens: u.cacheReadTokens,
424
+ cacheWriteTokens: u.cacheWriteTokens,
425
+ costUsd: u.costUsd
426
+ });
427
+ }
428
+ if (!acc) return null;
429
+ return {
430
+ inputTokens: acc.inputTokens,
431
+ outputTokens: acc.outputTokens,
432
+ ...acc.cacheReadTokens != null ? { cacheReadTokens: acc.cacheReadTokens } : {},
433
+ ...acc.cacheWriteTokens != null ? { cacheWriteTokens: acc.cacheWriteTokens } : {},
434
+ ...acc.costUsd != null ? { costUsd: acc.costUsd } : {}
435
+ };
436
+ }
437
+ function hasBilledTokens(u) {
438
+ return Boolean(
439
+ u.inputTokens || u.outputTokens || u.cacheReadTokens || u.cacheWriteTokens
440
+ );
441
+ }
442
+ function applyTurnUsage(current, incoming, scope = "request") {
443
+ if (scope === "turn") {
444
+ if (!hasBilledTokens(incoming) && current && incoming.costUsd != null) {
445
+ return { ...current, costUsd: incoming.costUsd };
446
+ }
447
+ return {
448
+ ...incoming,
449
+ costUsd: incoming.costUsd ?? current?.costUsd,
450
+ lastRequestTokens: current?.lastRequestTokens ?? requestOccupancy(incoming)
451
+ };
452
+ }
453
+ const merged = mergeUsage(current, incoming);
454
+ const occ = incoming.lastRequestTokens != null && incoming.lastRequestTokens > 0 ? incoming.lastRequestTokens : requestOccupancy(incoming);
455
+ return {
456
+ ...merged,
457
+ lastRequestTokens: occ > 0 ? occ : current?.lastRequestTokens ?? occ
458
+ };
459
+ }
460
+ function contextTokens(u) {
461
+ if (u.lastRequestTokens != null && u.lastRequestTokens > 0) return u.lastRequestTokens;
462
+ return requestOccupancy(u);
463
+ }
464
+
465
+ // src/store/history-retention.ts
466
+ var HISTORY_MAX_COUNT_DEFAULT = 200;
467
+ var HISTORY_MAX_COUNT_MIN = 1;
468
+ var HISTORY_MAX_COUNT_MAX = 2e3;
469
+ var HISTORY_MAX_DAYS_DEFAULT = 0;
470
+ var HISTORY_MAX_DAYS_MAX = 3650;
471
+ var HISTORY_CLEANUP_INTERVAL_HOURS_DEFAULT = 6;
472
+ var HISTORY_DISCARDED_TEXT = "Transcript discarded by History retention.";
473
+ function clampHistoryMaxCount(value) {
474
+ return Math.max(HISTORY_MAX_COUNT_MIN, Math.min(HISTORY_MAX_COUNT_MAX, Math.floor(value)));
475
+ }
476
+ function clampHistoryMaxDays(value) {
477
+ if (!Number.isFinite(value) || value <= 0) return 0;
478
+ return Math.min(HISTORY_MAX_DAYS_MAX, Math.floor(value));
479
+ }
480
+ function archivedUpdatedMs(thread) {
481
+ const updated = Date.parse(thread.updatedAt);
482
+ if (Number.isFinite(updated)) return updated;
483
+ const created = Date.parse(thread.createdAt);
484
+ return Number.isFinite(created) ? created : 0;
485
+ }
486
+ function isHistoryRetentionStub(thread) {
487
+ if ((thread.attachments?.length ?? 0) > 0) return false;
488
+ const messages = thread.messages ?? [];
489
+ if (messages.length === 0) return true;
490
+ if (messages.length > 1) return false;
491
+ const only = messages[0];
492
+ if (only.parts?.length) return false;
493
+ if ((only.attachments?.length ?? 0) > 0) return false;
494
+ const text = (only.text ?? "").trim();
495
+ return text === "" || text === HISTORY_DISCARDED_TEXT;
496
+ }
497
+ function historyRetentionStubMessage(thread) {
498
+ const usage = sumUsageList((thread.messages ?? []).map((m) => m.usage));
499
+ return {
500
+ role: "summary",
501
+ text: HISTORY_DISCARDED_TEXT,
502
+ ts: thread.updatedAt,
503
+ ...usage ? { usage } : {}
504
+ };
505
+ }
506
+ function sortArchivedOldestFirst(threads) {
507
+ return [...threads].sort((a, b) => archivedUpdatedMs(a) - archivedUpdatedMs(b));
508
+ }
509
+ function planHistoryRetention(archived, thresholds = {}) {
510
+ const maxCount = clampHistoryMaxCount(thresholds.maxCount ?? HISTORY_MAX_COUNT_DEFAULT);
511
+ const maxDays = clampHistoryMaxDays(thresholds.maxDays ?? HISTORY_MAX_DAYS_DEFAULT);
512
+ const nowMs = thresholds.nowMs ?? Date.now();
513
+ const oldestFirst = sortArchivedOldestFirst(archived);
514
+ const expiredIds = /* @__PURE__ */ new Set();
515
+ if (maxDays > 0) {
516
+ const cutoff = nowMs - maxDays * 864e5;
517
+ for (const thread of oldestFirst) {
518
+ if (archivedUpdatedMs(thread) < cutoff) expiredIds.add(thread.id);
519
+ }
520
+ }
521
+ const remaining = oldestFirst.filter((t) => !expiredIds.has(t.id));
522
+ const overflow = remaining.length > maxCount ? remaining.slice(0, remaining.length - maxCount) : [];
523
+ const stripIds = [];
524
+ const purgeIds = [...expiredIds];
525
+ const seenPurge = new Set(purgeIds);
526
+ for (const thread of overflow) {
527
+ if (isHistoryRetentionStub(thread)) {
528
+ if (!seenPurge.has(thread.id)) {
529
+ seenPurge.add(thread.id);
530
+ purgeIds.push(thread.id);
531
+ }
532
+ } else {
533
+ stripIds.push(thread.id);
534
+ }
535
+ }
536
+ return { stripIds, purgeIds };
537
+ }
538
+ function planHistoryAgePurge(archived, olderThanDays, nowMs = Date.now()) {
539
+ const days = clampHistoryMaxDays(olderThanDays);
540
+ if (days <= 0) return [];
541
+ const cutoff = nowMs - days * 864e5;
542
+ return sortArchivedOldestFirst(archived).filter((t) => archivedUpdatedMs(t) < cutoff).map((t) => t.id);
543
+ }
544
+
386
545
  // src/store/usage-on-limit.ts
387
546
  var USAGE_ON_LIMIT_VALUES = [
388
547
  "keep_going",
@@ -843,6 +1002,24 @@ function normalizeAdvanced(raw) {
843
1002
  if (typeof source.autoCleanupOrphans === "boolean") {
844
1003
  out.autoCleanupOrphans = source.autoCleanupOrphans;
845
1004
  }
1005
+ if (typeof source.autoCleanupHistory === "boolean") {
1006
+ out.autoCleanupHistory = source.autoCleanupHistory;
1007
+ }
1008
+ if (typeof source.historyMaxCount === "number" && Number.isFinite(source.historyMaxCount)) {
1009
+ out.historyMaxCount = clampHistoryMaxCount(source.historyMaxCount);
1010
+ }
1011
+ if (typeof source.historyMaxDays === "number" && Number.isFinite(source.historyMaxDays)) {
1012
+ out.historyMaxDays = clampHistoryMaxDays(source.historyMaxDays);
1013
+ }
1014
+ if (typeof source.historyCleanupIntervalHours === "number" && Number.isFinite(source.historyCleanupIntervalHours)) {
1015
+ out.historyCleanupIntervalHours = Math.max(
1016
+ 1,
1017
+ Math.min(168, Math.floor(source.historyCleanupIntervalHours))
1018
+ );
1019
+ }
1020
+ if (typeof source.historyLastCleanupAt === "string" && source.historyLastCleanupAt.trim()) {
1021
+ out.historyLastCleanupAt = source.historyLastCleanupAt.trim();
1022
+ }
846
1023
  if (source.orchestrationQuotaOnLimit === "switch_agent" || source.orchestrationQuotaOnLimit === "wait_reset") {
847
1024
  out.orchestrationQuotaOnLimit = source.orchestrationQuotaOnLimit;
848
1025
  }
@@ -1748,6 +1925,24 @@ function updateAdvancedSettings(patch) {
1748
1925
  if (typeof patch.autoCleanupOrphans === "boolean") {
1749
1926
  advanced.autoCleanupOrphans = patch.autoCleanupOrphans;
1750
1927
  }
1928
+ if (typeof patch.autoCleanupHistory === "boolean") {
1929
+ advanced.autoCleanupHistory = patch.autoCleanupHistory;
1930
+ }
1931
+ if (typeof patch.historyMaxCount === "number" && Number.isFinite(patch.historyMaxCount)) {
1932
+ advanced.historyMaxCount = clampHistoryMaxCount(patch.historyMaxCount);
1933
+ }
1934
+ if (typeof patch.historyMaxDays === "number" && Number.isFinite(patch.historyMaxDays)) {
1935
+ advanced.historyMaxDays = clampHistoryMaxDays(patch.historyMaxDays);
1936
+ }
1937
+ if (typeof patch.historyCleanupIntervalHours === "number" && Number.isFinite(patch.historyCleanupIntervalHours)) {
1938
+ advanced.historyCleanupIntervalHours = Math.max(
1939
+ 1,
1940
+ Math.min(168, Math.floor(patch.historyCleanupIntervalHours))
1941
+ );
1942
+ }
1943
+ if (typeof patch.historyLastCleanupAt === "string") {
1944
+ advanced.historyLastCleanupAt = patch.historyLastCleanupAt;
1945
+ }
1751
1946
  if (patch.orchestrationQuotaOnLimit === "switch_agent" || patch.orchestrationQuotaOnLimit === "wait_reset") {
1752
1947
  advanced.orchestrationQuotaOnLimit = patch.orchestrationQuotaOnLimit;
1753
1948
  }
@@ -1798,6 +1993,15 @@ function autoArchiveOnMergeEnabled(settings = loadAppSettings()) {
1798
1993
  function autoCleanupOrphansEnabled(settings = loadAppSettings()) {
1799
1994
  return Boolean(settings.advanced.autoCleanupOrphans);
1800
1995
  }
1996
+ function autoCleanupHistoryEnabled(settings = loadAppSettings()) {
1997
+ return settings.advanced.autoCleanupHistory !== false;
1998
+ }
1999
+ function historyMaxCount(settings = loadAppSettings()) {
2000
+ return clampHistoryMaxCount(settings.advanced.historyMaxCount ?? HISTORY_MAX_COUNT_DEFAULT);
2001
+ }
2002
+ function historyMaxDays(settings = loadAppSettings()) {
2003
+ return clampHistoryMaxDays(settings.advanced.historyMaxDays ?? HISTORY_MAX_DAYS_DEFAULT);
2004
+ }
1801
2005
  function usageOnLimit(settings = loadAppSettings()) {
1802
2006
  return resolveUsageOnLimit(settings.advanced);
1803
2007
  }
@@ -1932,6 +2136,14 @@ export {
1932
2136
  formatWorkspaceProfileSuffix,
1933
2137
  formatViewerContextDirective,
1934
2138
  formatViewerContextReminder,
2139
+ fromInclusiveInputUsage,
2140
+ sumUsageList,
2141
+ applyTurnUsage,
2142
+ contextTokens,
2143
+ HISTORY_CLEANUP_INTERVAL_HOURS_DEFAULT,
2144
+ historyRetentionStubMessage,
2145
+ planHistoryRetention,
2146
+ planHistoryAgePurge,
1935
2147
  USAGE_ON_LIMIT_VALUES,
1936
2148
  isUsageOnLimit,
1937
2149
  resolveUsageOnLimit,
@@ -2001,6 +2213,9 @@ export {
2001
2213
  confirmClaudeUsageOverLimitEnabled,
2002
2214
  autoArchiveOnMergeEnabled,
2003
2215
  autoCleanupOrphansEnabled,
2216
+ autoCleanupHistoryEnabled,
2217
+ historyMaxCount,
2218
+ historyMaxDays,
2004
2219
  usageOnLimit,
2005
2220
  orchestrationQuotaOnLimit,
2006
2221
  orchestrationQuotaFallbackAgent,