agent-fuel 0.2.0 → 0.4.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.
package/dist/tmux.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export declare class TuiScraper {
2
+ private readonly command;
3
+ private readonly width;
4
+ private readonly height;
5
+ readonly sessionId: string;
6
+ constructor(command: string, width?: number, height?: number);
7
+ start(): void;
8
+ capture(historyLines?: number): string;
9
+ send(text: string): void;
10
+ sendKey(key: string): void;
11
+ waitFor(pattern: RegExp, timeoutMs: number, historyLines?: number): Promise<string>;
12
+ kill(): void;
13
+ }
package/dist/tmux.js ADDED
@@ -0,0 +1,72 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { debug } from './debug.js';
3
+ export class TuiScraper {
4
+ command;
5
+ width;
6
+ height;
7
+ sessionId;
8
+ constructor(command, width = 220, height = 50) {
9
+ this.command = command;
10
+ this.width = width;
11
+ this.height = height;
12
+ this.sessionId = `af-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
13
+ }
14
+ start() {
15
+ try {
16
+ execFileSync('which', ['tmux'], { stdio: 'ignore' });
17
+ }
18
+ catch {
19
+ throw new Error('tmux not found — install with: brew install tmux');
20
+ }
21
+ debug('tmux', `starting session ${this.sessionId} for command: ${this.command}`);
22
+ execFileSync('tmux', [
23
+ 'new-session', '-d', '-s', this.sessionId,
24
+ '-x', String(this.width), '-y', String(this.height),
25
+ this.command,
26
+ ]);
27
+ }
28
+ // historyLines > 0 → include that many lines of scrollback above the visible screen.
29
+ // This catches transient overlays that rendered and then re-rendered away.
30
+ capture(historyLines = 0) {
31
+ const args = historyLines > 0
32
+ ? ['capture-pane', '-t', this.sessionId, '-S', `-${historyLines}`, '-p']
33
+ : ['capture-pane', '-t', this.sessionId, '-p'];
34
+ const text = execFileSync('tmux', args).toString();
35
+ debug('tmux:capture', `[${this.sessionId}] captured ${text.length} chars (history=${historyLines})`);
36
+ return text;
37
+ }
38
+ send(text) {
39
+ debug('tmux:send', `[${this.sessionId}] sending: ${JSON.stringify(text)}`);
40
+ execFileSync('tmux', ['send-keys', '-t', this.sessionId, text, 'Enter']);
41
+ }
42
+ // Send a named key (Tab, Escape, Up, Down, etc.) without appending Enter.
43
+ sendKey(key) {
44
+ debug('tmux:send', `[${this.sessionId}] sendKey: ${key}`);
45
+ execFileSync('tmux', ['send-keys', '-t', this.sessionId, key]);
46
+ }
47
+ async waitFor(pattern, timeoutMs, historyLines = 500) {
48
+ const deadline = Date.now() + timeoutMs;
49
+ debug('tmux:waitFor', `[${this.sessionId}] waiting for ${pattern} (timeout ${timeoutMs}ms, history=${historyLines})`);
50
+ while (Date.now() < deadline) {
51
+ const text = this.capture(historyLines);
52
+ if (pattern.test(text)) {
53
+ debug('tmux:waitFor', `[${this.sessionId}] matched ${pattern}`);
54
+ return text;
55
+ }
56
+ await sleep(100);
57
+ }
58
+ const last = this.capture(historyLines);
59
+ debug('tmux:waitFor', `[${this.sessionId}] TIMEOUT for ${pattern}, last screen:\n${last}`);
60
+ throw new Error(`TuiScraper.waitFor timeout after ${timeoutMs}ms: ${pattern}`);
61
+ }
62
+ kill() {
63
+ debug('tmux', `killing session ${this.sessionId}`);
64
+ try {
65
+ execFileSync('tmux', ['kill-session', '-t', this.sessionId], { stdio: 'ignore' });
66
+ }
67
+ catch { /* already dead */ }
68
+ }
69
+ }
70
+ function sleep(ms) {
71
+ return new Promise(res => setTimeout(res, ms));
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-fuel",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Sleek term-based dashboard for AI coding CLI quotas",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,4 +31,4 @@
31
31
  "@types/node": "^20.11.24",
32
32
  "typescript": "^5.3.3"
33
33
  }
34
- }
34
+ }