@dmsdc-ai/aigentry-telepty 0.1.46 → 0.1.48

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.
Files changed (2) hide show
  1. package/daemon.js +68 -3
  2. package/package.json +1 -1
package/daemon.js CHANGED
@@ -633,8 +633,9 @@ app.post('/api/sessions/:id/inject', (req, res) => {
633
633
  if (from && !prompt.startsWith('[from:')) {
634
634
  finalPrompt = `[from: ${from}] [reply-to: ${reply_to}] ${prompt}`;
635
635
  }
636
- // Append reply guide when reply_to is set (self-contained reply instructions)
637
- if (reply_to && reply_to !== id) {
636
+ // Append reply guide when reply_to is set, UNLESS message contains termination signal
637
+ const TERMINATION_SIGNALS = /no further reply needed|thread closed|closed on .+ side|ack received|ack-only|회신 불필요|스레드 종료/i;
638
+ if (reply_to && reply_to !== id && !TERMINATION_SIGNALS.test(prompt)) {
638
639
  finalPrompt += `\n\n---\n[reply-to: ${reply_to}] 위 세션에 회신이 필요합니다. 답변 시 아래 명령을 실행하세요:\ntelepty inject --from ${id} ${reply_to} "답변 내용"\n---`;
639
640
  }
640
641
  const inject_id = crypto.randomUUID();
@@ -1239,12 +1240,76 @@ busWss.on('connection', (ws, req) => {
1239
1240
  ws.on('message', (message) => {
1240
1241
  try {
1241
1242
  const msg = JSON.parse(message);
1242
- // For MVP, simply broadcast any valid JSON message to all other bus clients
1243
+ // Broadcast to all other bus clients
1243
1244
  busClients.forEach(client => {
1244
1245
  if (client !== ws && client.readyState === 1) {
1245
1246
  client.send(JSON.stringify(msg));
1246
1247
  }
1247
1248
  });
1249
+
1250
+ // Auto-router: turn_request → inject to target session PTY
1251
+ if (msg.type === 'turn_request' && msg.target_session_id) {
1252
+ const targetId = resolveSessionAlias(msg.target_session_id);
1253
+ const targetSession = targetId ? sessions[targetId] : null;
1254
+ if (targetSession) {
1255
+ const prompt = msg.content || msg.prompt || JSON.stringify(msg);
1256
+ const inject_id = crypto.randomUUID();
1257
+
1258
+ // Write to session (kitty primary, WS fallback)
1259
+ const sock = findKittySocket();
1260
+ if (!targetSession.kittyWindowId && sock) targetSession.kittyWindowId = findKittyWindowId(sock, targetId);
1261
+ const wid = targetSession.kittyWindowId;
1262
+ let delivered = false;
1263
+
1264
+ if (wid && sock && targetSession.type === 'wrapped') {
1265
+ try {
1266
+ const escaped = prompt.replace(/\\/g, '\\\\').replace(/'/g, "'\\''");
1267
+ require('child_process').execSync(`kitty @ --to unix:${sock} send-text --match id:${wid} '${escaped}'`, {
1268
+ timeout: 5000, stdio: ['pipe', 'pipe', 'pipe']
1269
+ });
1270
+ setTimeout(() => {
1271
+ try {
1272
+ require('child_process').execSync(`kitty @ --to unix:${sock} send-key --match id:${wid} Return`, {
1273
+ timeout: 3000, stdio: ['pipe', 'pipe', 'pipe']
1274
+ });
1275
+ } catch {}
1276
+ }, 500);
1277
+ delivered = true;
1278
+ } catch {}
1279
+ }
1280
+ if (!delivered) {
1281
+ // WS fallback
1282
+ if (targetSession.type === 'wrapped' && targetSession.ownerWs && targetSession.ownerWs.readyState === 1) {
1283
+ targetSession.ownerWs.send(JSON.stringify({ type: 'inject', data: prompt }));
1284
+ setTimeout(() => {
1285
+ if (targetSession.ownerWs && targetSession.ownerWs.readyState === 1) {
1286
+ targetSession.ownerWs.send(JSON.stringify({ type: 'inject', data: '\r' }));
1287
+ }
1288
+ }, 300);
1289
+ delivered = true;
1290
+ } else if (targetSession.ptyProcess) {
1291
+ targetSession.ptyProcess.write(prompt);
1292
+ setTimeout(() => targetSession.ptyProcess.write('\r'), 300);
1293
+ delivered = true;
1294
+ }
1295
+ }
1296
+
1297
+ // Emit inject_written ack
1298
+ const ackMsg = JSON.stringify({
1299
+ type: 'inject_written',
1300
+ inject_id,
1301
+ sender: 'daemon',
1302
+ target_agent: targetId,
1303
+ source_type: 'bus_auto_route',
1304
+ delivered,
1305
+ timestamp: new Date().toISOString()
1306
+ });
1307
+ busClients.forEach(client => {
1308
+ if (client.readyState === 1) client.send(ackMsg);
1309
+ });
1310
+ console.log(`[BUS-ROUTE] turn_request → ${targetId}: ${delivered ? 'delivered' : 'failed'}`);
1311
+ }
1312
+ }
1248
1313
  } catch (e) {
1249
1314
  console.error('[BUS] Invalid message format', e);
1250
1315
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dmsdc-ai/aigentry-telepty",
3
- "version": "0.1.46",
3
+ "version": "0.1.48",
4
4
  "main": "daemon.js",
5
5
  "bin": {
6
6
  "aigentry-telepty": "install.js",