ai-agentmanager 1.51.0 → 1.51.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/CHANGELOG.md +6 -0
- package/README.md +4 -4
- package/package.json +1 -1
- package/public/side.js +2 -2
- package/public/style.css +1 -0
- package/public/usage.js +24 -4
- package/src/cli.js +4 -1
- package/src/engines/claude.js +2 -0
- package/src/manager.js +54 -0
- package/src/server.js +3 -0
- package/src/usage.js +33 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.51.1 (2026-11-14)
|
|
4
|
+
|
|
5
|
+
- **Usage: Read now.** The Usage window's ↻ only re-read the last saved reading, which is as old as the last reply of a session started here; Claude Code used elsewhere moved the real numbers on meanwhile. **↻ Read now** (or `agentmgr usage --now`) takes a reading on the spot. Claude Code only reports its limits to a session that has had a reply, so it starts a short session that says one word on its smallest model (a very small amount of usage) and removes it after. The chip and the once-a-minute update never start a session.
|
|
6
|
+
- **The engine new agents start on** shows a pressed **✓ New agents start here** button where the other engines have **Start new agents here**, instead of a label that looked like a button that did nothing.
|
|
7
|
+
- **Debug:** the examples no longer name E2E tests.
|
|
8
|
+
|
|
3
9
|
## 1.51.0 (2026-11-14)
|
|
4
10
|
|
|
5
11
|
- **Usage: what is left of each engine's plan.** A chip by the connection light shows the engine new agents start on with what is used of its limits (`Claude Code 5h 23% · wk 41%`), amber then red as a limit nears. Click it (or **Usage…** in the menu, `z`, `agentmgr usage`) for every engine: each limit's percent used, percent left, and when it resets.
|
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ Run one background [Claude Code](https://claude.com/claude-code) agent per inten
|
|
|
29
29
|
- **Share for review.** One click writes an **Analysis**, **Design**, **Flow** or **Proposal** document from the agent's work, a human time **Estimate** for planning, or the change's **Documentation** with an OpenAPI spec of any API changes. Copy it as Markdown, download it, or print it to PDF with diagrams.
|
|
30
30
|
- **Plan.** A project's commitment dates (code complete, release candidate, GA) with a checklist of what is still open for each, reminders as they come near, and an at-risk or late flag. A **decision log** gathered from plan reviews, your answers and design docs. A **tech debt radar** from git history and the code. What is open can be handed to an agent.
|
|
31
31
|
- **Your day.** Connect your calendar and Today lays the day out around your meetings: the free time between them with what needs you placed in it, and what each meeting is about.
|
|
32
|
-
- **Debug.** Say what to debug (a failure,
|
|
32
|
+
- **Debug.** Say what to debug (a failure, instability at max scale, slowness under load) in the **Debug** tab beside an agent's session. The agent investigates there and writes a report next to it: animated diagrams of the code path and the data flow with where it breaks, findings with evidence, likely causes and recommended fixes. It changes no code until you press **Apply fixes**.
|
|
33
33
|
- **Usage.** How much of each engine's plan limits is used and left (Claude Code's 5-hour session and week, Codex's), and when they reset: a chip by the connection light, an alert near a limit, an option to hold new work at a percent, and one click to start new agents on another engine.
|
|
34
34
|
- **Reverse engineer.** Name a target (an app's folder, a binary, a website) and what you want to understand, in the **Reverse** tab beside an agent's session: the agent investigates with [REA](https://github.com/morluto/rea)'s tools and keeps a report with animated diagrams of how it works, the evidence, what could not be determined, and a plan to build your own version.
|
|
35
35
|
- **Runbooks for support.** A runbook for the support team written from a release ticket, every ticket of an epic, or a project's code changes in a time frame: what changed, what customers may see, how to check it, troubleshooting, rollback, when to escalate, and what to confirm with engineering.
|
|
@@ -195,7 +195,7 @@ agentmgr reverse <agent> -t /path/to/app "how does search work" # reverse engin
|
|
|
195
195
|
agentmgr dates <project> --cc 2026-12-01 --rc 2026-12-10 --ga 2026-12-20 # commitment dates; no dates: where each stands
|
|
196
196
|
agentmgr decisions [project] [--md] # the decision log; --add "<question>" --decision "<what>" adds one
|
|
197
197
|
agentmgr debt <project> --scan # the tech debt radar: files that change often and are hard to read
|
|
198
|
-
agentmgr usage # each engine's plan limits: used, left, resets (--warn 80, --hold 95, --default codex)
|
|
198
|
+
agentmgr usage # each engine's plan limits: used, left, resets (--now, --warn 80, --hold 95, --default codex)
|
|
199
199
|
agentmgr runbook --ticket REL-42 # a support runbook from a release ticket (or --epic KEY, or --since 2026-10-01 -p <project>; -o file.md)
|
|
200
200
|
agentmgr decide # what waits for your decision, with its recommendation (--do <n>, --handled, --standing, --autonomy p=level, --priority, --risk)
|
|
201
201
|
agentmgr os # this computer and its load: processor, memory, disks, what each open session takes (--json)
|
|
@@ -1234,7 +1234,7 @@ A chip by the connection light shows the engine new agents start on with what is
|
|
|
1234
1234
|
- **Hold new work at** a percent (off by default): no new agent starts on an engine at or past it; the backlog waits and New agents says why. Agents already running carry on.
|
|
1235
1235
|
- **Start new agents here** makes another installed engine the default for new agents; agents already running stay where they are (**Continue on** moves one).
|
|
1236
1236
|
|
|
1237
|
-
These are numbers the engines hand out on this computer
|
|
1237
|
+
These are numbers the engines hand out on this computer, so a reading is as old as the last reply of a session started here; Claude Code you use elsewhere moves the real numbers on meanwhile. **↻ Read now** (or `agentmgr usage --now`) brings them up to date: Claude Code only reports its limits to a session that has had a reply, so it starts a short one that says one word on its smallest model (a very small amount of usage) and removes it after. Nothing else calls a model. Turn it off with `"usage": { "enabled": false }` in config.json.
|
|
1238
1238
|
|
|
1239
1239
|
## Reverse engineer
|
|
1240
1240
|
|
|
@@ -1249,7 +1249,7 @@ These are numbers the engines hand out on this computer: no service is asked and
|
|
|
1249
1249
|
|
|
1250
1250
|
## Debug
|
|
1251
1251
|
|
|
1252
|
-
**🐞 Debug** in an agent's detail (or the **Debug** tab of the split, **◫ Split** in the terminal bar) puts the agent's session on the left and the debug pane on the right. Type what is going wrong, for example *
|
|
1252
|
+
**🐞 Debug** in an agent's detail (or the **Debug** tab of the split, **◫ Split** in the terminal bar) puts the agent's session on the left and the debug pane on the right. Type what is going wrong, for example *imports fail at max scale after about 20 minutes* or *p99 latency triples under load*, and press **Debug** (or Enter).
|
|
1253
1253
|
|
|
1254
1254
|
The agent investigates in its own session, with everything it already knows about the work: it reads the code on the path, the logs and the tests, reproduces the problem where it can (the failing test, a small load, a script) and measures. It keeps a report, drawn in the pane as it grows:
|
|
1255
1255
|
|
package/package.json
CHANGED
package/public/side.js
CHANGED
|
@@ -78,8 +78,8 @@ export function initSide({ api, esc, toast, $, agents, codeUi, docHtml, renderDi
|
|
|
78
78
|
// your own), and Reverse engineer also names a target and needs REA's tools.
|
|
79
79
|
const ASK = {
|
|
80
80
|
debug: {
|
|
81
|
-
ideas: ['
|
|
82
|
-
first: 'What should it debug? For example:
|
|
81
|
+
ideas: ['Unstable at max scale', 'Slow or failing under load', 'A flaky test', 'A memory or connection leak', 'Wrong data end to end'],
|
|
82
|
+
first: 'What should it debug? For example: imports fail at max scale after about 20 minutes',
|
|
83
83
|
more: 'A follow-up: what you know, what to look at next, or which fixes to apply',
|
|
84
84
|
go: 'Debug',
|
|
85
85
|
short: 'Say what to debug',
|
package/public/style.css
CHANGED
|
@@ -1467,6 +1467,7 @@ table.plan-debt code { overflow-wrap: anywhere; }
|
|
|
1467
1467
|
.usage-level.ok { color: var(--green); }
|
|
1468
1468
|
.usage-level.warn { color: var(--yellow); border-color: var(--yellow); }
|
|
1469
1469
|
.usage-level.high, .usage-level.held, .usage-level.limited { color: var(--red); border-color: var(--red); }
|
|
1470
|
+
.usage-default-on, .usage-default-on:hover { color: var(--green); border-color: var(--green); }
|
|
1470
1471
|
.usage-settings { display: flex; gap: 18px; flex-wrap: wrap; margin: 6px 0 8px; font-size: 13px; }
|
|
1471
1472
|
.usage-settings label { display: flex; flex-direction: row; align-items: center; gap: 6px; margin: 0; }
|
|
1472
1473
|
.usage-settings select { width: auto; }
|
package/public/usage.js
CHANGED
|
@@ -11,6 +11,7 @@ export function initUsage({ api, $, esc, ago, toast }) {
|
|
|
11
11
|
const chip = $('#usage-chip');
|
|
12
12
|
let data = null;
|
|
13
13
|
let again = null;
|
|
14
|
+
let reading = false;
|
|
14
15
|
|
|
15
16
|
async function load({ quiet = false } = {}) {
|
|
16
17
|
try {
|
|
@@ -50,8 +51,9 @@ export function initUsage({ api, $, esc, ago, toast }) {
|
|
|
50
51
|
</div>`))
|
|
51
52
|
.join('');
|
|
52
53
|
return `<div class="plan-project usage-engine" data-usage-engine="${esc(e.id)}">
|
|
53
|
-
<div class="plan-project-head"><h3>${esc(e.label)}</h3><span class="tag usage-level ${esc(e.level)}">${esc(LEVEL[e.level] ?? e.level)}</span>${e.
|
|
54
|
+
<div class="plan-project-head"><h3>${esc(e.label)}</h3><span class="tag usage-level ${esc(e.level)}">${esc(LEVEL[e.level] ?? e.level)}</span>${e.installed ? '' : '<span class="tag">not installed</span>'}
|
|
54
55
|
<span class="spacer"></span>${e.at ? `<span class="hint">read ${esc(ago(e.at))}${e.source ? ` from ${esc(e.source)}` : ''}</span>` : ''}
|
|
56
|
+
${e.id === data.default ? `<button class="small usage-default-on" aria-pressed="true" data-usage-is-default="${esc(e.label)}" title="New agents start on ${esc(e.label)} unless you pick another engine for them. Press the button on another engine to move them there">✓ New agents start here</button>` : ''}
|
|
55
57
|
${e.installed && e.id !== data.default ? `<button class="small" data-usage-default="${esc(e.id)}" title="New agents start on ${esc(e.label)} unless you pick another engine for them. Agents already running stay where they are">Start new agents here</button>` : ''}</div>
|
|
56
58
|
${e.limited ? `<p class="issues-problem">An agent stopped at a limit${e.limited.resetsIn ? `; it resets ${esc(e.limited.resetsIn)}` : ''}: ${esc(e.limited.text)}</p>` : ''}
|
|
57
59
|
${rows}
|
|
@@ -65,14 +67,14 @@ export function initUsage({ api, $, esc, ago, toast }) {
|
|
|
65
67
|
const s = data.settings;
|
|
66
68
|
const level = (name, v, off) => `<select data-usage-set="${name}" aria-label="${name}"><option value="off" ${v ? '' : 'selected'}>${off}</option>${[50, 60, 70, 75, 80, 85, 90, 95, 100].map((n) => `<option value="${n}" ${v === n ? 'selected' : ''}>${n}% used</option>`).join('')}${v && ![50, 60, 70, 75, 80, 85, 90, 95, 100].includes(v) ? `<option value="${v}" selected>${v}% used</option>` : ''}</select>`;
|
|
67
69
|
body.innerHTML = `
|
|
68
|
-
<div class="issues-head"><h2>Usage</h2><span class="hint">What is used and left of each engine's plan limits</span><span class="spacer"></span><button class="small" data-usage="refresh" title="Read
|
|
70
|
+
<div class="issues-head"><h2>Usage</h2><span class="hint">What is used and left of each engine's plan limits</span><span class="spacer"></span><button class="small" data-usage="refresh" ${reading ? 'disabled' : ''} title="Take a reading now. Claude Code only reports its limits to a session that has had a reply, so this starts a short one that says one word on its smallest model (a very small amount of usage)">${reading ? 'Reading…' : '↻ Read now'}</button><button class="small" data-usage="close" title="Close (Esc)">Close</button></div>
|
|
69
71
|
<div class="issues-scroll usage-scroll">
|
|
70
72
|
${data.engines.map(engineHtml).join('') || '<p class="hint issues-empty">No engine is installed.</p>'}
|
|
71
73
|
<div class="usage-settings">
|
|
72
74
|
<label>Alert me at ${level('warnAt', s.warnAt, 'never')}</label>
|
|
73
75
|
<label title="No new agent starts on an engine at or past this much of a limit (the backlog waits, and New agents says why). Agents already running carry on.">Hold new work at ${level('holdAt', s.holdAt, 'never')}</label>
|
|
74
76
|
</div>
|
|
75
|
-
<p class="hint">These are numbers the engines hand out on this computer: Claude Code gives them to the status line of the sessions started here, Codex writes them in its session logs
|
|
77
|
+
<p class="hint">These are numbers the engines hand out on this computer: Claude Code gives them to the status line of the sessions started here, Codex writes them in its session logs, so a reading is as old as the last reply of a session started here; Claude Code you use elsewhere moves the real numbers on meanwhile. <b>Read now</b> brings them up to date with a one-word session on Claude Code's smallest model. A limit an agent actually hits is shown for any engine until it resets, and the agent carries on by itself when it does.</p>
|
|
76
78
|
</div>`;
|
|
77
79
|
}
|
|
78
80
|
|
|
@@ -87,12 +89,30 @@ export function initUsage({ api, $, esc, ago, toast }) {
|
|
|
87
89
|
draw();
|
|
88
90
|
};
|
|
89
91
|
|
|
92
|
+
/** A reading as of now, not the last one a session happened to bring. */
|
|
93
|
+
async function readNow() {
|
|
94
|
+
if (reading) return;
|
|
95
|
+
reading = true;
|
|
96
|
+
draw();
|
|
97
|
+
try {
|
|
98
|
+
data = await api('POST', '/usage/refresh');
|
|
99
|
+
toast?.(data.problem ?? 'Read just now', data.problem ? 7000 : 2500);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
toast?.(e.message, 6000);
|
|
102
|
+
}
|
|
103
|
+
reading = false;
|
|
104
|
+
drawChip();
|
|
105
|
+
if (dialog.open) draw();
|
|
106
|
+
}
|
|
107
|
+
|
|
90
108
|
body.addEventListener('click', (e) => {
|
|
109
|
+
const on = e.target.closest('[data-usage-is-default]');
|
|
110
|
+
if (on) return toast?.(`New agents already start on ${on.dataset.usageIsDefault}. Press "Start new agents here" on another engine to move them`, 4000);
|
|
91
111
|
const d = e.target.closest('[data-usage-default]');
|
|
92
112
|
if (d) return save({ engine: d.dataset.usageDefault }, 'New agents start there from now on');
|
|
93
113
|
const b = e.target.closest('[data-usage]')?.dataset.usage;
|
|
94
114
|
if (b === 'close') dialog.close();
|
|
95
|
-
else if (b === 'refresh')
|
|
115
|
+
else if (b === 'refresh') readNow();
|
|
96
116
|
});
|
|
97
117
|
body.addEventListener('change', (e) => {
|
|
98
118
|
const s = e.target.closest('[data-usage-set]');
|
package/src/cli.js
CHANGED
|
@@ -829,12 +829,15 @@ export async function main(argv) {
|
|
|
829
829
|
.option('--warn <percent>', 'alert when a limit is this much used (or off)')
|
|
830
830
|
.option('--hold <percent>', 'start no new agents on an engine this much used (or off)')
|
|
831
831
|
.option('--default <engine>', 'the engine new agents start on')
|
|
832
|
+
.option('--now', 'take a reading now: a one-word Claude Code session on its smallest model (a very small amount of usage)')
|
|
832
833
|
.option('--json', 'print JSON')
|
|
833
834
|
.action(async (opts) => {
|
|
834
835
|
await daemon();
|
|
835
836
|
const patch = { ...(opts.warn !== undefined ? { warnAt: opts.warn } : {}), ...(opts.hold !== undefined ? { holdAt: opts.hold } : {}), ...(opts.default ? { engine: opts.default } : {}) };
|
|
836
|
-
|
|
837
|
+
let v = Object.keys(patch).length ? await api('PUT', '/usage', patch) : await api('GET', '/usage');
|
|
838
|
+
if (opts.now) v = await api('POST', '/usage/refresh');
|
|
837
839
|
if (opts.json) return console.log(JSON.stringify(v, null, 2));
|
|
840
|
+
if (v.problem) console.log(yellow(v.problem));
|
|
838
841
|
const tone = { ok: green, warn: yellow, high: red, held: red, limited: red };
|
|
839
842
|
for (const e of v.engines) {
|
|
840
843
|
console.log(`${bold(e.label)}${e.id === v.default ? dim(' (default)') : ''}${e.level === 'held' ? red(' held for new work') : ''}`);
|
package/src/engines/claude.js
CHANGED
|
@@ -20,6 +20,8 @@ export default {
|
|
|
20
20
|
* For the sessions started here (not one-off calls): a status line that records the plan's usage
|
|
21
21
|
* (usage.js). `script` is its path; your own status line still shows (see statusline.js).
|
|
22
22
|
*/
|
|
23
|
+
/** A session that says one word on the smallest model, so the status line has a reply to report after. */
|
|
24
|
+
usageProbeArgs: (sessionId) => ['--model', 'haiku', '--strict-mcp-config', '--session-id', sessionId, '--', 'Reply with the single word: ok'],
|
|
23
25
|
usageArgs: (config, script) => (config.usage?.enabled === false ? [] : ['--settings', JSON.stringify({ statusLine: { type: 'command', command: `${JSON.stringify(process.execPath)} ${JSON.stringify(script)}` } })]),
|
|
24
26
|
|
|
25
27
|
/** Options for every launch: permissions, model, a folder it may write to, extra instructions. */
|
package/src/manager.js
CHANGED
|
@@ -1718,6 +1718,60 @@ export class AgentManager extends EventEmitter {
|
|
|
1718
1718
|
return resumed;
|
|
1719
1719
|
}
|
|
1720
1720
|
|
|
1721
|
+
/**
|
|
1722
|
+
* A reading of Claude Code's plan limits taken now: a short session that says one word, so its
|
|
1723
|
+
* status line (statusline.js) writes the numbers. In a folder of its own; its transcript is
|
|
1724
|
+
* removed after. Resolves true once the reading is written.
|
|
1725
|
+
*/
|
|
1726
|
+
readUsage({ timeoutMs = 45_000, settleMs = 3000 } = {}) {
|
|
1727
|
+
const engine = engineOf(DEFAULT_ENGINE);
|
|
1728
|
+
if (!engine.usageProbeArgs || !installed(engine, this.config)) return Promise.resolve(false);
|
|
1729
|
+
const dir = path.join(path.dirname(usageFile()), 'probe');
|
|
1730
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
1731
|
+
const cwd = fs.realpathSync(dir);
|
|
1732
|
+
try {
|
|
1733
|
+
engine.trust(cwd); // the app's own empty folder: no "do you trust this folder?" to answer
|
|
1734
|
+
} catch {}
|
|
1735
|
+
const sessionId = crypto.randomUUID();
|
|
1736
|
+
const mtime = () => {
|
|
1737
|
+
try {
|
|
1738
|
+
return fs.statSync(usageFile()).mtimeMs;
|
|
1739
|
+
} catch {
|
|
1740
|
+
return 0;
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
const before = mtime();
|
|
1744
|
+
return new Promise((resolve) => {
|
|
1745
|
+
let proc;
|
|
1746
|
+
try {
|
|
1747
|
+
proc = pty.spawn(engine.bin(this.config), [...engine.extraArgs(this.config), ...engine.usageArgs(this.config, statusLineScript()), ...engine.usageProbeArgs(sessionId)], { name: 'xterm-256color', cols: 120, rows: 34, cwd, env: this.childEnv(null) });
|
|
1748
|
+
} catch {
|
|
1749
|
+
return resolve(false);
|
|
1750
|
+
}
|
|
1751
|
+
const started = Date.now();
|
|
1752
|
+
let wrote = null;
|
|
1753
|
+
let done = false;
|
|
1754
|
+
const finish = (ok) => {
|
|
1755
|
+
if (done) return;
|
|
1756
|
+
done = true;
|
|
1757
|
+
clearInterval(timer);
|
|
1758
|
+
try {
|
|
1759
|
+
proc.kill();
|
|
1760
|
+
} catch {}
|
|
1761
|
+
fs.rm(engine.sessionFile(cwd, sessionId), { force: true }, () => {});
|
|
1762
|
+
resolve(ok);
|
|
1763
|
+
};
|
|
1764
|
+
// The first reading can come as the reply starts; a moment more catches the one after it.
|
|
1765
|
+
const timer = setInterval(() => {
|
|
1766
|
+
if (!wrote && mtime() > before) wrote = Date.now();
|
|
1767
|
+
if (wrote && Date.now() - wrote >= settleMs) finish(true);
|
|
1768
|
+
else if (Date.now() - started > timeoutMs) finish(Boolean(wrote));
|
|
1769
|
+
}, 250);
|
|
1770
|
+
proc.onData(() => {});
|
|
1771
|
+
proc.onExit(() => finish(Boolean(wrote) || mtime() > before));
|
|
1772
|
+
});
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1721
1775
|
childEnv(agent) {
|
|
1722
1776
|
const env = { ...process.env, ...(agent ? { AGENTMGR_AGENT_ID: agent.id } : {}), TERM: 'xterm-256color', COLORTERM: 'truecolor', AGENTMGR_TERMINAL: '1', AGENTMGR_USAGE_FILE: usageFile(), AGENTMGR_USER_STATUSLINE: ownStatusLine() };
|
|
1723
1777
|
for (const key of STRIP_ENV) delete env[key];
|
package/src/server.js
CHANGED
|
@@ -330,6 +330,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
330
330
|
store,
|
|
331
331
|
config,
|
|
332
332
|
engines: () => listEngines(config),
|
|
333
|
+
probe: () => manager.readUsage(),
|
|
333
334
|
onChange: () => pushUsage(),
|
|
334
335
|
notify: async (text, plain) => {
|
|
335
336
|
const n = loadNotify();
|
|
@@ -1134,6 +1135,8 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
1134
1135
|
api.post('/milestones/:project/task', wrap((req) => milestones.task(req.params.project, req.body?.stage, req.body?.item)));
|
|
1135
1136
|
// Plan → Decisions: the log (?project=<key>&q=<words>; ?format=markdown), one of your own, and removal.
|
|
1136
1137
|
api.get('/usage', wrap(() => usage.view()));
|
|
1138
|
+
// A reading taken now (a one-word Claude Code session, so its status line reports).
|
|
1139
|
+
api.post('/usage/refresh', wrap(() => usage.refresh()));
|
|
1137
1140
|
api.put('/usage', wrap((req) => {
|
|
1138
1141
|
const b = req.body ?? {};
|
|
1139
1142
|
const next = usage.update(b);
|
package/src/usage.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
// Codex - the rate limits Codex writes in its session logs, when it reports them.
|
|
7
7
|
// any engine - a limit an agent actually hit ("usage limit reached… resets 3pm") counts as used
|
|
8
8
|
// up until it resets.
|
|
9
|
-
// Engines that report nothing are listed as that.
|
|
10
|
-
//
|
|
9
|
+
// Engines that report nothing are listed as that. These are numbers the engines already hand out on
|
|
10
|
+
// this computer; nothing else is asked of any service. "Read now" is the one thing that uses a
|
|
11
|
+
// model: a one-word session on Claude Code's smallest model, so there is a reply to report after.
|
|
11
12
|
|
|
12
13
|
import fs from 'node:fs';
|
|
13
14
|
import path from 'node:path';
|
|
@@ -71,10 +72,11 @@ const NOTES = {
|
|
|
71
72
|
export class EngineUsage {
|
|
72
73
|
/**
|
|
73
74
|
* `engines()`: the engines as listEngines gives them ({ id, label, installed }); `notify(text,
|
|
74
|
-
* plain)`: an alert; `store`: where the readings are kept between restarts
|
|
75
|
+
* plain)`: an alert; `store`: where the readings are kept between restarts; `probe()`: takes a
|
|
76
|
+
* reading of Claude Code's limits now (a short session), resolving true once it is written.
|
|
75
77
|
*/
|
|
76
|
-
constructor({ store, config, engines, notify = null, onChange = () => {}, file = usageFile(), now = () => Date.now(), log = (m) => console.log(`[agentmgr] ${m}`), timer = true }) {
|
|
77
|
-
Object.assign(this, { store, config, engines, notify, onChange, file, now, log });
|
|
78
|
+
constructor({ store, config, engines, notify = null, probe = null, onChange = () => {}, file = usageFile(), now = () => Date.now(), log = (m) => console.log(`[agentmgr] ${m}`), timer = true }) {
|
|
79
|
+
Object.assign(this, { store, config, engines, notify, probe, onChange, file, now, log });
|
|
78
80
|
this.fileAt = null;
|
|
79
81
|
if (timer) {
|
|
80
82
|
this.timer = setInterval(() => this.tick(), 20_000);
|
|
@@ -164,6 +166,32 @@ export class EngineUsage {
|
|
|
164
166
|
this.readClaude();
|
|
165
167
|
}
|
|
166
168
|
|
|
169
|
+
/**
|
|
170
|
+
* A reading taken now. Claude Code only gives its numbers to a session that has had a reply, so
|
|
171
|
+
* this starts a short one that says one word (the probe).
|
|
172
|
+
* One at a time: asked again meanwhile, it is the same reading.
|
|
173
|
+
*/
|
|
174
|
+
refresh() {
|
|
175
|
+
return (this.refreshing ??= (async () => {
|
|
176
|
+
let fresh = false;
|
|
177
|
+
let problem = null;
|
|
178
|
+
try {
|
|
179
|
+
const claude = this.engines().find((d) => d.id === 'claude');
|
|
180
|
+
if (!this.settings.enabled) problem = 'Usage readings are switched off';
|
|
181
|
+
else if (!this.probe || !claude || claude.installed === false) problem = 'Claude Code is not installed here, and no other engine can be asked for a reading';
|
|
182
|
+
else {
|
|
183
|
+
fresh = await this.probe();
|
|
184
|
+
this.readClaude();
|
|
185
|
+
if (!fresh) problem = 'Claude Code gave no reading. It reports its limits for Pro, Max and Ultra plans, once signed in';
|
|
186
|
+
}
|
|
187
|
+
} catch (e) {
|
|
188
|
+
problem = e.message;
|
|
189
|
+
}
|
|
190
|
+
this.onChange();
|
|
191
|
+
return { ...this.view(), fresh, problem };
|
|
192
|
+
})().finally(() => (this.refreshing = null)));
|
|
193
|
+
}
|
|
194
|
+
|
|
167
195
|
/** One engine as it stands now: its windows with what is left, and how worried to be. */
|
|
168
196
|
engineView(def) {
|
|
169
197
|
const now = this.now();
|