@dmsdc-ai/aigentry-telepty 0.1.18 → 0.1.19
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/cli.js +36 -1
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -694,6 +694,28 @@ async function main() {
|
|
|
694
694
|
env: { ...process.env, TELEPTY_SESSION_ID: sessionId }
|
|
695
695
|
});
|
|
696
696
|
|
|
697
|
+
// Prompt-ready detection for safe inject delivery
|
|
698
|
+
const PROMPT_PATTERNS = {
|
|
699
|
+
claude: /[❯>]\s*$/,
|
|
700
|
+
gemini: /[❯>]\s*$/,
|
|
701
|
+
codex: /[❯>]\s*$/,
|
|
702
|
+
};
|
|
703
|
+
const cmdBase = path.basename(command).replace(/\..*$/, '');
|
|
704
|
+
const promptPattern = PROMPT_PATTERNS[cmdBase] || /[❯>$#%]\s*$/;
|
|
705
|
+
let promptReady = true; // assume ready initially for first inject
|
|
706
|
+
const injectQueue = [];
|
|
707
|
+
|
|
708
|
+
function flushInjectQueue() {
|
|
709
|
+
if (injectQueue.length === 0) return;
|
|
710
|
+
const batch = injectQueue.splice(0);
|
|
711
|
+
let delay = 0;
|
|
712
|
+
for (const item of batch) {
|
|
713
|
+
setTimeout(() => child.write(item), delay);
|
|
714
|
+
delay += item === '\r' ? 0 : 100;
|
|
715
|
+
}
|
|
716
|
+
promptReady = false;
|
|
717
|
+
}
|
|
718
|
+
|
|
697
719
|
// Connect to daemon WebSocket for inject reception and output relay
|
|
698
720
|
const wsUrl = `ws://${REMOTE_HOST}:${PORT}/api/sessions/${encodeURIComponent(sessionId)}?token=${encodeURIComponent(TOKEN)}`;
|
|
699
721
|
const daemonWs = new WebSocket(wsUrl);
|
|
@@ -708,7 +730,15 @@ async function main() {
|
|
|
708
730
|
try {
|
|
709
731
|
const msg = JSON.parse(message);
|
|
710
732
|
if (msg.type === 'inject') {
|
|
711
|
-
|
|
733
|
+
if (promptReady) {
|
|
734
|
+
child.write(msg.data);
|
|
735
|
+
// After writing prompt text (not \r), mark as not ready until next prompt
|
|
736
|
+
if (msg.data !== '\r' && msg.data.length > 1) {
|
|
737
|
+
promptReady = false;
|
|
738
|
+
}
|
|
739
|
+
} else {
|
|
740
|
+
injectQueue.push(msg.data);
|
|
741
|
+
}
|
|
712
742
|
} else if (msg.type === 'resize') {
|
|
713
743
|
child.resize(msg.cols, msg.rows);
|
|
714
744
|
}
|
|
@@ -746,6 +776,11 @@ async function main() {
|
|
|
746
776
|
if (wsReady && daemonWs.readyState === 1) {
|
|
747
777
|
daemonWs.send(JSON.stringify({ type: 'output', data }));
|
|
748
778
|
}
|
|
779
|
+
// Detect prompt in output to enable inject delivery
|
|
780
|
+
if (promptPattern.test(data)) {
|
|
781
|
+
promptReady = true;
|
|
782
|
+
flushInjectQueue();
|
|
783
|
+
}
|
|
749
784
|
});
|
|
750
785
|
|
|
751
786
|
// Handle child exit
|