@thegitai/cli 1.0.0-preview.55 → 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 +11 -0
- package/dist/src/api/chat.js +4 -0
- package/dist/src/ui/repl.js +21 -9
- package/dist/src/ui/tui/build-frame.js +4 -0
- package/dist/src/ui/tui/markdown-render.js +10 -9
- package/dist/src/ui/tui/text.js +31 -6
- package/dist/src/usage-notice.js +47 -0
- package/package.json +6 -6
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
|
package/dist/src/api/chat.js
CHANGED
|
@@ -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)
|
package/dist/src/ui/repl.js
CHANGED
|
@@ -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
|
|
960
|
-
|
|
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(''));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { displayWidth, line, padToWidth, plainLine, sliceToWidth, span, wrapText, wrapToWidth, } from './text.js';
|
|
1
|
+
import { displayWidth, expandTabs, line, padToWidth, plainLine, sliceToWidth, span, wrapText, wrapToWidth, } from './text.js';
|
|
2
2
|
const MIN_TABLE_COLUMN_WIDTH = 3;
|
|
3
3
|
function tableRowOverhead(columnCount) {
|
|
4
4
|
return 3 * columnCount + 1;
|
|
@@ -178,10 +178,10 @@ function parseMarkdownTableBlock(lines, startIndex) {
|
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
function splitFormattedLines(body) {
|
|
181
|
-
const
|
|
181
|
+
const normalizedBody = String(body ?? '')
|
|
182
182
|
.replace(/\r\n/g, '\n')
|
|
183
|
-
.replace(/\r/g, '\n')
|
|
184
|
-
|
|
183
|
+
.replace(/\r/g, '\n');
|
|
184
|
+
const lines = expandTabs(normalizedBody).split('\n');
|
|
185
185
|
const formatted = [];
|
|
186
186
|
let inCodeBlock = false;
|
|
187
187
|
for (let index = 0; index < lines.length; index++) {
|
|
@@ -410,7 +410,7 @@ export function renderFormattedBodyLines(body, width, kind) {
|
|
|
410
410
|
if (prev && prev.kind !== 'code' && prev.kind !== 'blank') {
|
|
411
411
|
output.push(plainLine(''));
|
|
412
412
|
}
|
|
413
|
-
for (const wrapped of wrapText(formattedLine.text || ' ',
|
|
413
|
+
for (const wrapped of wrapText(formattedLine.text || ' ', Math.max(1, width - 4))) {
|
|
414
414
|
output.push(plainLine(` ${wrapped}`, { color: 'cyan' }));
|
|
415
415
|
}
|
|
416
416
|
const next = formatted[index + 1];
|
|
@@ -446,16 +446,17 @@ export function renderPreformattedBodyLines(body, width, kind) {
|
|
|
446
446
|
const bodyColor = kind === 'error' ? 'red' : undefined;
|
|
447
447
|
const bodyWidth = Math.max(1, width - 8);
|
|
448
448
|
const output = [];
|
|
449
|
-
const normalizedBody = String(body ?? '').replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
449
|
+
const normalizedBody = expandTabs(String(body ?? '').replace(/\r\n/g, '\n').replace(/\r/g, '\n'));
|
|
450
450
|
for (const rawLine of normalizedBody.split('\n')) {
|
|
451
451
|
if (rawLine === '') {
|
|
452
452
|
output.push(plainLine(''));
|
|
453
453
|
continue;
|
|
454
454
|
}
|
|
455
455
|
let remaining = rawLine;
|
|
456
|
-
while (remaining
|
|
457
|
-
|
|
458
|
-
|
|
456
|
+
while (displayWidth(remaining) > bodyWidth) {
|
|
457
|
+
const head = sliceToWidth(remaining, bodyWidth);
|
|
458
|
+
output.push(plainLine(` ${head}`, { color: bodyColor }));
|
|
459
|
+
remaining = remaining.slice(head.length);
|
|
459
460
|
}
|
|
460
461
|
output.push(plainLine(` ${remaining}`, { color: bodyColor }));
|
|
461
462
|
}
|
package/dist/src/ui/tui/text.js
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
1
|
-
const CSI_PATTERN =
|
|
2
|
-
const OSC_PATTERN =
|
|
3
|
-
const
|
|
1
|
+
const CSI_PATTERN = /(?:\u001B\[|\u009B)[0-?]*[ -\/]*[@-~]/g;
|
|
2
|
+
const OSC_PATTERN = /(?:\u001B\]|\u009D)[^\u0007\u001B\u009C]*(?:\u0007|\u001B\\|\u009C)?/g;
|
|
3
|
+
const STRING_CONTROL_PATTERN = /(?:\u001B[PX^_]|[\u0090\u0098\u009E\u009F])[^\u001B\u009C]*(?:\u001B\\|\u009C)?/g;
|
|
4
|
+
const ESC_PATTERN = /\u001B[ -\/]*[0-~]/g;
|
|
5
|
+
const CONTROL_CHAR_PATTERN = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g;
|
|
4
6
|
export function stripControlCharacters(text) {
|
|
5
7
|
return String(text ?? '')
|
|
6
8
|
.replace(OSC_PATTERN, '')
|
|
9
|
+
.replace(STRING_CONTROL_PATTERN, '')
|
|
7
10
|
.replace(CSI_PATTERN, '')
|
|
11
|
+
.replace(ESC_PATTERN, '')
|
|
8
12
|
.replace(CONTROL_CHAR_PATTERN, '');
|
|
9
13
|
}
|
|
14
|
+
export function expandTabs(text, initialColumn = 0) {
|
|
15
|
+
let column = initialColumn;
|
|
16
|
+
return stripControlCharacters(text).split(/(\t|\n)/).map((part) => {
|
|
17
|
+
if (part === '\n') {
|
|
18
|
+
column = 0;
|
|
19
|
+
return part;
|
|
20
|
+
}
|
|
21
|
+
if (part === '\t') {
|
|
22
|
+
const spaces = 8 - column % 8;
|
|
23
|
+
column += spaces;
|
|
24
|
+
return ' '.repeat(spaces);
|
|
25
|
+
}
|
|
26
|
+
column += displayWidth(part);
|
|
27
|
+
return part;
|
|
28
|
+
}).join('');
|
|
29
|
+
}
|
|
10
30
|
export function span(text, style = {}) {
|
|
11
31
|
return { text: stripControlCharacters(text), ...style };
|
|
12
32
|
}
|
|
13
33
|
export function line(...spans) {
|
|
14
|
-
|
|
34
|
+
let column = 0;
|
|
35
|
+
return { spans: spans.map((part) => {
|
|
36
|
+
const text = expandTabs(part.text.replace(/\n/g, ' '), column);
|
|
37
|
+
column += displayWidth(text);
|
|
38
|
+
return { ...part, text };
|
|
39
|
+
}) };
|
|
15
40
|
}
|
|
16
41
|
export function plainLine(text, style = {}) {
|
|
17
42
|
return line(span(text, style));
|
|
@@ -21,7 +46,7 @@ export function wrapText(text, width) {
|
|
|
21
46
|
if (!text)
|
|
22
47
|
return [''];
|
|
23
48
|
const lines = [];
|
|
24
|
-
for (const rawLine of text.split('\n')) {
|
|
49
|
+
for (const rawLine of expandTabs(text).split('\n')) {
|
|
25
50
|
let remaining = rawLine;
|
|
26
51
|
while (displayWidth(remaining) > safeWidth) {
|
|
27
52
|
const head = sliceToWidth(remaining, safeWidth);
|
|
@@ -152,7 +177,7 @@ export function padToWidth(text, width) {
|
|
|
152
177
|
export function wrapToWidth(text, width) {
|
|
153
178
|
const limit = Math.max(1, Math.floor(width));
|
|
154
179
|
const out = [];
|
|
155
|
-
for (const rawLine of
|
|
180
|
+
for (const rawLine of expandTabs(text).split('\n')) {
|
|
156
181
|
let current = '';
|
|
157
182
|
const flush = () => {
|
|
158
183
|
out.push(current);
|
|
@@ -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.
|
|
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.
|
|
49
|
-
"@thegitai/tui-darwin-x64": "1.0.0-preview.
|
|
50
|
-
"@thegitai/tui-linux-arm64": "1.0.0-preview.
|
|
51
|
-
"@thegitai/tui-linux-x64": "1.0.0-preview.
|
|
52
|
-
"@thegitai/tui-win32-x64": "1.0.0-preview.
|
|
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": {
|