@zeph-to/cli 1.19.3 → 1.20.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/listener.d.ts +13 -0
- package/dist/listener.d.ts.map +1 -1
- package/dist/listener.js +60 -9
- package/package.json +1 -1
package/dist/listener.d.ts
CHANGED
|
@@ -157,6 +157,16 @@ export interface ScreenSnapshot {
|
|
|
157
157
|
* token bucket as command injection.
|
|
158
158
|
*/
|
|
159
159
|
export declare const handleScreenRequest: (req: ScreenRequest) => ScreenSnapshot | null;
|
|
160
|
+
/**
|
|
161
|
+
* After the phone injects keys, push fresh frames instead of waiting for its
|
|
162
|
+
* next screen request — the phone's post-tap re-pull raced the key landing
|
|
163
|
+
* (its timer starts at tap time, the key lands a REST+WS hop later), so it
|
|
164
|
+
* often re-captured the pre-keypress screen and the next update was a full
|
|
165
|
+
* auto-refresh period away. Unsolicited frames carry no requestId; the phone
|
|
166
|
+
* matches them by deviceId + sessionName. A newer tap cancels pending
|
|
167
|
+
* captures so a burst of arrow presses yields frames after the LAST press.
|
|
168
|
+
*/
|
|
169
|
+
export declare const scheduleInjectSnapshots: (sessionName: string, send: (data: Record<string, unknown>) => void, delays?: number[]) => void;
|
|
160
170
|
export interface CollectResult {
|
|
161
171
|
sessions: AgentSession[];
|
|
162
172
|
/** Diagnostic notes per rejected session — surfaced under `--verbose`. */
|
|
@@ -221,6 +231,9 @@ interface HandlePushDeps {
|
|
|
221
231
|
downloadAttachments?: (pushId: string, files: PushFileAttachment[]) => Promise<string[]>;
|
|
222
232
|
/** Pane cwd lookup for the remote-origin marker (ADR-0002). */
|
|
223
233
|
paneCwd?: (session: string) => string | null;
|
|
234
|
+
/** Fired after a successful named-key injection so the WS loop can push
|
|
235
|
+
* fresh screen frames to the phone (scheduleInjectSnapshots). */
|
|
236
|
+
onKeysInjected?: (session: string) => void;
|
|
224
237
|
}
|
|
225
238
|
/**
|
|
226
239
|
* Record a successful phone→pane text injection so a prompt-submit hook
|
package/dist/listener.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../src/listener.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAUH,OAAO,EAA2B,KAAK,SAAS,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACzG,OAAO,EAAiD,KAAK,UAAU,EAA4C,MAAM,kBAAkB,CAAC;AAoC5I,eAAO,MAAM,2BAA2B,QAAS,CAAC;AAElD,UAAU,YAAY;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAU,YAAY,EAAE,KAAG,MAS7C,CAAC;AAEnB;6BAC6B;AAC7B,eAAO,MAAM,iBAAiB,GAC1B,aAAa,MAAM,EACnB,qBAAqB,MAAM,GAAG,IAAI,EAClC,cAAc,MAAM,EACpB,OAAO,MAAM,KACd,OAEoD,CAAC;AAYxD,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAA+B,CAAC;AAenF,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,MAAK,MAAmB,KAAG,OAgB1E,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,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U,GACnB,MAAM,QAAQ,EACd,OAAM,cAAmB,KAC1B,OAAO,CAAC,OAAO,CAoCjB,CAAC;AAcF,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,MAIhD,CAAC;AA0BF,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MAUvD,CAAC;AAqRF,eAAO,MAAM,cAAc,GAAU,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,KAAG,OAAO,CAAC,MAAM,CA+H3F,CAAC"}
|
package/dist/listener.js
CHANGED
|
@@ -25,7 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.handleListener = exports.computeListenerDeviceId = exports.computeBackoff = exports.handlePush = exports.gcAttachments = exports.setAttachmentContext = exports.writeRemoteMarker = exports.collectSessions = exports.collectSessionsVerbose = exports.handleScreenRequest = exports.collectWatchHits = exports.resetPatternWatches = exports.setPatternWatches = exports.deriveSessionState = exports.resetSessionStates = exports.detectRemoteAgent = exports.parseSessionName = exports.invalidateTmuxSocketCache = exports.resolveKeys = exports.paneCurrentCommand = exports.checkRateLimit = exports.AUTH_FAILURE_CODES = exports.sessionsReportDue = exports.sessionsFingerprint = exports.SESSION_REPORT_HEARTBEAT_MS = void 0;
|
|
28
|
+
exports.handleListener = exports.computeListenerDeviceId = exports.computeBackoff = exports.handlePush = exports.gcAttachments = exports.setAttachmentContext = exports.writeRemoteMarker = exports.collectSessions = exports.collectSessionsVerbose = exports.scheduleInjectSnapshots = exports.handleScreenRequest = exports.collectWatchHits = exports.resetPatternWatches = exports.setPatternWatches = exports.deriveSessionState = exports.resetSessionStates = exports.detectRemoteAgent = exports.parseSessionName = exports.invalidateTmuxSocketCache = exports.resolveKeys = exports.paneCurrentCommand = exports.checkRateLimit = exports.AUTH_FAILURE_CODES = exports.sessionsReportDue = exports.sessionsFingerprint = exports.SESSION_REPORT_HEARTBEAT_MS = void 0;
|
|
29
29
|
const child_process_1 = require("child_process");
|
|
30
30
|
const crypto_1 = require("crypto");
|
|
31
31
|
const fs_1 = require("fs");
|
|
@@ -683,13 +683,22 @@ const handleScreenRequest = (req) => {
|
|
|
683
683
|
if (!(0, exports.collectSessions)().some((s) => s.name === req.sessionName)) {
|
|
684
684
|
return { ...base, error: 'unknown_session' };
|
|
685
685
|
}
|
|
686
|
-
const
|
|
686
|
+
const captured = capturePane(req.sessionName);
|
|
687
|
+
if (!captured) {
|
|
688
|
+
return { ...base, error: 'capture_failed' };
|
|
689
|
+
}
|
|
690
|
+
return { ...base, ...captured };
|
|
691
|
+
};
|
|
692
|
+
exports.handleScreenRequest = handleScreenRequest;
|
|
693
|
+
/** Raw pane capture + size cap. Shared by the request path and the
|
|
694
|
+
* post-injection auto-snapshot. */
|
|
695
|
+
const capturePane = (sessionName) => {
|
|
696
|
+
const r = (0, child_process_1.spawnSync)('tmux', tmuxArgs(['capture-pane', '-p', '-t', sessionName, '-S', `-${SCREEN_PEEK_LINES}`]), {
|
|
687
697
|
encoding: 'utf-8',
|
|
688
698
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
689
699
|
});
|
|
690
|
-
if (r.status !== 0)
|
|
691
|
-
return
|
|
692
|
-
}
|
|
700
|
+
if (r.status !== 0)
|
|
701
|
+
return null;
|
|
693
702
|
let content = r.stdout ?? '';
|
|
694
703
|
let truncated = false;
|
|
695
704
|
while (Buffer.byteLength(content, 'utf-8') > SCREEN_PEEK_MAX_BYTES) {
|
|
@@ -698,9 +707,42 @@ const handleScreenRequest = (req) => {
|
|
|
698
707
|
content = cut > 0 ? content.slice(cut + 1) : content.slice(-SCREEN_PEEK_MAX_BYTES);
|
|
699
708
|
truncated = true;
|
|
700
709
|
}
|
|
701
|
-
return {
|
|
710
|
+
return { content, truncated };
|
|
702
711
|
};
|
|
703
|
-
|
|
712
|
+
/** Delays after a key injection at which the pane is re-captured and pushed
|
|
713
|
+
* to the phone unsolicited. The first frame lands right after most TUI
|
|
714
|
+
* redraws; the second catches slow animations and is skipped when nothing
|
|
715
|
+
* changed since the first. */
|
|
716
|
+
const INJECT_SNAPSHOT_DELAYS_MS = [250, 900];
|
|
717
|
+
const pendingInjectSnapshots = new Map();
|
|
718
|
+
/**
|
|
719
|
+
* After the phone injects keys, push fresh frames instead of waiting for its
|
|
720
|
+
* next screen request — the phone's post-tap re-pull raced the key landing
|
|
721
|
+
* (its timer starts at tap time, the key lands a REST+WS hop later), so it
|
|
722
|
+
* often re-captured the pre-keypress screen and the next update was a full
|
|
723
|
+
* auto-refresh period away. Unsolicited frames carry no requestId; the phone
|
|
724
|
+
* matches them by deviceId + sessionName. A newer tap cancels pending
|
|
725
|
+
* captures so a burst of arrow presses yields frames after the LAST press.
|
|
726
|
+
*/
|
|
727
|
+
const scheduleInjectSnapshots = (sessionName, send, delays = INJECT_SNAPSHOT_DELAYS_MS) => {
|
|
728
|
+
for (const t of pendingInjectSnapshots.get(sessionName) ?? [])
|
|
729
|
+
clearTimeout(t);
|
|
730
|
+
let lastContent = null;
|
|
731
|
+
const timers = delays.map((delay) => setTimeout(() => {
|
|
732
|
+
const captured = capturePane(sessionName);
|
|
733
|
+
if (!captured || captured.content === lastContent)
|
|
734
|
+
return;
|
|
735
|
+
lastContent = captured.content;
|
|
736
|
+
send({
|
|
737
|
+
subtype: 'agent.screen.snapshot',
|
|
738
|
+
sessionName,
|
|
739
|
+
capturedAt: new Date().toISOString(),
|
|
740
|
+
...captured,
|
|
741
|
+
});
|
|
742
|
+
}, delay));
|
|
743
|
+
pendingInjectSnapshots.set(sessionName, timers);
|
|
744
|
+
};
|
|
745
|
+
exports.scheduleInjectSnapshots = scheduleInjectSnapshots;
|
|
704
746
|
/**
|
|
705
747
|
* Inventory pass that also records *why* each `zeph-*` session was
|
|
706
748
|
* skipped. The verbose log uses the rejection notes to explain empty
|
|
@@ -997,7 +1039,10 @@ const handlePush = async (push, deps = {}) => {
|
|
|
997
1039
|
log(`! ${push.agentSessionName}: unknown key(s) [${push.keys.join(' ')}] — drop`);
|
|
998
1040
|
return false;
|
|
999
1041
|
}
|
|
1000
|
-
|
|
1042
|
+
const injected = tryInjectKeys(push.agentSessionName, tokens, deps);
|
|
1043
|
+
if (injected)
|
|
1044
|
+
deps.onKeysInjected?.(push.agentSessionName);
|
|
1045
|
+
return injected;
|
|
1001
1046
|
}
|
|
1002
1047
|
// Download any attachments BEFORE injecting so the agent can read the
|
|
1003
1048
|
// local paths immediately. A download-phase failure is isolated: the
|
|
@@ -1247,7 +1292,13 @@ const streamSession = (wsUrl, apiKey) => {
|
|
|
1247
1292
|
// Fire-and-forget: handlePush is async (attachment download)
|
|
1248
1293
|
// but the WS read loop must stay responsive. Errors are
|
|
1249
1294
|
// logged, never thrown into the socket handler.
|
|
1250
|
-
void (0, exports.handlePush)(m.data
|
|
1295
|
+
void (0, exports.handlePush)(m.data, {
|
|
1296
|
+
onKeysInjected: (session) => (0, exports.scheduleInjectSnapshots)(session, (data) => {
|
|
1297
|
+
if (sock.readyState === ws_1.default.OPEN) {
|
|
1298
|
+
sock.send(JSON.stringify({ type: 'ephemeral', data }));
|
|
1299
|
+
}
|
|
1300
|
+
}),
|
|
1301
|
+
}).catch((err) => log(`! handlePush: ${err.message}`));
|
|
1251
1302
|
}
|
|
1252
1303
|
if (m.type === 'ephemeral' && m.data) {
|
|
1253
1304
|
// Screen peek (§S4): the phone asks for this machine's live
|