hi-ai-cli 0.1.0 → 0.1.1
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 +2 -2
- package/lib/usage.mjs +9 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ A small, usage-aware utility for **Claude Code and Codex**, on macOS and Linux.
|
|
|
13
13
|
|
|
14
14
|
HiAI uses lightweight models by default: Claude's `haiku` alias and Codex's `gpt-6-luna`. It has no npm runtime dependencies, GUI, or HiAI account.
|
|
15
15
|
|
|
16
|
-
**Release status: 0.1.
|
|
16
|
+
**Release status: 0.1.1.** Usage readers, timing decisions, failure recovery, and native schedulers have tests. Live usage reads, background delivery, and the idle → hello → newly active window transition have been observed on real accounts on macOS; see [Validation](#validation) for what is and is not covered. A hello consumes usage; the provider controls quota and billing.
|
|
17
17
|
|
|
18
18
|
## Install
|
|
19
19
|
|
|
@@ -100,7 +100,7 @@ A saved provider failure is a completed scheduled check, so the scheduler proces
|
|
|
100
100
|
|
|
101
101
|
**Claude:** HiAI runs the installed, unmodified `claude -p /usage --safe-mode --no-session-persistence --output-format json` command. Claude Code owns login and credential refresh. HiAI does not read the Keychain, credential files, access tokens, or refresh tokens, and makes no direct Anthropic HTTP requests.
|
|
102
102
|
|
|
103
|
-
The command uses a deliberately invalid model name, so a CLI that stops recognizing `/usage` locally cannot silently turn the check into a normal model request. HiAI requires a local `usage` result with zero turns, zero API duration, zero cost, and no model usage before parsing the current-session and all-model weekly lines. The human-readable reset includes a timezone and
|
|
103
|
+
The command uses a deliberately invalid model name, so a CLI that stops recognizing `/usage` locally cannot silently turn the check into a normal model request. HiAI requires a local `usage` result with zero turns, zero API duration, zero cost, and no model usage before parsing the current-session and all-model weekly lines. The human-readable reset includes a timezone, and its wording follows the platform's date formatting: `Nov 13 at 5am` on macOS, `Nov 13, 5am` on Linux, with the year added when the reset falls in the next year. HiAI accepts both forms and handles timezone offsets, year rollover, and daylight-saving changes. Missing or changed output counts as a failed read. Both session states have been captured live: an active session names its reset time, and an idle session reads `0% used` with no reset time.
|
|
104
104
|
|
|
105
105
|
**Codex:** HiAI starts the installed CLI's app server and calls the documented [`account/rateLimits/read`](https://learn.chatgpt.com/docs/app-server) method. It creates no thread or inference turn and does not parse Codex credential files. An idle Codex account reports an unused window whose reset time moves forward with every read, while a started window keeps a fixed reset. When the window is unused, HiAI reads twice, two seconds apart, and treats a moving reset as idle.
|
|
106
106
|
|
package/lib/usage.mjs
CHANGED
|
@@ -52,18 +52,24 @@ function wallTime(formatter, parts) {
|
|
|
52
52
|
return candidates.size ? Math.max(...candidates) : NaN;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// Claude Code formats resets with its runtime's ICU data, which joins the date
|
|
56
|
+
// and time with " at " (macOS system ICU) or ", " (the ICU bundled on Linux),
|
|
57
|
+
// and adds the year only when the reset falls in a different year.
|
|
58
|
+
const CLAUDE_RESET = /^(?:(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{1,2})(?:,\s(\d{4}))?(?:\sat|,)\s)?(\d{1,2})(?::(\d{2}))?\s*(am|pm)\s\(([^()]+)\)$/i;
|
|
59
|
+
|
|
55
60
|
function claudeReset(text, now, maximumDelay) {
|
|
56
|
-
const match =
|
|
61
|
+
const match = CLAUDE_RESET.exec(text);
|
|
57
62
|
if (!match) throw new Error('Claude /usage reset format is unrecognized.');
|
|
58
|
-
const [, monthName, dayText, hourText, minuteText = '0', period, zone] = match;
|
|
63
|
+
const [, monthName, dayText, yearText, hourText, minuteText = '0', period, zone] = match;
|
|
59
64
|
const hour = Number(hourText); const minute = Number(minuteText);
|
|
60
65
|
if (hour < 1 || hour > 12 || minute > 59) throw new Error('Claude /usage reset time is invalid.');
|
|
61
66
|
let formatter;
|
|
62
67
|
try { formatter = new Intl.DateTimeFormat('en-US', { timeZone: zone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }); }
|
|
63
68
|
catch { throw new Error('Claude /usage timezone is invalid.'); }
|
|
64
69
|
const current = localParts(formatter, now);
|
|
70
|
+
const month = monthName && months.findIndex(name => name.toLowerCase() === monthName.toLowerCase()) + 1;
|
|
65
71
|
const dates = monthName
|
|
66
|
-
? [-1, 0, 1].map(offset =>
|
|
72
|
+
? (yearText ? [Number(yearText)] : [-1, 0, 1].map(offset => current[0] + offset)).map(year => [year, month, Number(dayText)])
|
|
67
73
|
: [0, 1].map(offset => { const date = new Date(Date.UTC(current[0], current[1] - 1, current[2] + offset)); return [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()]; });
|
|
68
74
|
const candidates = dates.map(date => wallTime(formatter, [...date, hour % 12 + (period.toLowerCase() === 'pm' ? 12 : 0), minute]) + 60_000)
|
|
69
75
|
.filter(time => Number.isFinite(time) && time >= now - 60_000 && time <= now + maximumDelay);
|