@agentguard-run/burn 0.1.1 → 0.2.0

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +110 -1
  3. package/dist/src/adapters/codex.d.ts +48 -0
  4. package/dist/src/adapters/codex.js +194 -0
  5. package/dist/src/adapters/cursor.d.ts +35 -0
  6. package/dist/src/adapters/cursor.js +132 -0
  7. package/dist/src/adapters/raw-api.d.ts +76 -0
  8. package/dist/src/adapters/raw-api.js +130 -0
  9. package/dist/src/cli.d.ts +7 -3
  10. package/dist/src/cli.js +99 -10
  11. package/dist/src/conformance.d.ts +26 -0
  12. package/dist/src/conformance.js +261 -0
  13. package/dist/src/defaults.d.ts +11 -0
  14. package/dist/src/defaults.js +16 -1
  15. package/dist/src/detectors/local-compute.d.ts +19 -0
  16. package/dist/src/detectors/local-compute.js +66 -0
  17. package/dist/src/events.d.ts +94 -0
  18. package/dist/src/events.js +47 -0
  19. package/dist/src/gateway.d.ts +134 -0
  20. package/dist/src/gateway.js +522 -0
  21. package/dist/src/index.d.ts +15 -4
  22. package/dist/src/index.js +41 -1
  23. package/dist/src/proxy/server.d.ts +45 -0
  24. package/dist/src/proxy/server.js +169 -0
  25. package/dist/src/proxy/usage-observer.d.ts +40 -0
  26. package/dist/src/proxy/usage-observer.js +128 -0
  27. package/dist/src/receipt.d.ts +61 -0
  28. package/dist/src/receipt.js +98 -0
  29. package/dist/src/replay/render.d.ts +1 -0
  30. package/dist/src/replay/render.js +2 -1
  31. package/dist/src/state/reservations.d.ts +115 -11
  32. package/dist/src/state/reservations.js +293 -59
  33. package/dist/src/state/session.d.ts +6 -0
  34. package/dist/src/state/session.js +17 -0
  35. package/dist/src/status.d.ts +11 -0
  36. package/dist/src/status.js +48 -0
  37. package/dist/src/types.d.ts +14 -1
  38. package/package.json +33 -6
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * One status for the whole machine.
4
+ *
5
+ * Every host's sessions in one table, with coverage stated per plane, so an
6
+ * OK never masquerades as full visibility. A Cursor session shows
7
+ * `usage:n/a`; a proxy session shows `spawns:n/a`; a session fed by both
8
+ * middleware and the proxy shows full coverage, because it has it.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.renderMachineStatus = renderMachineStatus;
12
+ const evaluate_1 = require("./detectors/evaluate");
13
+ const LIVE_WINDOW_MS = 30 * 60 * 1000;
14
+ function renderMachineStatus(sessions, compute, now = Date.now()) {
15
+ const live = sessions.filter((s) => s.closedAt === null && now - s.state.lastEventAt <= LIVE_WINDOW_MS);
16
+ const totalTokens = live.reduce((n, s) => n + s.state.totalTokens, 0);
17
+ const lines = [];
18
+ lines.push(`cross-tool sessions: ${live.length} live · ${(0, evaluate_1.fmt)(totalTokens)} tokens · ${compute.inFlight} model call(s) in flight · ${Math.round(compute.occupiedMs / 1000)}s occupied in last ${Math.round(compute.windowMs / 60000)} min`);
19
+ if (live.length === 0) {
20
+ lines.push(' (none in the last 30 minutes; Claude Code sessions are tracked by the hook and listed by `replay`)');
21
+ return lines.join('\n');
22
+ }
23
+ lines.push(' ' + pad('HOST(S)', 22) + pad('SESSION', 20) + pad('TOKENS', 9) + pad('SPAWNS', 8) + pad('DEPTH', 7) + pad('LIVE', 6) + 'COVERAGE');
24
+ for (const s of live) {
25
+ lines.push(' ' +
26
+ pad(s.hosts.join('+'), 22) +
27
+ pad(shortId(s.sessionId), 20) +
28
+ pad((0, evaluate_1.fmt)(s.state.totalTokens), 9) +
29
+ pad(String(s.state.spawnCount), 8) +
30
+ pad(String(s.state.maxDepth), 7) +
31
+ pad(String(s.liveSpawns), 6) +
32
+ coverageLine(s));
33
+ }
34
+ return lines.join('\n');
35
+ }
36
+ function coverageLine(s) {
37
+ const usage = s.usage.missing > 0 ? `usage:partial(${s.usage.missing} missing)` : s.usage.authoritative > 0 ? 'usage:auth' : s.usage.estimated > 0 ? 'usage:est' : `usage:${short(s.capabilities.usage)}`;
38
+ return `spawns:${short(s.capabilities.spawns)} depth:${short(s.capabilities.depth)} ${usage}`;
39
+ }
40
+ function short(c) {
41
+ return c === 'authoritative' ? 'auth' : c === 'estimated' ? 'est' : 'n/a';
42
+ }
43
+ function pad(v, w) {
44
+ return v.length >= w ? `${v.slice(0, w - 1)} ` : v.padEnd(w, ' ');
45
+ }
46
+ function shortId(v) {
47
+ return v.length <= 18 ? v : `${v.slice(0, 8)}…${v.slice(-8)}`;
48
+ }
@@ -8,7 +8,7 @@
8
8
  * competitors, so the policy layer has to sit above all of them.
9
9
  */
10
10
  export type Verdict = 'OK' | 'WARN' | 'STOP';
11
- export type Detector = 'fanout' | 'sustained_burn' | 'burn_debt' | 'spawn_rate' | 'account' | 'duplicate_work';
11
+ export type Detector = 'fanout' | 'sustained_burn' | 'burn_debt' | 'spawn_rate' | 'account' | 'duplicate_work' | 'local_compute';
12
12
  /** One normalised observation from a host transcript. */
13
13
  export interface BurnEvent {
14
14
  /** Unix milliseconds. */
@@ -114,6 +114,19 @@ export interface Thresholds {
114
114
  windowActiveMinutes: number;
115
115
  warnConcurrentSessions: number;
116
116
  };
117
+ /**
118
+ * Local inference plane (Ollama, vLLM, LM Studio). Token dollars are close
119
+ * to meaningless when the GPU is yours; what runs away is concurrency and
120
+ * occupied time. WARN-only by default: no universal STOP is honest for
121
+ * hardware we cannot see. Optional so pre-0.2 policy files stay valid.
122
+ */
123
+ localCompute?: {
124
+ windowMs: number;
125
+ warnConcurrent: number;
126
+ stopConcurrent: number | null;
127
+ warnOccupiedMs: number | null;
128
+ stopOccupiedMs: number | null;
129
+ };
117
130
  }
118
131
  export type Mode = 'shadow' | 'enforce';
119
132
  export interface Policy {
package/package.json CHANGED
@@ -1,17 +1,41 @@
1
1
  {
2
2
  "name": "@agentguard-run/burn",
3
- "version": "0.1.1",
4
- "description": "Local runaway-agent circuit breaker for AI coding agents. Detects fan-out storms and sustained token burn, blocks the next spawn, and proves what happened. Nothing leaves the machine.",
3
+ "version": "0.2.0",
4
+ "description": "Local runaway-agent circuit breaker for AI coding agents and local model runtimes. One policy across Claude Code, Cursor, Codex, Ollama, vLLM, LM Studio and raw orchestrators: detects fan-out storms and sustained token burn, blocks the next spawn, and proves what happened with content-free signed receipts. Nothing leaves the machine.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "commonjs",
7
7
  "main": "dist/src/index.js",
8
8
  "types": "dist/src/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/src/index.d.ts",
12
+ "default": "./dist/src/index.js"
13
+ },
14
+ "./middleware": {
15
+ "types": "./dist/src/adapters/raw-api.d.ts",
16
+ "default": "./dist/src/adapters/raw-api.js"
17
+ },
18
+ "./proxy": {
19
+ "types": "./dist/src/proxy/server.d.ts",
20
+ "default": "./dist/src/proxy/server.js"
21
+ },
22
+ "./cursor": {
23
+ "types": "./dist/src/adapters/cursor.d.ts",
24
+ "default": "./dist/src/adapters/cursor.js"
25
+ },
26
+ "./codex": {
27
+ "types": "./dist/src/adapters/codex.d.ts",
28
+ "default": "./dist/src/adapters/codex.js"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
9
32
  "bin": {
10
33
  "agentguard-burn": "dist/src/cli.js"
11
34
  },
12
35
  "files": [
13
36
  "dist/src",
14
37
  "README.md",
38
+ "CHANGELOG.md",
15
39
  "LICENSE"
16
40
  ],
17
41
  "engines": {
@@ -21,11 +45,10 @@
21
45
  "build": "tsc -p tsconfig.json",
22
46
  "test": "tsc -p tsconfig.json && node --test \"dist/tests/**/*.test.js\"",
23
47
  "typecheck": "tsc -p tsconfig.json --noEmit",
24
- "replay": "node dist/cli.js replay"
25
- },
26
- "dependencies": {
27
- "@noble/ed25519": "^3.0.0"
48
+ "conformance": "tsc -p tsconfig.json && node dist/src/cli.js conformance",
49
+ "replay": "node dist/src/cli.js replay"
28
50
  },
51
+ "dependencies": {},
29
52
  "devDependencies": {
30
53
  "@types/node": "^22",
31
54
  "typescript": "^5.0.0"
@@ -33,6 +56,10 @@
33
56
  "keywords": [
34
57
  "agentguard",
35
58
  "claude-code",
59
+ "cursor",
60
+ "codex",
61
+ "ollama",
62
+ "vllm",
36
63
  "agents",
37
64
  "token-budget",
38
65
  "circuit-breaker",