@agentguard-run/burn 0.7.1 → 0.7.3
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 +16 -0
- package/README.md +18 -0
- package/dist/src/cli.js +44 -2
- package/dist/src/idle/hook.js +7 -0
- package/dist/src/idle/memory.d.ts +38 -0
- package/dist/src/idle/memory.js +225 -0
- package/dist/src/idle/render.js +1 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +20 -1
- package/dist/src/insights/i18n.d.ts +39 -0
- package/dist/src/insights/i18n.js +80 -1
- package/dist/src/insights/models.d.ts +169 -0
- package/dist/src/insights/models.js +280 -0
- package/dist/src/insights/pricing.js +2 -0
- package/dist/src/insights/status-fields.d.ts +19 -0
- package/dist/src/insights/status-fields.js +46 -0
- package/dist/src/insights/status-machine.d.ts +21 -0
- package/dist/src/insights/status-machine.js +53 -0
- package/dist/src/insights/status-text.d.ts +30 -0
- package/dist/src/insights/status-text.js +9 -0
- package/package.json +1 -1
|
@@ -32,6 +32,12 @@ function statusCount(n) {
|
|
|
32
32
|
function money(value, range) {
|
|
33
33
|
return Math.abs(value.max - value.min) < .000001 ? `$${value.min.toFixed(2)}` : `$${value.min.toFixed(2)} ${range} $${value.max.toFixed(2)}`;
|
|
34
34
|
}
|
|
35
|
+
function gigabytes(bytes, short = false) {
|
|
36
|
+
// Under 10 GB one decimal place, from 10 GB whole numbers. The switch is made on
|
|
37
|
+
// the rounded tenths so 9.96 reads "10" (not "10.0"), and each side rounds once.
|
|
38
|
+
const tenths = Math.round(bytes / 1e8), text = tenths >= 100 ? String(Math.round(bytes / 1e9)) : (tenths / 10).toFixed(1);
|
|
39
|
+
return short ? `${text}G` : `${text} GB`;
|
|
40
|
+
}
|
|
35
41
|
function duration(minutes) {
|
|
36
42
|
const n = Math.max(0, Math.round(minutes / 10) * 10);
|
|
37
43
|
return '~' + (n >= 60 ? `${Math.floor(n / 60)}h` : '') + (n % 60 || n < 60 ? `${n % 60}m` : '');
|
|
@@ -70,6 +76,31 @@ function formatStatusFields(input) {
|
|
|
70
76
|
const ctx = input.context && Number.isFinite(input.context.tokens) && input.context.tokens >= 0 &&
|
|
71
77
|
Number.isFinite(input.context.threshold) && input.context.threshold > 0 ? input.context : null;
|
|
72
78
|
const left = ctx ? Math.max(0, Math.round(100 - (100 * ctx.tokens) / ctx.threshold)) : null;
|
|
79
|
+
const whole = (n) => typeof n === 'number' && Number.isFinite(n) && n >= 0;
|
|
80
|
+
// The machine parts come from outside this file. Each value is read once and
|
|
81
|
+
// copied into a fresh object in one of the few shapes drawn below: a share
|
|
82
|
+
// from 0 to 100 with a known level, or an unread share marked unknown; a low
|
|
83
|
+
// disk; swap in use. Anything else is malformed and draws nothing, never a quiet "fine".
|
|
84
|
+
const object = (v) => v && typeof v === 'object' && !Array.isArray(v) ? v : null;
|
|
85
|
+
let memory = null;
|
|
86
|
+
let disk = null, swap = null;
|
|
87
|
+
try {
|
|
88
|
+
const machine = object(input.machine), m = object(machine?.memory), d = object(machine?.disk), s = object(machine?.swap);
|
|
89
|
+
const share = m?.availablePercent, shareLevel = m?.level, free = d?.freeBytes, freeLevel = d?.level, used = s?.usedBytes;
|
|
90
|
+
if (m && share === null && shareLevel === 'unknown')
|
|
91
|
+
memory = { availablePercent: null, level: 'unknown' };
|
|
92
|
+
else if (m && whole(share) && share <= 100 && (shareLevel === 'ok' || shareLevel === 'warn' || shareLevel === 'crit'))
|
|
93
|
+
memory = { availablePercent: Math.round(share), level: shareLevel };
|
|
94
|
+
if (d && whole(free) && (freeLevel === 'warn' || freeLevel === 'crit'))
|
|
95
|
+
disk = { freeBytes: free, level: freeLevel };
|
|
96
|
+
if (s && whole(used) && used > 0)
|
|
97
|
+
swap = { usedBytes: used };
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
memory = null;
|
|
101
|
+
disk = null;
|
|
102
|
+
swap = null;
|
|
103
|
+
}
|
|
73
104
|
const optional = new Map();
|
|
74
105
|
if (pace !== null)
|
|
75
106
|
optional.set('pace', { text: `${words.limit} ${duration(pace)}`, color: pace < 30 ? 'yellow' : null });
|
|
@@ -108,6 +139,18 @@ function formatStatusFields(input) {
|
|
|
108
139
|
const color = left <= 10 ? 'red' : left <= 30 ? 'yellow' : null;
|
|
109
140
|
add(short > 1 ? `ac ${left}%` : `${left}% ${short ? words.compactShort : words.compact}`, color ? { color } : {});
|
|
110
141
|
}
|
|
142
|
+
// The machine's own state sits with the session's limits and is never one of
|
|
143
|
+
// the optional fields dropped for width: a red disk is the part to keep.
|
|
144
|
+
// Low disk comes first of the three: on a clipped line it is the one to keep.
|
|
145
|
+
if (disk)
|
|
146
|
+
add(short ? `${words.disk} ${gigabytes(disk.freeBytes, true)}` : `${words.disk} ${gigabytes(disk.freeBytes)} ${words.diskFree}`, { color: disk.level === 'crit' ? 'red' : 'yellow' });
|
|
147
|
+
if (memory) {
|
|
148
|
+
const color = memory.level === 'crit' ? 'red' : memory.level === 'warn' ? 'yellow' : null;
|
|
149
|
+
add(memory.availablePercent === null ? (short ? `${words.memoryShort} ?` : words.memoryUnknown)
|
|
150
|
+
: short ? `${short > 1 ? 'm' : words.memoryShort} ${memory.availablePercent}%` : `${memory.availablePercent}% ${words.memory}`, color ? { color } : {});
|
|
151
|
+
}
|
|
152
|
+
if (swap)
|
|
153
|
+
add(`${words.swap} ${gigabytes(swap.usedBytes, short > 0)}`, { color: 'yellow' });
|
|
111
154
|
if (typeof input.share === 'number' && Number.isFinite(input.share))
|
|
112
155
|
add(`${Math.round(input.share)}% ${short ? words.sub : words.share}`);
|
|
113
156
|
if (plan)
|
|
@@ -141,6 +184,9 @@ function formatStatusFields(input) {
|
|
|
141
184
|
...(ctx && left !== null ? [words.contextLine.replace('{used}', Math.round(ctx.tokens).toLocaleString('en-US'))
|
|
142
185
|
.replace('{threshold}', Math.round(ctx.threshold).toLocaleString('en-US')).replace('{left}', String(left))] : []),
|
|
143
186
|
...plans.map(window => `${words.plan} ${Math.round(window.usedPercent)}% (${planName(window)}). ${words.reset} ${Number.isFinite(window.resetsAt) ? new Date(window.resetsAt).toISOString() : words.none}.${age(window) ? ` ${words.lastRead} ${age(window)}.` : ''}`),
|
|
187
|
+
...(memory ? [memory.availablePercent === null ? words.memoryLineUnknown : words.memoryLine.replace('{percent}', String(memory.availablePercent))] : []),
|
|
188
|
+
...(swap ? [words.swapLine.replace('{used}', gigabytes(swap.usedBytes))] : []),
|
|
189
|
+
...(disk ? [words.diskLine.replace('{free}', gigabytes(disk.freeBytes))] : []),
|
|
144
190
|
pace !== null ? `${words.limit} ${duration(pace)}.` : words.paceEmpty,
|
|
145
191
|
input.cost ? `${words.costLead} ≈ ${money(input.cost, words.range)} ${words.costFull}.` : words.costEmpty,
|
|
146
192
|
input.cache && input.cache.tokens > 0 ? `${words.cacheLead} ${input.cache.tokens.toLocaleString('en-US')} ${words.tokens}${input.cache.usd ? ` (≈ ${money(input.cache.usd, words.range)} ${words.costFull})` : ''}.` : words.cacheEmpty,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type VolumeProbe } from '../idle/disk';
|
|
2
|
+
import { type MemoryProbe } from '../idle/memory';
|
|
3
|
+
import type { StatusMachine } from './status-fields';
|
|
4
|
+
/** Swap this large against physical memory means the machine is living on disk. */
|
|
5
|
+
export declare const SWAP_HEAVY_FRACTION = 0.5;
|
|
6
|
+
/** With the disk already low, this much swap is worth showing: swap is what fills it. */
|
|
7
|
+
export declare const SWAP_WITH_LOW_DISK_BYTES: number;
|
|
8
|
+
export interface MachineSources {
|
|
9
|
+
platform?: string;
|
|
10
|
+
memory?: MemoryProbe;
|
|
11
|
+
volume?: VolumeProbe;
|
|
12
|
+
volumePath?: string;
|
|
13
|
+
physicalBytes?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* macOS grows swap files on demand, so "used over total" is near full whenever
|
|
17
|
+
* any swap exists and says nothing. Size against physical memory, or against a
|
|
18
|
+
* disk that is already low, is what tells a person something.
|
|
19
|
+
*/
|
|
20
|
+
export declare function swapIsHeavy(usedBytes: number | null, physicalBytes: number, diskLow: boolean): boolean;
|
|
21
|
+
export declare function readStatusMachine(home: string, now?: number, sources?: MachineSources): Promise<StatusMachine>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SWAP_WITH_LOW_DISK_BYTES = exports.SWAP_HEAVY_FRACTION = void 0;
|
|
4
|
+
exports.swapIsHeavy = swapIsHeavy;
|
|
5
|
+
exports.readStatusMachine = readStatusMachine;
|
|
6
|
+
/**
|
|
7
|
+
* What the status line says about this machine: available memory always (on
|
|
8
|
+
* systems we can read), swap only when it is heavy, free disk only when it is
|
|
9
|
+
* low. Local metadata reads, shared across sessions through small cache files.
|
|
10
|
+
* Reported only: nothing here denies, signals or deletes.
|
|
11
|
+
*/
|
|
12
|
+
const node_os_1 = require("node:os");
|
|
13
|
+
const disk_1 = require("../idle/disk");
|
|
14
|
+
const memory_1 = require("../idle/memory");
|
|
15
|
+
/** Swap this large against physical memory means the machine is living on disk. */
|
|
16
|
+
exports.SWAP_HEAVY_FRACTION = 0.5;
|
|
17
|
+
/** With the disk already low, this much swap is worth showing: swap is what fills it. */
|
|
18
|
+
exports.SWAP_WITH_LOW_DISK_BYTES = 4 * 1024 ** 3;
|
|
19
|
+
/**
|
|
20
|
+
* macOS grows swap files on demand, so "used over total" is near full whenever
|
|
21
|
+
* any swap exists and says nothing. Size against physical memory, or against a
|
|
22
|
+
* disk that is already low, is what tells a person something.
|
|
23
|
+
*/
|
|
24
|
+
function swapIsHeavy(usedBytes, physicalBytes, diskLow) {
|
|
25
|
+
if (usedBytes === null || !Number.isFinite(usedBytes) || usedBytes <= 0)
|
|
26
|
+
return false;
|
|
27
|
+
if (Number.isFinite(physicalBytes) && physicalBytes > 0 && usedBytes >= physicalBytes * exports.SWAP_HEAVY_FRACTION)
|
|
28
|
+
return true;
|
|
29
|
+
return diskLow && usedBytes >= exports.SWAP_WITH_LOW_DISK_BYTES;
|
|
30
|
+
}
|
|
31
|
+
async function readStatusMachine(home, now = Date.now(), sources = {}) {
|
|
32
|
+
const out = {};
|
|
33
|
+
try {
|
|
34
|
+
const platform = sources.platform ?? process.platform;
|
|
35
|
+
let level = 'unknown';
|
|
36
|
+
try {
|
|
37
|
+
const space = (sources.volume ?? disk_1.statfsProbe)(sources.volumePath ?? (0, node_os_1.homedir)());
|
|
38
|
+
level = (0, disk_1.diskLevel)(space);
|
|
39
|
+
if (space && (level === 'warn' || level === 'crit'))
|
|
40
|
+
out.disk = { freeBytes: space.freeBytes, level };
|
|
41
|
+
}
|
|
42
|
+
catch { /* unknown disk shows nothing */ }
|
|
43
|
+
// A system with no memory source shows no memory part at all, rather than a permanent question mark.
|
|
44
|
+
if (platform !== 'darwin' && platform !== 'linux')
|
|
45
|
+
return out;
|
|
46
|
+
const reading = await (0, memory_1.readMemory)(home, now, sources.memory ?? (0, memory_1.systemMemoryProbe)(platform));
|
|
47
|
+
out.memory = { availablePercent: reading.availablePercent, level: reading.level };
|
|
48
|
+
if (swapIsHeavy(reading.swapUsedBytes, sources.physicalBytes ?? (0, node_os_1.totalmem)(), level === 'warn' || level === 'crit'))
|
|
49
|
+
out.swap = { usedBytes: reading.swapUsedBytes };
|
|
50
|
+
}
|
|
51
|
+
catch { /* the line is drawn without the machine parts */ }
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
@@ -10,6 +10,16 @@ export declare const STATUS_TEXT: {
|
|
|
10
10
|
share: string;
|
|
11
11
|
sub: string;
|
|
12
12
|
weekly: string;
|
|
13
|
+
memory: string;
|
|
14
|
+
memoryShort: string;
|
|
15
|
+
memoryUnknown: string;
|
|
16
|
+
disk: string;
|
|
17
|
+
diskFree: string;
|
|
18
|
+
swap: string;
|
|
19
|
+
memoryLine: string;
|
|
20
|
+
memoryLineUnknown: string;
|
|
21
|
+
diskLine: string;
|
|
22
|
+
swapLine: string;
|
|
13
23
|
pastLimit: string;
|
|
14
24
|
pastShort: string;
|
|
15
25
|
waits: string;
|
|
@@ -51,6 +61,16 @@ export declare const STATUS_TEXT: {
|
|
|
51
61
|
share: string;
|
|
52
62
|
sub: string;
|
|
53
63
|
weekly: string;
|
|
64
|
+
memory: string;
|
|
65
|
+
memoryShort: string;
|
|
66
|
+
memoryUnknown: string;
|
|
67
|
+
disk: string;
|
|
68
|
+
diskFree: string;
|
|
69
|
+
swap: string;
|
|
70
|
+
memoryLine: string;
|
|
71
|
+
memoryLineUnknown: string;
|
|
72
|
+
diskLine: string;
|
|
73
|
+
swapLine: string;
|
|
54
74
|
pastLimit: string;
|
|
55
75
|
pastShort: string;
|
|
56
76
|
waits: string;
|
|
@@ -92,6 +112,16 @@ export declare const STATUS_TEXT: {
|
|
|
92
112
|
share: string;
|
|
93
113
|
sub: string;
|
|
94
114
|
weekly: string;
|
|
115
|
+
memory: string;
|
|
116
|
+
memoryShort: string;
|
|
117
|
+
memoryUnknown: string;
|
|
118
|
+
disk: string;
|
|
119
|
+
diskFree: string;
|
|
120
|
+
swap: string;
|
|
121
|
+
memoryLine: string;
|
|
122
|
+
memoryLineUnknown: string;
|
|
123
|
+
diskLine: string;
|
|
124
|
+
swapLine: string;
|
|
95
125
|
pastLimit: string;
|
|
96
126
|
pastShort: string;
|
|
97
127
|
waits: string;
|
|
@@ -4,6 +4,9 @@ exports.STATUS_TEXT = void 0;
|
|
|
4
4
|
// Display-only words shared with the Claude mod. No environment or I/O here.
|
|
5
5
|
exports.STATUS_TEXT = {
|
|
6
6
|
en: { ago: '{minutes}m ago', lastRead: 'Last read', range: 'to', fiveHour: '5-hour', agents: 'sub-agents', tokens: 'tokens', of: 'of', share: 'to sub-agents', sub: 'sub', weekly: 'weekly',
|
|
7
|
+
memory: 'memory free', memoryShort: 'mem', memoryUnknown: 'memory ?', disk: 'disk', diskFree: 'free', swap: 'swap',
|
|
8
|
+
memoryLine: 'Memory: {percent}% of this machine\'s memory is available.', memoryLineUnknown: 'Memory: the available share could not be read.',
|
|
9
|
+
diskLine: 'Disk: {free} free on the volume holding your home folder.', swapLine: 'Swap: {used} in use. Heavy swap means memory is short and the disk is filling.',
|
|
7
10
|
pastLimit: 'past the {limit} limit', pastShort: 'past {limit}', waits: 'sub-agents wait for your yes', compact: 'to auto-compact', compactShort: 'to compact',
|
|
8
11
|
contextLine: 'Context: {used} of {threshold} tokens, {left}% left before Claude Code compacts the conversation.',
|
|
9
12
|
limit: 'limit in', cache: 'cache waste', spend: 'spend', today: 'today', list: 'list', watching: 'watching only',
|
|
@@ -16,6 +19,9 @@ exports.STATUS_TEXT = {
|
|
|
16
19
|
enabled: 'Optional status fields on:', none: 'none', change: 'Change status_fields in the AgentGuard plugin settings, or pass the fields flag to Burn statusline.',
|
|
17
20
|
unknown: 'Ignored unknown status fields:', reset: 'Resets at', plan: 'Plan usage:', hidden: 'Fields hidden to fit this width:' },
|
|
18
21
|
es: { ago: 'hace {minutes}min', lastRead: 'Última lectura', range: 'a', fiveHour: '5 horas', agents: 'subagentes', tokens: 'tokens', of: 'de', share: 'a subagentes', sub: 'sub', weekly: 'semanal',
|
|
22
|
+
memory: 'de memoria libre', memoryShort: 'mem', memoryUnknown: 'memoria ?', disk: 'disco', diskFree: 'libres', swap: 'swap',
|
|
23
|
+
memoryLine: 'Memoria: {percent}% de la memoria de este equipo está disponible.', memoryLineUnknown: 'Memoria: no se pudo leer la parte disponible.',
|
|
24
|
+
diskLine: 'Disco: {free} libres en el volumen de tu carpeta personal.', swapLine: 'Swap: {used} en uso. Mucho swap significa que falta memoria y el disco se llena.',
|
|
19
25
|
pastLimit: 'pasó el límite de {limit}', pastShort: 'pasó {limit}', waits: 'los subagentes esperan tu sí', compact: 'para autocompactar', compactShort: 'hasta compactar',
|
|
20
26
|
contextLine: 'Contexto: {used} de {threshold} tokens, queda {left}% antes de que Claude Code compacte la conversación.',
|
|
21
27
|
limit: 'límite en', cache: 'caché reescrita', spend: 'gasto', today: 'hoy', list: 'lista', watching: 'solo observando',
|
|
@@ -28,6 +34,9 @@ exports.STATUS_TEXT = {
|
|
|
28
34
|
enabled: 'Campos opcionales activos:', none: 'ninguno', change: 'Cambia status_fields en los ajustes del plugin AgentGuard o pasa la opción fields a Burn statusline.',
|
|
29
35
|
unknown: 'Campos de estado desconocidos ignorados:', reset: 'Se reinicia a las', plan: 'Uso del plan:', hidden: 'Campos ocultos para caber en este ancho:' },
|
|
30
36
|
pt: { ago: 'há {minutes}min', lastRead: 'Última leitura', range: 'a', fiveHour: '5 horas', agents: 'subagentes', tokens: 'tokens', of: 'de', share: 'para subagentes', sub: 'sub', weekly: 'semanal',
|
|
37
|
+
memory: 'de memória livre', memoryShort: 'mem', memoryUnknown: 'memória ?', disk: 'disco', diskFree: 'livres', swap: 'swap',
|
|
38
|
+
memoryLine: 'Memória: {percent}% da memória desta máquina está disponível.', memoryLineUnknown: 'Memória: não foi possível ler a parte disponível.',
|
|
39
|
+
diskLine: 'Disco: {free} livres no volume da sua pasta pessoal.', swapLine: 'Swap: {used} em uso. Muito swap significa pouca memória e disco enchendo.',
|
|
31
40
|
pastLimit: 'passou do limite de {limit}', pastShort: 'passou {limit}', waits: 'subagentes esperam seu sim', compact: 'até autocompactar', compactShort: 'até compactar',
|
|
32
41
|
contextLine: 'Contexto: {used} de {threshold} tokens, resta {left}% antes de o Claude Code compactar a conversa.',
|
|
33
42
|
limit: 'limite em', cache: 'cache regravado', spend: 'gasto', today: 'hoje', list: 'lista', watching: 'só observando',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentguard-run/burn",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "Local session usage and runaway-agent circuit breaker. Explain tokens, cache rewrites and API list cost, track pace, warn on heavy turns, and gate agent fan-out with signed receipts. Developer command ranking requires explicit --rank.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"homepage": "https://agentguard.run/burn",
|