@thegitai/cli 1.0.0-preview.56 → 1.0.0-preview.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -40,6 +40,17 @@ ai --version print the version and exit
40
40
 
41
41
  Run `ai --help` for sessions, modes, keys, and chat commands.
42
42
 
43
+ The CLI shows a usage notice at 80% and 95% of your 5-hour, weekly, or monthly
44
+ allowance while work continues. Notices include when usage starts resetting in
45
+ your local time and a reminder to run `/usage`. Windows crossing a threshold
46
+ together share one notice. While the CLI stays open, the 80% notice rearms only
47
+ below 75% usage and the 95% notice only below 90%, so small fluctuations stay
48
+ quiet. Restarting the CLI can show a notice again. A nearly exhausted allowance
49
+ displays "over 99%". Live notices clear when a turn ends or is cancelled, and
50
+ remain in the transcript. Usage updates arrive when a turn starts and after
51
+ usage is saved during and at the end of the turn. An exhausted allowance still
52
+ shows `Usage limit reached`.
53
+
43
54
  Coding sessions require an interactive terminal on stdin and stdout. Piped
44
55
  one-shot prompts are not supported. Saved history is local to the repo and can
45
56
  always be viewed or resumed from that computer. Continuing it through the
@@ -551,6 +551,10 @@ async function runTurnStream({ openStream, config, session, input, request, reco
551
551
  lastEventId = event.id;
552
552
  const data = event.data;
553
553
  switch (event.event) {
554
+ case 'account-usage': {
555
+ session.onAccountUsage?.(data);
556
+ break;
557
+ }
554
558
  case 'turn-start': {
555
559
  const turnId = String(data?.turnId ?? '').trim();
556
560
  if (!turnId)
@@ -27,6 +27,7 @@ import { isTurnFailureMarker } from '../turn-failure-marker.js';
27
27
  import { clearCliAuthConfig, logoutFromServer, } from '../api/auth.js';
28
28
  import { authenticationErrorMessage, isAuthenticationError, } from '../api/http.js';
29
29
  import { buildQuotaNotice } from '../quota-notice.js';
30
+ import { createUsageNoticeTracker } from '../usage-notice.js';
30
31
  import { createUserInputPromptState, formatUserInputTranscript, } from './tui/user-input.js';
31
32
  import { setCommandOutputHook, withTuiMode } from '../runtime-mode.js';
32
33
  import { collectBackgroundJobUiKillMutations, collectBackgroundJobUiOutputMutations, } from '../tool-executor.js';
@@ -940,7 +941,7 @@ export function closedJobsPickerFields(state) {
940
941
  jobsPickerReturnStatus: null,
941
942
  };
942
943
  }
943
- function createShellStore(initialState) {
944
+ export function createShellStore(initialState) {
944
945
  let state = initialState;
945
946
  let nextEntryId = 1;
946
947
  const listeners = new Set();
@@ -948,6 +949,10 @@ function createShellStore(initialState) {
948
949
  for (const listener of listeners)
949
950
  listener();
950
951
  };
952
+ const setState = (nextState) => {
953
+ state = nextState.busy ? nextState : { ...nextState, usageNotice: null };
954
+ notify();
955
+ };
951
956
  return {
952
957
  getState: () => state,
953
958
  subscribe: (listener) => {
@@ -956,14 +961,8 @@ function createShellStore(initialState) {
956
961
  listeners.delete(listener);
957
962
  };
958
963
  },
959
- setState: (nextState) => {
960
- state = nextState;
961
- notify();
962
- },
963
- update: (updater) => {
964
- state = updater(state);
965
- notify();
966
- },
964
+ setState,
965
+ update: (updater) => setState(updater(state)),
967
966
  appendEntry: (entry) => {
968
967
  const id = nextEntryId++;
969
968
  state = {
@@ -1433,6 +1432,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
1433
1432
  let tuiReady = false;
1434
1433
  let lastTurnStartedAt = null;
1435
1434
  let latestUsageSummary = null;
1435
+ const usageNotice = createUsageNoticeTracker();
1436
1436
  let pendingTurnEntries = [];
1437
1437
  let activeTurnAbort = null;
1438
1438
  let activeTurnImageAttachments = [];
@@ -2852,6 +2852,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
2852
2852
  clockNow: turnStartedAt,
2853
2853
  recoveryStatus: '',
2854
2854
  status: 'Running turn...',
2855
+ usageNotice: null,
2855
2856
  thinkingTitle: '',
2856
2857
  thinkingNotes: [],
2857
2858
  transcriptScrollOffset: 0,
@@ -2904,6 +2905,7 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
2904
2905
  commandLog: [],
2905
2906
  imageAttachments: [],
2906
2907
  status: result.waitingForApproval ? 'Awaiting approval' : 'Finishing response...',
2908
+ usageNotice: null,
2907
2909
  thinkingTitle: '',
2908
2910
  thinkingNotes: [],
2909
2911
  tokenUsage: formatClientTokenUsage(Date.now() - turnStartedAt, latestUsageSummary),
@@ -3026,6 +3028,16 @@ export async function runClientInteractive({ appendPromptHistory, authConfig, de
3026
3028
  scheduleJobFollowUp();
3027
3029
  }
3028
3030
  };
3031
+ session.onAccountUsage = (usage) => {
3032
+ const notice = usageNotice(usage);
3033
+ if (!notice)
3034
+ return;
3035
+ const entry = { ...notice, kind: 'system' };
3036
+ appendTurnAwareEntry(entry);
3037
+ if (store.getState().busy) {
3038
+ store.update((current) => ({ ...current, usageNotice: entry }));
3039
+ }
3040
+ };
3029
3041
  session.onImageAnalysis = (activeImageCount) => {
3030
3042
  store.update((current) => ({
3031
3043
  ...current,
@@ -768,6 +768,10 @@ function buildLiveLines(state, width, spinnerFrame, elapsedSeconds, nowMs) {
768
768
  if (state.recoveryStatus) {
769
769
  lines.push(...buildRecoveryStatusLines(state.recoveryStatus, width));
770
770
  }
771
+ if (state.usageNotice) {
772
+ lines.push(plainLine(''));
773
+ lines.push(...renderTranscriptEntryLines(state.usageNotice, width));
774
+ }
771
775
  const turnMessages = state.turnMessages ?? [];
772
776
  if (turnMessages.length > 0) {
773
777
  lines.push(plainLine(''));
@@ -0,0 +1,47 @@
1
+ import { USAGE_WINDOWS } from './usage.js';
2
+ function resetDescription(resetsAt, now) {
3
+ const minutes = Math.max(1, Math.ceil((resetsAt - now) / 60_000));
4
+ const hours = Math.floor(minutes / 60);
5
+ const days = Math.floor(hours / 24);
6
+ const remaining = days > 0
7
+ ? `${days}d ${hours % 24}h`
8
+ : hours > 0
9
+ ? `${hours}h ${minutes % 60}m`
10
+ : `${minutes}m`;
11
+ const time = new Intl.DateTimeFormat(undefined, {
12
+ month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', timeZoneName: 'short',
13
+ }).format(resetsAt);
14
+ return `Usage starts resetting in ${remaining}, at ${time}.`;
15
+ }
16
+ export function createUsageNoticeTracker() {
17
+ const shown = new Map();
18
+ return (usage, now = Date.now()) => {
19
+ const lines = [];
20
+ for (const [label, window] of USAGE_WINDOWS) {
21
+ const left = usage?.percentLeft?.[window];
22
+ if (typeof left !== 'number' || !Number.isFinite(left) || left < 0 || left > 100)
23
+ continue;
24
+ const used = 100 - left;
25
+ if (used < 75)
26
+ shown.delete(window);
27
+ else if (used < 90 && shown.get(window) === 95)
28
+ shown.set(window, 80);
29
+ const threshold = used >= 95 ? 95 : used >= 80 ? 80 : 0;
30
+ const previous = shown.get(window) ?? 0;
31
+ if (!threshold || threshold <= previous)
32
+ continue;
33
+ const reset = usage?.resetsAt?.[window];
34
+ const resetsAt = typeof reset === 'string' ? Date.parse(reset) : NaN;
35
+ if (!Number.isFinite(resetsAt) || resetsAt <= now)
36
+ continue;
37
+ shown.set(window, threshold);
38
+ const percent = used === 100 ? 'over 99%' : `${Math.floor(used)}%`;
39
+ lines.push(`You've used ${percent} of your ${label.toLowerCase()} allowance.`);
40
+ lines.push(resetDescription(resetsAt, now));
41
+ }
42
+ if (!lines.length)
43
+ return null;
44
+ lines.push('Run /usage for details.');
45
+ return { title: 'Usage notice', body: lines.join('\n') };
46
+ };
47
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thegitai/cli",
3
- "version": "1.0.0-preview.56",
3
+ "version": "1.0.0-preview.58",
4
4
  "description": "TheGitAI is an agentic AI coding tool for your terminal. It reads and searches your repository, writes and edits files, runs your tests, and verifies the change before handing it back.",
5
5
  "keywords": [
6
6
  "agentic-ai",
@@ -45,11 +45,11 @@
45
45
  "@lydell/node-pty-linux-x64": "1.1.0",
46
46
  "@lydell/node-pty-win32-arm64": "1.1.0",
47
47
  "@lydell/node-pty-win32-x64": "1.1.0",
48
- "@thegitai/tui-darwin-arm64": "1.0.0-preview.56",
49
- "@thegitai/tui-darwin-x64": "1.0.0-preview.56",
50
- "@thegitai/tui-linux-arm64": "1.0.0-preview.56",
51
- "@thegitai/tui-linux-x64": "1.0.0-preview.56",
52
- "@thegitai/tui-win32-x64": "1.0.0-preview.56",
48
+ "@thegitai/tui-darwin-arm64": "1.0.0-preview.58",
49
+ "@thegitai/tui-darwin-x64": "1.0.0-preview.58",
50
+ "@thegitai/tui-linux-arm64": "1.0.0-preview.58",
51
+ "@thegitai/tui-linux-x64": "1.0.0-preview.58",
52
+ "@thegitai/tui-win32-x64": "1.0.0-preview.58",
53
53
  "@vscode/ripgrep": "1.18.0"
54
54
  },
55
55
  "repository": {