instar 0.7.47 → 0.7.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.
@@ -1420,9 +1420,58 @@ export function createRoutes(ctx) {
1420
1420
  }
1421
1421
  }
1422
1422
  else if (ctx.sessionManager) {
1423
- // No telegram adapter with routing inject directly into any mapped session
1424
- ctx.sessionManager.injectTelegramMessage(`${ctx.config.projectName}-interface`, topicId, text);
1425
- res.json({ ok: true, forwarded: true, method: 'direct-inject' });
1423
+ // No TelegramAdapter (--no-telegram mode)route using topic-session registry on disk
1424
+ const registryPath = path.join(ctx.config.stateDir, 'topic-session-registry.json');
1425
+ let targetSession = null;
1426
+ try {
1427
+ if (fs.existsSync(registryPath)) {
1428
+ const registry = JSON.parse(fs.readFileSync(registryPath, 'utf-8'));
1429
+ targetSession = registry.topicToSession?.[String(topicId)] ?? null;
1430
+ }
1431
+ }
1432
+ catch { /* registry read failed — fall through to spawn */ }
1433
+ if (targetSession && ctx.sessionManager.isSessionAlive(targetSession)) {
1434
+ // Session exists and is alive — inject message
1435
+ console.log(`[telegram-forward] Injecting into ${targetSession}: "${text.slice(0, 80)}"`);
1436
+ ctx.sessionManager.injectTelegramMessage(targetSession, topicId, text);
1437
+ res.json({ ok: true, forwarded: true, method: 'registry-inject', session: targetSession });
1438
+ }
1439
+ else {
1440
+ // No session or session dead — auto-spawn a new one
1441
+ const topicName = targetSession || `topic-${topicId}`;
1442
+ console.log(`[telegram-forward] No live session for topic ${topicId}, spawning "${topicName}"...`);
1443
+ const contextLines = [
1444
+ `This session was auto-created for Telegram topic ${topicId}.`,
1445
+ ``,
1446
+ `CRITICAL: You MUST relay your response back to Telegram after responding.`,
1447
+ `Use the relay script:`,
1448
+ ``,
1449
+ `cat <<'EOF' | .claude/scripts/telegram-reply.sh ${topicId}`,
1450
+ `Your response text here`,
1451
+ `EOF`,
1452
+ ``,
1453
+ `Strip the [telegram:${topicId}] prefix before interpreting the message.`,
1454
+ `Only relay conversational text — not tool output or internal reasoning.`,
1455
+ ];
1456
+ const tmpDir = '/tmp/instar-telegram';
1457
+ fs.mkdirSync(tmpDir, { recursive: true });
1458
+ const ctxPath = path.join(tmpDir, `ctx-${topicId}-${Date.now()}.txt`);
1459
+ fs.writeFileSync(ctxPath, contextLines.join('\n'));
1460
+ const bootstrapMessage = `[telegram:${topicId}] ${text} (IMPORTANT: Read ${ctxPath} for Telegram relay instructions — you MUST relay your response back.)`;
1461
+ ctx.sessionManager.spawnInteractiveSession(bootstrapMessage, topicName, { telegramTopicId: topicId }).then((newSessionName) => {
1462
+ // Update registry on disk
1463
+ try {
1464
+ const reg = fs.existsSync(registryPath) ? JSON.parse(fs.readFileSync(registryPath, 'utf-8')) : { topicToSession: {}, topicToName: {} };
1465
+ reg.topicToSession[String(topicId)] = newSessionName;
1466
+ fs.writeFileSync(registryPath, JSON.stringify(reg, null, 2));
1467
+ }
1468
+ catch { /* non-critical */ }
1469
+ console.log(`[telegram-forward] Spawned "${newSessionName}" for topic ${topicId}`);
1470
+ }).catch((err) => {
1471
+ console.error(`[telegram-forward] Spawn failed:`, err);
1472
+ });
1473
+ res.json({ ok: true, forwarded: true, method: 'spawn', topicName });
1474
+ }
1426
1475
  }
1427
1476
  else {
1428
1477
  res.status(503).json({ error: 'No message routing available' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instar",
3
- "version": "0.7.47",
3
+ "version": "0.7.48",
4
4
  "description": "Persistent autonomy infrastructure for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",