claude-code-remote-pilot 0.2.10 → 0.2.11
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/bin/claude-pilot.js +15 -4
- package/lib/Watcher.js +32 -6
- package/package.json +1 -1
package/bin/claude-pilot.js
CHANGED
|
@@ -118,14 +118,25 @@ function uptime(startedAt) {
|
|
|
118
118
|
return `${Math.floor(s / 3600)}h ${Math.floor((s % 3600) / 60)}m`;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
function formatUsage(session) {
|
|
122
|
+
if (session.status === 'limit' && session.resetTime) {
|
|
123
|
+
return `resets ${session.resetTime}`;
|
|
124
|
+
}
|
|
125
|
+
if (session.tokens) {
|
|
126
|
+
return `↑${session.tokens.sent} ↓${session.tokens.received}`;
|
|
127
|
+
}
|
|
128
|
+
return '';
|
|
129
|
+
}
|
|
130
|
+
|
|
121
131
|
function renderTable(sessions) {
|
|
122
|
-
const NW = 18, SW = 14, UW =
|
|
123
|
-
const bar = ' ' + '─'.repeat(NW + SW + UW +
|
|
124
|
-
const header = ` ${'SESSION'.padEnd(NW)} ${'STATUS'.padEnd(SW)} ${'UP'.padEnd(UW)}
|
|
132
|
+
const NW = 18, SW = 14, UW = 7, TW = 16;
|
|
133
|
+
const bar = ' ' + '─'.repeat(NW + SW + UW + TW + 10);
|
|
134
|
+
const header = ` ${'SESSION'.padEnd(NW)} ${'STATUS'.padEnd(SW)} ${'UP'.padEnd(UW)} ${'USAGE / RESET'.padEnd(TW)}`;
|
|
125
135
|
const rows = sessions.map(s => {
|
|
126
136
|
const { plain, colored } = formatStatus(s);
|
|
127
137
|
const pad = ' '.repeat(Math.max(0, SW - plain.length));
|
|
128
|
-
|
|
138
|
+
const usage = formatUsage(s);
|
|
139
|
+
return ` ${trunc(s.name, NW)} ${colored}${pad} ${uptime(s.startedAt).padEnd(UW)} ${trunc(usage, TW)}`;
|
|
129
140
|
});
|
|
130
141
|
const footer = ` ${sessions.length} session${sessions.length !== 1 ? 's' : ''} ${new Date().toLocaleTimeString()} q to exit`;
|
|
131
142
|
return ['\n', ' Claude Code Remote Pilot', bar, header, bar, ...rows, bar, footer, ''].join('\n');
|
package/lib/Watcher.js
CHANGED
|
@@ -4,12 +4,13 @@ const crypto = require('crypto');
|
|
|
4
4
|
const notifier = require('./notifier');
|
|
5
5
|
|
|
6
6
|
const LIMIT_RE = /hit your limit|usage limit|rate limit|limit reached|try again|resets/i;
|
|
7
|
-
// Checked against full capture — these messages persist on screen
|
|
8
7
|
const RESPONSE_RE = /do you want to proceed|esc to cancel|ctrl\+e to explain|❯\s*\d+\.\s*yes/i;
|
|
9
|
-
// Checked against last 5 lines only — footer disappears when Claude finishes
|
|
10
8
|
const RUNNING_RE = /esc to interrupt/i;
|
|
11
|
-
// Checked against the single last non-empty line
|
|
12
9
|
const IDLE_RE = /^\s*>\s*$/;
|
|
10
|
+
// Claude Code footer: "tokens: ↑1,234 ↓567" or "↑1.2k ↓890"
|
|
11
|
+
const TOKEN_RE = /↑\s*([\d.,]+[km]?)\s*↓\s*([\d.,]+[km]?)/i;
|
|
12
|
+
// Limit reset time: "resets at 2:00 AM" or "resets at 14:30"
|
|
13
|
+
const RESET_AT_RE = /resets?\s+(?:at\s+)?(\d{1,2}:\d{2}\s*(?:am|pm)?)/i;
|
|
13
14
|
|
|
14
15
|
class Watcher {
|
|
15
16
|
constructor(session, opts = {}) {
|
|
@@ -66,6 +67,21 @@ class Watcher {
|
|
|
66
67
|
return this.fallbackWait;
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
_parseResetTime(text) {
|
|
71
|
+
// "resets at 2:00 AM"
|
|
72
|
+
const atMatch = text.match(RESET_AT_RE);
|
|
73
|
+
if (atMatch) return atMatch[1].trim().toUpperCase();
|
|
74
|
+
// "try again in X minutes" — calculate clock time
|
|
75
|
+
const inMatch = text.match(/(?:try again|retry|wait).*?in\s+(\d+)\s*(second|minute|hour)/i);
|
|
76
|
+
if (inMatch) {
|
|
77
|
+
const v = parseInt(inMatch[1]);
|
|
78
|
+
const mult = inMatch[2].startsWith('second') ? 1 : inMatch[2].startsWith('minute') ? 60 : 3600;
|
|
79
|
+
const resetMs = Date.now() + v * mult * 1000;
|
|
80
|
+
return new Date(resetMs).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
69
85
|
async _check() {
|
|
70
86
|
if (this._busy) return;
|
|
71
87
|
this._busy = true;
|
|
@@ -85,7 +101,13 @@ class Watcher {
|
|
|
85
101
|
const lastLine = nonEmptyLines[nonEmptyLines.length - 1] || '';
|
|
86
102
|
const recentLines = nonEmptyLines.slice(-5).join('\n');
|
|
87
103
|
|
|
88
|
-
//
|
|
104
|
+
// Extract token usage from footer whenever Claude is running
|
|
105
|
+
const tokenMatch = recentLines.match(TOKEN_RE);
|
|
106
|
+
if (tokenMatch) {
|
|
107
|
+
this.session.tokens = { sent: tokenMatch[1], received: tokenMatch[2] };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Track output stability
|
|
89
111
|
const outputHash = this._hash(recentLines);
|
|
90
112
|
if (outputHash === this._prevOutputHash) {
|
|
91
113
|
this._outputUnchangedCount++;
|
|
@@ -128,13 +150,16 @@ class Watcher {
|
|
|
128
150
|
if ((Date.now() / 1000) - this.lastResumeAt < this.cooldown) return;
|
|
129
151
|
|
|
130
152
|
this.lastHash = hash;
|
|
131
|
-
this._outputUnchangedCount = 0;
|
|
153
|
+
this._outputUnchangedCount = 0;
|
|
132
154
|
const wait = this._parseWait(text);
|
|
155
|
+
const resetTime = this._parseResetTime(text);
|
|
156
|
+
|
|
133
157
|
this.session.status = 'limit';
|
|
134
158
|
this.session.resumeAt = Date.now() + wait * 1000;
|
|
159
|
+
this.session.resetTime = resetTime;
|
|
135
160
|
|
|
136
161
|
notifier.send(this.telegram.token, this.telegram.chatId,
|
|
137
|
-
`Pilot: limit in "${this.session.name}".
|
|
162
|
+
`Pilot: limit in "${this.session.name}". Resets ${resetTime || `in ${Math.ceil(wait / 60)}m`}.`);
|
|
138
163
|
|
|
139
164
|
await new Promise(r => setTimeout(r, wait * 1000));
|
|
140
165
|
|
|
@@ -144,6 +169,7 @@ class Watcher {
|
|
|
144
169
|
this.lastResumeAt = Date.now() / 1000;
|
|
145
170
|
this.session.status = 'running';
|
|
146
171
|
this.session.resumeAt = null;
|
|
172
|
+
this.session.resetTime = null;
|
|
147
173
|
|
|
148
174
|
notifier.send(this.telegram.token, this.telegram.chatId,
|
|
149
175
|
`Pilot: resumed "${this.session.name}".`);
|
package/package.json
CHANGED