@dmsdc-ai/aigentry-telepty 0.1.23 → 0.1.25
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 +22 -14
- package/daemon.js +15 -3
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -725,23 +725,26 @@ async function main() {
|
|
|
725
725
|
let lastInjectTextTime = 0;
|
|
726
726
|
const MAX_RECONNECT_DELAY = 30000;
|
|
727
727
|
|
|
728
|
-
function connectDaemonWs() {
|
|
728
|
+
async function connectDaemonWs() {
|
|
729
|
+
// Re-register session BEFORE WebSocket connect (daemon rejects WS if session unknown)
|
|
730
|
+
if (reconnectAttempts > 0) {
|
|
731
|
+
try {
|
|
732
|
+
await fetchWithAuth(`${DAEMON_URL}/api/sessions/register`, {
|
|
733
|
+
method: 'POST',
|
|
734
|
+
headers: { 'Content-Type': 'application/json' },
|
|
735
|
+
body: JSON.stringify({ session_id: sessionId, command, cwd: process.cwd() })
|
|
736
|
+
});
|
|
737
|
+
} catch (e) {
|
|
738
|
+
// Registration may fail if session already exists or daemon not ready
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
729
742
|
daemonWs = new WebSocket(wsUrl);
|
|
730
743
|
|
|
731
|
-
daemonWs.on('open',
|
|
744
|
+
daemonWs.on('open', () => {
|
|
732
745
|
wsReady = true;
|
|
733
746
|
if (reconnectAttempts > 0) {
|
|
734
747
|
console.error(`\n\x1b[32m⚡ Reconnected to daemon. Inject restored.\x1b[0m`);
|
|
735
|
-
// Re-register session on reconnect
|
|
736
|
-
try {
|
|
737
|
-
await fetchWithAuth(`${DAEMON_URL}/api/sessions/register`, {
|
|
738
|
-
method: 'POST',
|
|
739
|
-
headers: { 'Content-Type': 'application/json' },
|
|
740
|
-
body: JSON.stringify({ session_id: sessionId, command, cwd: process.cwd() })
|
|
741
|
-
});
|
|
742
|
-
} catch (e) {
|
|
743
|
-
// Registration may fail if session already exists, that's fine
|
|
744
|
-
}
|
|
745
748
|
}
|
|
746
749
|
reconnectAttempts = 0;
|
|
747
750
|
});
|
|
@@ -978,6 +981,11 @@ async function main() {
|
|
|
978
981
|
args.splice(replyToIndex, 2);
|
|
979
982
|
}
|
|
980
983
|
|
|
984
|
+
// Extract --reply-expected flag
|
|
985
|
+
const replyExpectedIndex = args.indexOf('--reply-expected');
|
|
986
|
+
const replyExpected = replyExpectedIndex !== -1;
|
|
987
|
+
if (replyExpected) args.splice(replyExpectedIndex, 1);
|
|
988
|
+
|
|
981
989
|
const sessionId = args[1]; const prompt = args.slice(2).join(' ');
|
|
982
990
|
if (!sessionId || !prompt) { console.error('❌ Usage: telepty inject [--no-enter] [--from <id>] [--reply-to <id>] <session_id> "<prompt text>"'); process.exit(1); }
|
|
983
991
|
try {
|
|
@@ -990,6 +998,7 @@ async function main() {
|
|
|
990
998
|
const body = { prompt, no_enter: noEnter };
|
|
991
999
|
if (fromId) body.from = fromId;
|
|
992
1000
|
if (replyTo) body.reply_to = replyTo;
|
|
1001
|
+
if (replyExpected) body.reply_expected = true;
|
|
993
1002
|
|
|
994
1003
|
const res = await fetchWithAuth(`http://${target.host}:${PORT}/api/sessions/${encodeURIComponent(target.id)}/inject`, {
|
|
995
1004
|
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body)
|
|
@@ -1015,8 +1024,7 @@ async function main() {
|
|
|
1015
1024
|
if (!replyTo) { console.error(`❌ No pending reply-to found for session '${mySessionId}'`); process.exit(1); }
|
|
1016
1025
|
const target = await resolveSessionTarget(replyTo);
|
|
1017
1026
|
if (!target) { console.error(`❌ Session '${replyTo}' was not found on any discovered host.`); process.exit(1); }
|
|
1018
|
-
const
|
|
1019
|
-
const body = { prompt: fullPrompt, from: mySessionId, reply_to: mySessionId };
|
|
1027
|
+
const body = { prompt: replyText, from: mySessionId, reply_to: mySessionId };
|
|
1020
1028
|
const res = await fetchWithAuth(`http://${target.host}:${PORT}/api/sessions/${encodeURIComponent(target.id)}/inject`, {
|
|
1021
1029
|
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body)
|
|
1022
1030
|
});
|
package/daemon.js
CHANGED
|
@@ -530,10 +530,20 @@ app.post('/api/sessions/:id/inject', (req, res) => {
|
|
|
530
530
|
if (!resolvedId) return res.status(404).json({ error: 'Session not found', requested: requestedId });
|
|
531
531
|
const session = sessions[resolvedId];
|
|
532
532
|
const id = resolvedId;
|
|
533
|
-
const { prompt, no_enter, auto_submit,
|
|
533
|
+
const { prompt, no_enter, auto_submit, thread_id, reply_expected } = req.body;
|
|
534
|
+
let { from, reply_to } = req.body;
|
|
534
535
|
if (!prompt) return res.status(400).json({ error: 'prompt is required' });
|
|
536
|
+
// reply_to defaults to from when omitted
|
|
537
|
+
if (from && !reply_to) reply_to = from;
|
|
535
538
|
if (from) session.lastInjectFrom = from;
|
|
536
539
|
if (reply_to) session.lastInjectReplyTo = reply_to;
|
|
540
|
+
if (thread_id) session.lastThreadId = thread_id;
|
|
541
|
+
|
|
542
|
+
// Auto-prepend [from:] [reply-to:] header if from is set and not already in prompt
|
|
543
|
+
let finalPrompt = prompt;
|
|
544
|
+
if (from && !prompt.startsWith('[from:')) {
|
|
545
|
+
finalPrompt = `[from: ${from}] [reply-to: ${reply_to}] ${prompt}`;
|
|
546
|
+
}
|
|
537
547
|
const inject_id = crypto.randomUUID();
|
|
538
548
|
try {
|
|
539
549
|
// Always inject text WITHOUT \r first, then send \r separately after delay
|
|
@@ -554,13 +564,13 @@ app.post('/api/sessions/:id/inject', (req, res) => {
|
|
|
554
564
|
let submitResult = null;
|
|
555
565
|
if (!no_enter && session.type === 'wrapped') {
|
|
556
566
|
// Wrapped sessions: send text+\r in single message to bypass allow bridge prompt-ready gate
|
|
557
|
-
if (!writeToSession(
|
|
567
|
+
if (!writeToSession(finalPrompt + '\r')) {
|
|
558
568
|
return res.status(503).json({ error: 'Wrap process is not connected' });
|
|
559
569
|
}
|
|
560
570
|
submitResult = { strategy: 'combined_cr' };
|
|
561
571
|
console.log(`[INJECT+SUBMIT] Combined \\r for ${id}`);
|
|
562
572
|
} else {
|
|
563
|
-
if (!writeToSession(
|
|
573
|
+
if (!writeToSession(finalPrompt)) {
|
|
564
574
|
return res.status(503).json({ error: 'Wrap process is not connected' });
|
|
565
575
|
}
|
|
566
576
|
// Spawned sessions: send \r separately after delay (proven split_cr strategy)
|
|
@@ -583,6 +593,8 @@ app.post('/api/sessions/:id/inject', (req, res) => {
|
|
|
583
593
|
content: prompt,
|
|
584
594
|
from: from || null,
|
|
585
595
|
reply_to: reply_to || null,
|
|
596
|
+
thread_id: thread_id || null,
|
|
597
|
+
reply_expected: !!reply_expected,
|
|
586
598
|
timestamp: new Date().toISOString()
|
|
587
599
|
});
|
|
588
600
|
busClients.forEach(client => {
|